Skip to content

Adds strictMode option to strict-mode transform#3562

Merged
jamiebuilds merged 1 commit intomasterfrom
strictMode-false
Jul 2, 2016
Merged

Adds strictMode option to strict-mode transform#3562
jamiebuilds merged 1 commit intomasterfrom
strictMode-false

Conversation

@jamiebuilds
Copy link
Copy Markdown
Contributor

This allows you to disable "use strict"; when using the commonjs module transform.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 1, 2016

Current coverage is 87.91%

Merging #3562 into master will not change coverage

@@             master      #3562   diff @@
==========================================
  Files           194        194          
  Lines          9640       9640          
  Methods        1101       1101          
  Messages          0          0          
  Branches       2204       2204          
==========================================
  Hits           8475       8475          
  Misses         1165       1165          
  Partials          0          0          

Powered by Codecov. Last updated by ff4f476...2230caf

@loganfsmyth
Copy link
Copy Markdown
Member

Looks good.

@jamiebuilds jamiebuilds merged commit c561312 into master Jul 2, 2016
@jamiebuilds jamiebuilds deleted the strictMode-false branch July 2, 2016 20:27
@hzoo hzoo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jul 13, 2016
@jmm
Copy link
Copy Markdown
Member

jmm commented Jul 28, 2016

What's the use case for this?

What does "turn strict off" mean -- pass strict: false to transform-strict-mode?

@loganfsmyth
Copy link
Copy Markdown
Member

@jmm The issue is we have this plugin used inside transform-es2015-modules-commonjs via inherit, and that plugin also has an option called strict, so you can't toggle one but not the other, unexpectedly.

@jmm
Copy link
Copy Markdown
Member

jmm commented Jul 28, 2016

Thanks @loganfsmyth. Sorry, what I meant is, what is the use case for disabling Use Strict when transforming modules at all? When is it a good idea?

I was also wondering what's the purpose of the undocumented strict option to transform-es2015-modules-commonjs. I took a look at the source and couldn't totally figure it out yet. It looks like it controls at least a couple of other things besides adding Use Strict, one of which I didn't grok right away. The other is adding an __esModule export and I'm not sure what that has to do with adding Use Strict, and I see that you get 3 different transformations for strict values of true|false|undefined.

It's still not clear to me what the docs mean by:

turn strict off

@loganfsmyth
Copy link
Copy Markdown
Member

It's not a good idea, but we supported it in Babel 5 and James was transitioning a project from Babel 5 to Babel 6 and was hitting this as an issue because he couldn't toggle one flag without the other.

The other strict isn't related to strict mode, it's related to strictly processing modules, e.g. not adding another magic export called __esModule to the file that isn't actually declared in the file. I don't know why it was added or if it is used by anyone though.

@jmm
Copy link
Copy Markdown
Member

jmm commented Jul 28, 2016

Thanks Logan.

I'm guessing that was discussed on Slack...in any case, in general, if things are discussed on Slack it would be super helpful if people could record the background information and reasoning for decisions from there in PRs / issues.

It's not a good idea

We should make that clear in the README. I was helping a module author on the forum who used a preset that disables the Use Strict directive in the module transform to accommodate a user who wanted to concatenate their module with other code. Well, actually that user's package contains a script not a module, so omitting the module transform would be the appropriate solution there -- but it just goes to show that there's a lot of misunderstanding around strict mode and modules and we shouldn't make it sound like a good idea.

The other strict isn't related to strict mode, it's related to strictly processing modules, e.g. not adding another magic export called __esModule to the file that isn't actually declared in the file.

Thanks for that info. It does affect output of Use Strict directive though. You can get three different versions of output:

strict: true
=> Use Strict: yes, __esModule: no

strict: false
=> Use Strict: no, __esModule: yes

strict: undefined
=> Use Strict: yes, __esModule: yes

I don't know why it was added or if it is used by anyone though.

We should document or deprecate it. The preset that I mentioned above that came up on the discussion forum is using it for the purpose of omitting the Use Strict directive.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants