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
Implement importInterop: "node"
option for module transforms
#12838
Merged
nicolo-ribaudo
merged 4 commits into
babel:main
from
nicolo-ribaudo:modules-node-interop
Apr 28, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
1 change: 1 addition & 0 deletions
1
...ugin-transform-modules-amd/test/fixtures/importInterop-node/export-default-from/input.mjs
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 @@ | ||
export { default } from 'dep'; |
8 changes: 8 additions & 0 deletions
8
...ugin-transform-modules-amd/test/fixtures/importInterop-node/export-default-from/output.js
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,8 @@ | ||
define(["exports", "dep"], function (_exports, _dep) { | ||
"use strict"; | ||
|
||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.default = _dep; | ||
}); |
1 change: 1 addition & 0 deletions
1
...form-modules-amd/test/fixtures/importInterop-node/export-named-and-default-from/input.mjs
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 @@ | ||
export { default, name } from 'dep'; |
20 changes: 20 additions & 0 deletions
20
...form-modules-amd/test/fixtures/importInterop-node/export-named-and-default-from/output.js
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,20 @@ | ||
define(["exports", "dep"], function (_exports, _dep) { | ||
"use strict"; | ||
|
||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(_exports, "default", { | ||
enumerable: true, | ||
get: function () { | ||
return _dep.default; | ||
} | ||
}); | ||
Object.defineProperty(_exports, "name", { | ||
enumerable: true, | ||
get: function () { | ||
return _dep.name; | ||
} | ||
}); | ||
_dep = babelHelpers.interopRequireWildcard(_dep, true); | ||
}); |
1 change: 1 addition & 0 deletions
1
...plugin-transform-modules-amd/test/fixtures/importInterop-node/export-named-from/input.mjs
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 @@ | ||
export { name } from 'dep'; |
13 changes: 13 additions & 0 deletions
13
...plugin-transform-modules-amd/test/fixtures/importInterop-node/export-named-from/output.js
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,13 @@ | ||
define(["exports", "dep"], function (_exports, _dep) { | ||
"use strict"; | ||
|
||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(_exports, "name", { | ||
enumerable: true, | ||
get: function () { | ||
return _dep.name; | ||
} | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...el-plugin-transform-modules-amd/test/fixtures/importInterop-node/import-default/input.mjs
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,3 @@ | ||
import foo from "foo"; | ||
|
||
foo(); |
5 changes: 5 additions & 0 deletions
5
...el-plugin-transform-modules-amd/test/fixtures/importInterop-node/import-default/output.js
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,5 @@ | ||
define(["foo"], function (_foo) { | ||
"use strict"; | ||
|
||
_foo(); | ||
}); |
4 changes: 4 additions & 0 deletions
4
...transform-modules-amd/test/fixtures/importInterop-node/import-named-and-default/input.mjs
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 @@ | ||
import foo, { named } from "foo"; | ||
|
||
foo(); | ||
named(); |
7 changes: 7 additions & 0 deletions
7
...transform-modules-amd/test/fixtures/importInterop-node/import-named-and-default/output.js
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,7 @@ | ||
define(["foo"], function (_foo) { | ||
"use strict"; | ||
|
||
_foo = babelHelpers.interopRequireWildcard(_foo, true); | ||
(0, _foo.default)(); | ||
(0, _foo.named)(); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...abel-plugin-transform-modules-amd/test/fixtures/importInterop-node/import-named/input.mjs
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,3 @@ | ||
import { named } from "foo"; | ||
|
||
named(); |
5 changes: 5 additions & 0 deletions
5
...abel-plugin-transform-modules-amd/test/fixtures/importInterop-node/import-named/output.js
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,5 @@ | ||
define(["foo"], function (_foo) { | ||
"use strict"; | ||
|
||
(0, _foo.named)(); | ||
}); |
4 changes: 4 additions & 0 deletions
4
...l-plugin-transform-modules-amd/test/fixtures/importInterop-node/import-wildcard/input.mjs
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 @@ | ||
import * as foo from 'foo'; | ||
|
||
foo.bar(); | ||
foo.baz(); |
7 changes: 7 additions & 0 deletions
7
...l-plugin-transform-modules-amd/test/fixtures/importInterop-node/import-wildcard/output.js
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,7 @@ | ||
define(["foo"], function (foo) { | ||
"use strict"; | ||
|
||
foo = babelHelpers.interopRequireWildcard(foo, true); | ||
foo.bar(); | ||
foo.baz(); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-modules-amd/test/fixtures/importInterop-node/options.json
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,3 @@ | ||
{ | ||
"plugins": [["transform-modules-amd", { "importInterop": "node" }]] | ||
} |
1 change: 1 addition & 0 deletions
1
...babel-plugin-transform-modules-amd/test/fixtures/importInterop-none/export-from/input.mjs
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 @@ | ||
export { default } from 'foo'; |
13 changes: 13 additions & 0 deletions
13
...babel-plugin-transform-modules-amd/test/fixtures/importInterop-none/export-from/output.js
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,13 @@ | ||
define(["exports", "foo"], function (_exports, _foo) { | ||
"use strict"; | ||
|
||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(_exports, "default", { | ||
enumerable: true, | ||
get: function () { | ||
return _foo.default; | ||
} | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...ugin-transform-modules-amd/test/fixtures/importInterop-none/import-default-only/input.mjs
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,3 @@ | ||
import foo from "foo"; | ||
|
||
foo(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
metadata.interop
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It tells what interop function we need for the import:
Then in this function we specialize between "babel interop" and "node interop".