Conversation
Huh I wonder why. Some static analyzer not understanding the former?
We kinda can. Kinda because technically |
|
Don't we need this for closure? That is, won't closure change |
But here I'm just removing the line completely, not removing the quotes. The |
|
I see. Could be, I don't know enough about the details of JS module systems. |
|
The purpose of the quotes indeed is that closure does not mangle the property name. Only relevant when using advanced optimizations plus there are no externs describing the property otherwise. The code in question did the following before the change:
The last case is arguably the least important, but I can't tell how little. Iirc this code originated as a variation of Universal Module Defintion. Uses I know of would not be broken when removing the last case. |
|
What kind of CommonJS environments are there that don't have Given that the node also support the third case, could we drop the first case ( |
|
Looking at the closure docs it seems like it actually recommends doing Do you know why they seem unconcerned by the "variable does not become visible to the outside" issue you mention? |
|
Iiirc the |
|
As a bit of speculation: One possible error here is that if neither the first (CommonJS) nor the second branch (AMD) is taken, and A workaround specific to this case would be -else if (typeof exports === 'object')
+else if (typeof exports === 'object' && exports)
exports["%(EXPORT_NAME)s"] = %(EXPORT_NAME)s;but it's probably also not really fixing anything, since if |
|
Would we not wrap all of this code in Also, can you explain more what you we can't just do |
|
I believe the reason function initModule(module, exports) {
// module code is inserted here
return module.exports;
}
initModule(module, module.exports);where an assignment I don't know enough about the |
|
Sorry I meant ENVIRONMENT_IS_WEB. I guess we can't do that though because we actually do want this code to runnable on the web and folks use module loaders/bundlers to run modules on the web ? |
What platforms/toolchain do you think do this? I'd like to test it out (and add some tests to emscripten). |
Hmm, yeah, removing everything would produce non-functional artifacts if such a wrapper is present. Though, I guess a bundler would adhere to what Node does (for Node modules), so removing the third branch, or fixing it as of above if that's indeed the error seen, would not break the wrappers.
In Node, which I guess is somewhat the source of truth, the relevant code seems to be somewhere around here: const wrapper = [
'(function (exports, require, module, __filename, __dirname) { ',
'\n});',
];where what is returned ultimately is the module's I suggest that, if the reported error is something like |
We had a report the use of `exports["Foo"]` rather then `exports.Foo` was causing problems. Can we just remove this line completely and rely on module.exports to take care of the CommonJS case?
409d43c to
5911762
Compare
|
The oldest version of node that we support is v10.19.0 and I confirmed that both |
|
@kripken @RReverser can one of you lgtm? |
We had a report the use of
exports["Foo"]rather thenexports.Foowas causing problems.Can we just remove this line completely and rely on module.exports to take care of the CommonJS case?