-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime support for
__esModule
annotations (#3393)
* Runtime support for `__esModule` annotations * Ignore `__esModule` annotation when `"type": "module"` is set --------- Co-authored-by: Jarred Sumner <[email protected]>
- Loading branch information
1 parent
6d01e6e
commit a732999
Showing
17 changed files
with
221 additions
and
15 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
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
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
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
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
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
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,68 @@ | ||
import { test, expect, describe } from "bun:test"; | ||
import * as WithTypeModuleExportEsModuleAnnotationMissingDefault from "./with-type-module/export-esModule-annotation-empty.cjs"; | ||
import * as WithTypeModuleExportEsModuleAnnotationNoDefault from "./with-type-module/export-esModule-annotation-no-default.cjs"; | ||
import * as WithTypeModuleExportEsModuleAnnotation from "./with-type-module/export-esModule-annotation.cjs"; | ||
import * as WithTypeModuleExportEsModuleNoAnnotation from "./with-type-module/export-esModule-no-annotation.cjs"; | ||
import * as WithoutTypeModuleExportEsModuleAnnotationMissingDefault from "./without-type-module/export-esModule-annotation-empty.cjs"; | ||
import * as WithoutTypeModuleExportEsModuleAnnotationNoDefault from "./without-type-module/export-esModule-annotation-no-default.cjs"; | ||
import * as WithoutTypeModuleExportEsModuleAnnotation from "./without-type-module/export-esModule-annotation.cjs"; | ||
import * as WithoutTypeModuleExportEsModuleNoAnnotation from "./without-type-module/export-esModule-no-annotation.cjs"; | ||
|
||
describe('without type: "module"', () => { | ||
test("module.exports = {}", () => { | ||
expect(WithoutTypeModuleExportEsModuleAnnotationMissingDefault.default).toEqual({}); | ||
expect(WithoutTypeModuleExportEsModuleAnnotationMissingDefault.__esModule).toBeUndefined(); | ||
}); | ||
|
||
test("exports.__esModule = true", () => { | ||
expect(WithoutTypeModuleExportEsModuleAnnotationNoDefault.default).toEqual({ | ||
__esModule: true, | ||
}); | ||
|
||
// The module namespace object will not have the __esModule property. | ||
expect(WithoutTypeModuleExportEsModuleAnnotationNoDefault).not.toHaveProperty("__esModule"); | ||
}); | ||
|
||
test("exports.default = true; exports.__esModule = true;", () => { | ||
expect(WithoutTypeModuleExportEsModuleAnnotation.default).toBeTrue(); | ||
expect(WithoutTypeModuleExportEsModuleAnnotation.__esModule).toBeUndefined(); | ||
}); | ||
|
||
test("exports.default = true;", () => { | ||
expect(WithoutTypeModuleExportEsModuleNoAnnotation.default).toEqual({ | ||
default: true, | ||
}); | ||
expect(WithoutTypeModuleExportEsModuleAnnotation.__esModule).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('with type: "module"', () => { | ||
test("module.exports = {}", () => { | ||
expect(WithTypeModuleExportEsModuleAnnotationMissingDefault.default).toEqual({}); | ||
expect(WithTypeModuleExportEsModuleAnnotationMissingDefault.__esModule).toBeUndefined(); | ||
}); | ||
|
||
test("exports.__esModule = true", () => { | ||
expect(WithTypeModuleExportEsModuleAnnotationNoDefault.default).toEqual({ | ||
__esModule: true, | ||
}); | ||
|
||
// The module namespace object WILL have the __esModule property. | ||
expect(WithTypeModuleExportEsModuleAnnotationNoDefault).toHaveProperty("__esModule"); | ||
}); | ||
|
||
test("exports.default = true; exports.__esModule = true;", () => { | ||
expect(WithTypeModuleExportEsModuleAnnotation.default).toEqual({ | ||
default: true, | ||
__esModule: true, | ||
}); | ||
expect(WithTypeModuleExportEsModuleAnnotation.__esModule).toBeTrue(); | ||
}); | ||
|
||
test("exports.default = true;", () => { | ||
expect(WithTypeModuleExportEsModuleNoAnnotation.default).toEqual({ | ||
default: true, | ||
}); | ||
expect(WithTypeModuleExportEsModuleAnnotation.__esModule).toBeTrue(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/js/bun/resolve/with-type-module/export-esModule-annotation-empty.cjs
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 @@ | ||
module.exports = {}; |
1 change: 1 addition & 0 deletions
1
test/js/bun/resolve/with-type-module/export-esModule-annotation-no-default.cjs
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 @@ | ||
exports.__esModule = true; |
2 changes: 2 additions & 0 deletions
2
test/js/bun/resolve/with-type-module/export-esModule-annotation.cjs
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,2 @@ | ||
exports.default = true; | ||
exports.__esModule = true; |
1 change: 1 addition & 0 deletions
1
test/js/bun/resolve/with-type-module/export-esModule-no-annotation.cjs
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 @@ | ||
exports.default = true; |
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,4 @@ | ||
{ | ||
"name": "with-type-module", | ||
"type": "module" | ||
} |
1 change: 1 addition & 0 deletions
1
test/js/bun/resolve/without-type-module/export-esModule-annotation-empty.cjs
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 @@ | ||
module.exports = {}; |
1 change: 1 addition & 0 deletions
1
test/js/bun/resolve/without-type-module/export-esModule-annotation-no-default.cjs
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 @@ | ||
exports.__esModule = true; |
2 changes: 2 additions & 0 deletions
2
test/js/bun/resolve/without-type-module/export-esModule-annotation.cjs
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,2 @@ | ||
exports.default = true; | ||
exports.__esModule = true; |
1 change: 1 addition & 0 deletions
1
test/js/bun/resolve/without-type-module/export-esModule-no-annotation.cjs
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 @@ | ||
exports.default = true; |
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,4 @@ | ||
{ | ||
"name": "without-type-module", | ||
"type": "commonjs" | ||
} |