Skip to content

Fix alias of module.exports->exports->IIFE#27992

Merged
sandersn merged 1 commit into
masterfrom
js/fix-alias-of-module-exports-exports-iife
Oct 19, 2018
Merged

Fix alias of module.exports->exports->IIFE#27992
sandersn merged 1 commit into
masterfrom
js/fix-alias-of-module-exports-exports-iife

Conversation

@sandersn
Copy link
Copy Markdown
Member

In JS, when you assign module.exports = exports and the entire module is
wrapped in an IIFE, the resulting export= symbol, after following
aliases, is the module itself. This results in trying to merge the
file's exports with itself inside getCommonJsExportEquals, since it
thinks that it has found new exports, possibly in an object literal,
that need to be merged with the file's exports.

For example:

(function() {
exports.a = 1
module.exports = exports
})()

Fixes #27365

In JS, when you assign `module.exports = exports` and the entire module is
wrapped in an IIFE, the resulting `export=` symbol, after following
aliases, is the module itself. This results in trying to merge the
file's exports with itself inside `getCommonJsExportEquals`, since it
thinks that it has found new exports, possibly in an object literal,
that need to be merged with the file's exports.

For example:

```js
(function() {
exports.a = 1
module.exports = exports
})()
```
Comment thread src/compiler/checker.ts
if (moduleSymbol) {
const exportEquals = resolveSymbol(moduleSymbol.exports!.get(InternalSymbolName.ExportEquals), dontResolveAlias);
const exported = getCommonJsExportEquals(exportEquals, moduleSymbol);
return getMergedSymbol(exported) || moduleSymbol;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just makes it easier to read -- I found the previous found obtuse and too nested.

@sandersn sandersn merged commit e379aeb into master Oct 19, 2018
@sandersn sandersn deleted the js/fix-alias-of-module-exports-exports-iife branch October 19, 2018 20:50
@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