Skip to content

Fix commonjs module.exports= merging#27368

Merged
sandersn merged 1 commit intorelease-3.1from
js/fix-commonjs-exportequals-merging
Sep 26, 2018
Merged

Fix commonjs module.exports= merging#27368
sandersn merged 1 commit intorelease-3.1from
js/fix-commonjs-exportequals-merging

Conversation

@sandersn
Copy link
Copy Markdown
Member

Whenever the exported symbol is unknown getCommonJsExportEquals blithely clones unknownSymbol and proceeds to stick the exports.foo= properties onto it.

This causes problems later, because the compiler checks for unknownSymbol with ===. The fix is to not stick properties onto a clone of unknownSymbol. This makes the correct errors appear and removes
the crash. Maybe we should consider supporting this pattern [1], but for now I think it's fine to issue an error on the unknown property.

Fixes #27025

[1] Call it "speculative export of a supposedly-global expando object", I guess. Makes it sound really appetising.

I'm surprised we haven't seen more of this; I suspect it's because the
mixed `module.exports=` + `export.foo=` pattern isn't that common.
However, it'll happen any time that the exported symbol is unknown;
getCommonJsExportEquals blithely clones unknownSymbol and proceeds to
stick the `exports.foo=` properties onto it.

This causes problems later, because the compiler checks for
unknownSymbol with `===`. The fix is to not stick properties onto a
clone of unknownSymbol. This makes the correct errors appear and removes
the crash.
@sandersn sandersn added this to the TypeScript 3.1 milestone Sep 26, 2018
@sandersn sandersn merged commit b77cb2a into release-3.1 Sep 26, 2018
@sandersn sandersn deleted the js/fix-commonjs-exportequals-merging branch September 26, 2018 17:54
sandersn added a commit that referenced this pull request Sep 26, 2018
I'm surprised we haven't seen more of this; I suspect it's because the
mixed `module.exports=` + `export.foo=` pattern isn't that common.
However, it'll happen any time that the exported symbol is unknown;
getCommonJsExportEquals blithely clones unknownSymbol and proceeds to
stick the `exports.foo=` properties onto it.

This causes problems later, because the compiler checks for
unknownSymbol with `===`. The fix is to not stick properties onto a
clone of unknownSymbol. This makes the correct errors appear and removes
the crash.
sandersn added a commit that referenced this pull request Sep 26, 2018
I'm surprised we haven't seen more of this; I suspect it's because the
mixed `module.exports=` + `export.foo=` pattern isn't that common.
However, it'll happen any time that the exported symbol is unknown;
getCommonJsExportEquals blithely clones unknownSymbol and proceeds to
stick the `exports.foo=` properties onto it.

This causes problems later, because the compiler checks for
unknownSymbol with `===`. The fix is to not stick properties onto a
clone of unknownSymbol. This makes the correct errors appear and removes
the crash.
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants