-
Notifications
You must be signed in to change notification settings - Fork 17
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
Overriding a re-export with a local variable of same name results in runtime ReferenceError #78
Comments
I believe the key issue is not in the order, but in the line The expression In my opinion, if the key exists in the Furthermore, there is an issue with Otherwise, exporting functions with names like I strongly suspect that this code originates from the loose mode of Babel compilation. |
expected result: Object.keys(mod).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(exports, key)) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return mod[key];
},
configurable: true
});
}); |
Did my best at getting it to output what you mentioned in #79. Seems to fix my issue. |
Version: 0.79.55
Issue
Given an input file of:
swc_mut_cjs_exports will output:
If
someModule
exports a member namedfoo
aReferenceError
will be thrown at runtime:This is because the
forEach
in the output file tries to accessexports.foo
which has a getter to return the localfoo
variable which hasn't been defined yet.Expectation
I think, ideally, we'd want the transformed exports to follow the same order as the pre-transformed exports rather than hoisting local exports to the top.
Like:
The text was updated successfully, but these errors were encountered: