Skip to content
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

Remove redundant "use strict" #1473

Closed
MikeMcl opened this issue Apr 12, 2019 · 7 comments
Closed

Remove redundant "use strict" #1473

MikeMcl opened this issue Apr 12, 2019 · 7 comments
Labels

Comments

@MikeMcl
Copy link

MikeMcl commented Apr 12, 2019

In the webpack bundle, dist/math.js, there are 372 declarations of "use strict";.

I suggest that somehow a single "use strict"; be used at the top of the file instead, as this would reduce the size of the file by over 4800 characters.

This change might be a problem if some of the bundled modules need to run in 'sloppy mode', but that is highly unlikely.

Making this change would also make dist/math.js compatible with Qt QML, see #1454.

Unfortunately, I am not able to work on this myself at this time.

@josdejong
Copy link
Owner

That's actually a good idea, thanks Michael!

In the generated bundle it's enough to have just one "use strict;" at the top. I'm not sure about node.js files, if it's necessary/good to have "use strict;" on top of every node.js file. Does anybody know more about that?

@ericman314
Copy link
Collaborator

In ECMAScript 2015 modules are strict by default, but one person did an experiment two years ago using node v6 and v8 that showed modules were not strict by default, since they still used the require() syntax of CommonJS: http://imaginativethinking.ca/what-the-heck-is-node-modules-strict-by-default/

You can also add "use strict"; to individual functions, so if you have a function which wraps everything else you can limit strict mode to the wrapping function and everything inside.

And finally, here are some methods to check if strict mode is active: https://stackoverflow.com/questions/10480108/is-there-any-way-to-check-if-strict-mode-is-enforced

@josdejong
Copy link
Owner

The modular_architecture refactor (#71) replaces CommonJS with ES6 import/export, so that means we can simply remove all "use strict"; there, and make sure there is a single "use strict"; in the bundle? I'm not sure whether we need to rename the .js files to .mjs before code counts as a real ES6 module.

@ericman314
Copy link
Collaborator

Not sure. I guess we'll have to experiment.

@josdejong
Copy link
Owner

FYI: I've merged modular_architecture into develop now.

@josdejong
Copy link
Owner

I've removed all occurrences of 'use strict' now. I've double checked whether we're still in strict mode using the function from the stackoverflow issue mentioned by Eric, tested in browser and node.js and in both cases we're ok. The browser bundle generated by Webpack does add one 'use strict', that's what we want.

@harrysarson
Copy link
Collaborator

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants