traceur-compiler: Should not always add 'use strict' on node modules
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.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 25 (5 by maintainers)
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
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
"use strict";.If you are compiling ES6 scripts to ES5 scripts, then Traceur will not put
"use strict";there, as noted in @matthewrobb’s original comment.To be explicit, ES6 modules are always in strict mode. So if you are writing scripts (which do not allow
importandexportandmodulestatements), you can stay in sloppy mode, but if you are writing modules, then you are opting in to strict mode automatically.