Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 497edf2

Browse files
Remove importReflection parser plugin
1 parent 69d65f1 commit 497edf2

14 files changed

Lines changed: 41 additions & 24 deletions

File tree

packages/babel-generator/test/fixtures/comments/import-reflection-inner-comment/input.mjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/babel-generator/test/fixtures/comments/import-reflection-inner-comment/options.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/babel-generator/test/fixtures/comments/import-reflection-inner-comment/output.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* 0 */import /* 1 */source /* 2 */from /* 3 */from /* 4 */"./module.wasm"/* 5 */;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["sourcePhaseImports"]
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* 0 */import /* 1 */ source /* 2 */from /* 3 */ from /* 4 */"./module.wasm" /* 5 */;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"plugins": ["importReflection"]
2+
"plugins": ["importReflection"],
3+
"BABEL_8_BREAKING": false
34
}

packages/babel-parser/src/parser/statement.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,7 @@ export default abstract class StatementParser extends ExpressionParser {
29402940
return (
29412941
this.isContextual(tt._source) ||
29422942
this.isContextual(tt._defer) ||
2943-
this.isContextual(tt._module)
2943+
(!process.env.BABEL_8_BREAKING && this.isContextual(tt._module))
29442944
);
29452945
}
29462946

@@ -2952,7 +2952,10 @@ export default abstract class StatementParser extends ExpressionParser {
29522952
): void {
29532953
if (isExport) {
29542954
if (!process.env.IS_PUBLISH) {
2955-
if (phase === "module" || phase === "source") {
2955+
if (
2956+
(!process.env.BABEL_8_BREAKING && phase === "module") ||
2957+
phase === "source"
2958+
) {
29562959
throw new Error(
29572960
`Assertion failure: export declarations do not support the '${phase}' phase.`,
29582961
);
@@ -2961,7 +2964,7 @@ export default abstract class StatementParser extends ExpressionParser {
29612964
return;
29622965
}
29632966

2964-
if (phase === "module") {
2967+
if (!process.env.BABEL_8_BREAKING && phase === "module") {
29652968
this.expectPlugin("importReflection", loc);
29662969
(node as N.ImportDeclaration).module = true;
29672970
} else if (this.hasPlugin("importReflection")) {
@@ -2980,18 +2983,15 @@ export default abstract class StatementParser extends ExpressionParser {
29802983
}
29812984

29822985
/*
2983-
* Parse `module` in `import module x from "x"`, disambiguating
2984-
* `import module from "x"` and `import module from from "x"`.
2986+
* Parse `source` in `import source x from "x"`, disambiguating
2987+
* `import source from "x"` and `import source from from "x"`.
29852988
*
2986-
* This function might return an identifier representing the `module`
2987-
* if it eats `module` and then discovers that it was the default import
2989+
* This function might return an identifier representing the `source`
2990+
* if it eats `source` and then discovers that it was the default import
29882991
* binding and not the import reflection.
29892992
*
29902993
* This function is also used to parse `import type` and `import typeof`
2991-
* in the TS and Flow plugins.
2992-
*
2993-
* Note: the proposal has been updated to use `source` instead of `module`,
2994-
* but it has not been implemented yet.
2994+
* in the TS and Flow plugins, and for parsing `import defer`.
29952995
*/
29962996
parseMaybeImportPhase(
29972997
node: Undone<N.ImportDeclaration | N.TsImportEqualsDeclaration>,

packages/babel-parser/src/plugin-utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,19 @@ export function validatePlugins(pluginsMap: Map<string, any>) {
179179
" only supported value is '2023-07'.",
180180
);
181181
}
182-
if (process.env.BABEL_8_BREAKING && pluginsMap.has("decimal")) {
183-
throw new Error(
184-
"The 'decimal' plugin has been removed in Babel 8. Please remove it from your configuration.",
185-
);
182+
183+
if (process.env.BABEL_8_BREAKING) {
184+
if (pluginsMap.has("decimal")) {
185+
throw new Error(
186+
"The 'decimal' plugin has been removed in Babel 8. Please remove it from your configuration.",
187+
);
188+
}
189+
if (pluginsMap.has("importReflection")) {
190+
throw new Error(
191+
"The 'importReflection' plugin has been removed in Babel 8. Use 'sourcePhaseImports' instead, and " +
192+
"replace 'import module' with 'import source' in your code.",
193+
);
194+
}
186195
}
187196
}
188197

packages/babel-parser/src/typings.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type Plugin =
2828
| IF_BABEL_7<"logicalAssignment">
2929
| "importAssertions" // deprecated
3030
| "importAttributes"
31-
| "importReflection"
31+
| IF_BABEL_7<"importReflection">
3232
| "moduleBlocks"
3333
| IF_BABEL_7<"moduleStringNames">
3434
| IF_BABEL_7<"nullishCoalescingOperator">

0 commit comments

Comments
 (0)