-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix alias of module.exports->exports->IIFE (#27992)
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 })() ```
- Loading branch information
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/moduleExportAliasExports.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
=== tests/cases/conformance/salsa/Eloquent.js === | ||
// bug #27365, crashes from github.com/marijnh/Eloquent-JavaScript | ||
(function() { | ||
exports.bigOak = 1 | ||
>exports.bigOak : Symbol(bigOak, Decl(Eloquent.js, 1, 13)) | ||
>exports : Symbol(bigOak, Decl(Eloquent.js, 1, 13)) | ||
>bigOak : Symbol(bigOak, Decl(Eloquent.js, 1, 13)) | ||
|
||
exports.everywhere = 2 | ||
>exports.everywhere : Symbol(everywhere, Decl(Eloquent.js, 2, 18)) | ||
>exports : Symbol(everywhere, Decl(Eloquent.js, 2, 18)) | ||
>everywhere : Symbol(everywhere, Decl(Eloquent.js, 2, 18)) | ||
|
||
module.exports = exports | ||
>module.exports : Symbol("tests/cases/conformance/salsa/Eloquent", Decl(Eloquent.js, 0, 0)) | ||
>module : Symbol(export=, Decl(Eloquent.js, 3, 22)) | ||
>exports : Symbol(export=, Decl(Eloquent.js, 3, 22)) | ||
>exports : Symbol("tests/cases/conformance/salsa/Eloquent", Decl(Eloquent.js, 0, 0)) | ||
|
||
})() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
=== tests/cases/conformance/salsa/Eloquent.js === | ||
// bug #27365, crashes from github.com/marijnh/Eloquent-JavaScript | ||
(function() { | ||
>(function() {exports.bigOak = 1exports.everywhere = 2module.exports = exports})() : void | ||
>(function() {exports.bigOak = 1exports.everywhere = 2module.exports = exports}) : () => void | ||
>function() {exports.bigOak = 1exports.everywhere = 2module.exports = exports} : () => void | ||
|
||
exports.bigOak = 1 | ||
>exports.bigOak = 1 : 1 | ||
>exports.bigOak : number | ||
>exports : typeof import("tests/cases/conformance/salsa/Eloquent") | ||
>bigOak : number | ||
>1 : 1 | ||
|
||
exports.everywhere = 2 | ||
>exports.everywhere = 2 : 2 | ||
>exports.everywhere : number | ||
>exports : typeof import("tests/cases/conformance/salsa/Eloquent") | ||
>everywhere : number | ||
>2 : 2 | ||
|
||
module.exports = exports | ||
>module.exports = exports : typeof import("tests/cases/conformance/salsa/Eloquent") | ||
>module.exports : typeof import("tests/cases/conformance/salsa/Eloquent") | ||
>module : { "tests/cases/conformance/salsa/Eloquent": typeof import("tests/cases/conformance/salsa/Eloquent"); } | ||
>exports : typeof import("tests/cases/conformance/salsa/Eloquent") | ||
>exports : typeof import("tests/cases/conformance/salsa/Eloquent") | ||
|
||
})() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @noEmit: true | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @Filename: Eloquent.js | ||
// bug #27365, crashes from github.com/marijnh/Eloquent-JavaScript | ||
(function() { | ||
exports.bigOak = 1 | ||
exports.everywhere = 2 | ||
module.exports = exports | ||
})() |