New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should not always add 'use strict' on node modules #1031
Comments
If you use the makeDefault method for require overloading then you can specify a pattern or filter for what should be traceur loaded and what shouldn't. If you do this then only traceur module's end up with the added "use strict" which is absolutely correct from an ES6 stand point. If koa is using es6 modules then it is using "strict mode" implicitly according to the spec. |
To be explicit, ES6 modules are always in strict mode. So if you are writing scripts (which do not allow |
OK. Thanks a lot for the explanation. I had a hunch it was something like that. It would be cool if the koa modules where developed with 'use strict' on top of file because node does not seem to enforce it when --harmony is activated. It means that, basically, it is allowing users to run code with some ES6 features but not the enforcements made by use strict. This is sad. |
You can still use ES6 features while in sloppy mode, as long as you are authoring scripts, not modules. By default Node code is all in scripts; I don't know of a way to run Node code in modules, probably because V8 doesn't support modules yet. |
It's completely valid to use some ES6 features without "strict mode" and it's important to know that node uses it's own brand of CommonJS style module system and Traceur providing an easy means of hooking into that is really a special Traceur feature and nothing more. In a world where ES6 features are all available natively this "issue" still exists and by design. Keep in mind that you do not need your entire program to be in strict mode to gain the benefits of strict mode where it's been declared. var global = this;
function sloppy() {
console.log(this === global);
}
function strict(both){
"use strict";
console.log(this === global);
if(both){
sloppy();
}
}
sloppy(); // true
strict(); // false
strict(true); // false && true |
Then traceur should detect the presence of 'use strict' and add it back only if it was there first right? |
No. If you're compiling code to ES6 modules with Traceur, then that code needs to have strict semantics. Since traceur compiles ES6 modules -> ES5 scripts, it needs to put the scripts in strict mode via the only way that is possible, namely If you are compiling ES6 scripts to ES5 scripts, then Traceur will not put |
Only if you have module compilation off. Otherwise Traceur is transcompiling your source AS IF it was an ES6 module which like has already been stated, automatically strict mode. NOTE: Class bodies are also strict mode |
I don't think I am compiling to ES6 modules. How do I check that? |
var traceur = require("traceur");
traceur.options.modules = true; // This is the default |
OK. I added |
I'm sorry it looks like you need to add traceur.options.modules_ = false; as well. |
Same thing with |
If we are compiling a Module production we are adding @qraynaud How are you compiling your code? If you are using the command line compiler try passing the files as |
No I'm not using the command line compiler. i'm using the compiler on require via node. |
@arv: any other ideas? Right now I would really like to include modules created by others in my project that don't support and don't work in strict mode. It would be cool if traceur could work everywhere. That said, I would gladly write the patch myself but I would really need some help because the codebase is somewhat complex already. |
Currently the |
How about changing compile to use parseScript if the modules options is false? |
Sorry for the very long lapse since my last answer. I'm getting back to this and I found out that there is already something like that in the codebase of traceur (at least in recent versions). In var tree = mergedOptions.modules ? parser.parseModule() : parser.parseScript(); If I'm adding just before this line My problem is I can't find a way to get modules to I don't know how to pass options anymore to traceur. Has this changed recently? (I'm on |
Okay, after backporting some code from the future |
For others that might get here, here is what I wrote to get everything working properly: var traceur = require('traceur');
traceur.require.makeDefault(filterFn, {
blockBinding: true,
modules: false,
}); |
(hope 0.0.50 is released on NPM soon) |
Are there any other side effects to turning off modules and turning on blockBinding, other than preventing Traceur from inserting In my project, I want developers to insert So I want my source files to have |
Please don't ask questions on closed issues. Ask on the newsgroup or open a new issue. Refer to this one if it helps. |
Done: #1427 |
Right now, traceur automatically add a
"use strict"
statement on generated node modules (first line as should be). It can break existing modules that do not use strict mode but make use of parts of ES6 (like some koa modules).I believe (but I might be wrong) that it would be better to keep the
"use strict"
statement only if the user had it there in the first place.The text was updated successfully, but these errors were encountered: