diff --git a/packages/babel-generator/src/generators/modules.ts b/packages/babel-generator/src/generators/modules.ts index 5bc5b8bb06a6..8c4fec4e9937 100644 --- a/packages/babel-generator/src/generators/modules.ts +++ b/packages/babel-generator/src/generators/modules.ts @@ -184,8 +184,8 @@ export function ImportDeclaration(this: Printer, node: t.ImportDeclaration) { if (isTypeKind) { this.word(node.importKind); this.space(); - } else if (node.reflection != null) { - this.word(node.reflection); + } else if (node.module) { + this.word("module"); this.space(); } diff --git a/packages/babel-parser/src/parser/statement.ts b/packages/babel-parser/src/parser/statement.ts index 4f432f7e84c9..8ef4c679042b 100644 --- a/packages/babel-parser/src/parser/statement.ts +++ b/packages/babel-parser/src/parser/statement.ts @@ -2606,7 +2606,7 @@ export default abstract class StatementParser extends ExpressionParser { } checkImportReflection(node: Undone) { - if (node.reflection === "module") { + if (node.module) { if ( node.specifiers.length !== 1 || node.specifiers[0].type !== "ImportDefaultSpecifier" @@ -2655,9 +2655,9 @@ export default abstract class StatementParser extends ExpressionParser { if (this.match(tt._module)) { this.expectPlugin("importReflection"); this.next(); // eat tt._module; - node.reflection = "module"; + node.module = true; } else if (this.hasPlugin("importReflection")) { - node.reflection = null; + node.module = false; } } diff --git a/packages/babel-parser/src/plugins/flow/index.ts b/packages/babel-parser/src/plugins/flow/index.ts index 68777712d264..0c919d1a135c 100644 --- a/packages/babel-parser/src/plugins/flow/index.ts +++ b/packages/babel-parser/src/plugins/flow/index.ts @@ -2731,7 +2731,7 @@ export default (superClass: typeof Parser) => checkImportReflection(node: Undone) { super.checkImportReflection(node); - if (node.reflection === "module" && node.importKind !== "value") { + if (node.module && node.importKind !== "value") { this.raise(Errors.ImportReflectionNotBinding, { at: node.specifiers[0].loc.start, }); diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index 03d1940ed92f..08d4d23b161d 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -2615,7 +2615,7 @@ export default (superClass: ClassWithMixin) => checkImportReflection(node: Undone) { super.checkImportReflection(node); - if (node.reflection === "module" && node.importKind !== "value") { + if (node.module && node.importKind !== "value") { this.raise(Errors.ImportReflectionNotBinding, { at: node.specifiers[0].loc.start, }); diff --git a/packages/babel-parser/src/types.ts b/packages/babel-parser/src/types.ts index 3958f64a1c06..6b316eb1a643 100644 --- a/packages/babel-parser/src/types.ts +++ b/packages/babel-parser/src/types.ts @@ -922,7 +922,7 @@ export interface ImportDeclaration extends NodeBase { source: Literal; importKind?: "type" | "typeof" | "value"; // TODO: Not in spec, assertions?: ImportAttribute[]; - reflection?: "module"; + module?: boolean; } export interface ImportSpecifier extends ModuleSpecifier { diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-default-named-import/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-default-named-import/output.json index a46fb2ea1436..c1de98aac655 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-default-named-import/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-default-named-import/output.json @@ -38,7 +38,7 @@ } } ], - "reflection": "module", + "module": true, "source": { "type": "StringLiteral", "start":30,"end":45,"loc":{"start":{"line":1,"column":30,"index":30},"end":{"line":1,"column":45,"index":45}}, diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-type-import-2/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-type-import-2/output.json index 798ffbedde6a..fad5497c2906 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-type-import-2/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-type-import-2/output.json @@ -24,7 +24,7 @@ } } ], - "reflection": "module", + "module": true, "importKind": "type", "source": { "type": "StringLiteral", diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-named-import/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-named-import/output.json index 77b02f8e9d5f..a73ab093b583 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-named-import/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-named-import/output.json @@ -29,7 +29,7 @@ } } ], - "reflection": "module", + "module": true, "source": { "type": "StringLiteral", "start":27,"end":42,"loc":{"start":{"line":1,"column":27,"index":27},"end":{"line":1,"column":42,"index":42}}, diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-namespace-import/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-namespace-import/output.json index b518fad6f0c7..548eb43121bb 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-namespace-import/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-namespace-import/output.json @@ -24,7 +24,7 @@ } } ], - "reflection": "module", + "module": true, "source": { "type": "StringLiteral", "start":28,"end":43,"loc":{"start":{"line":1,"column":28,"index":28},"end":{"line":1,"column":43,"index":43}}, diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-ts-type-import-1/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-ts-type-import-1/output.json index d4b5f29059ae..59a9ae7bdfb7 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-ts-type-import-1/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-ts-type-import-1/output.json @@ -25,7 +25,7 @@ } } ], - "reflection": "module", + "module": true, "source": { "type": "StringLiteral", "start":28,"end":43,"loc":{"start":{"line":1,"column":28,"index":28},"end":{"line":1,"column":43,"index":43}}, diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-default-import/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-default-import/output.json index b290deaac24e..73ea501e6017 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-default-import/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-default-import/output.json @@ -21,7 +21,7 @@ } } ], - "reflection": "module", + "module": true, "source": { "type": "StringLiteral", "start":23,"end":38,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":38,"index":38}}, @@ -46,7 +46,7 @@ } } ], - "reflection": null, + "module": false, "source": { "type": "StringLiteral", "start":56,"end":71,"loc":{"start":{"line":2,"column":16,"index":56},"end":{"line":2,"column":31,"index":71}}, diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-flow-default-import/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-flow-default-import/output.json index 12b7dc00791e..6d61e19297e9 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-flow-default-import/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-flow-default-import/output.json @@ -21,7 +21,7 @@ } } ], - "reflection": "module", + "module": true, "importKind": "value", "source": { "type": "StringLiteral", @@ -47,7 +47,7 @@ } } ], - "reflection": null, + "module": false, "importKind": "value", "source": { "type": "StringLiteral", diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-ts-default-import/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-ts-default-import/output.json index 2cb17cf7e94a..40d43769defe 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-ts-default-import/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/valid-ts-default-import/output.json @@ -22,7 +22,7 @@ } } ], - "reflection": "module", + "module": true, "source": { "type": "StringLiteral", "start":23,"end":38,"loc":{"start":{"line":1,"column":23,"index":23},"end":{"line":1,"column":38,"index":38}}, @@ -48,7 +48,7 @@ } } ], - "reflection": null, + "module": false, "source": { "type": "StringLiteral", "start":56,"end":71,"loc":{"start":{"line":2,"column":16,"index":56},"end":{"line":2,"column":31,"index":71}}, diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index 571f90a104b5..e4d35d6e441e 100644 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -855,7 +855,7 @@ export interface ImportDeclaration extends BaseNode { source: StringLiteral; assertions?: Array | null; importKind?: "type" | "typeof" | "value" | null; - reflection?: "module" | null; + module?: boolean | null; } export interface ImportDefaultSpecifier extends BaseNode { diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 7ac6e3a6a4be..a57bb590a896 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -1689,9 +1689,9 @@ defineType("ImportDeclaration", { assertEach(assertNodeType("ImportAttribute")), ), }, - reflection: { + module: { optional: true, - validate: assertOneOf("module"), + validate: assertValueType("boolean"), }, specifiers: { validate: chain(