Skip to content

Commit

Permalink
update AST to module: boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 20, 2022
1 parent 48157b1 commit f6ba14e
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/babel-generator/src/generators/modules.ts
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions packages/babel-parser/src/parser/statement.ts
Expand Up @@ -2606,7 +2606,7 @@ export default abstract class StatementParser extends ExpressionParser {
}

checkImportReflection(node: Undone<N.ImportDeclaration>) {
if (node.reflection === "module") {
if (node.module) {
if (
node.specifiers.length !== 1 ||
node.specifiers[0].type !== "ImportDefaultSpecifier"
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/flow/index.ts
Expand Up @@ -2731,7 +2731,7 @@ export default (superClass: typeof Parser) =>

checkImportReflection(node: Undone<N.ImportDeclaration>) {
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,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -2615,7 +2615,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>

checkImportReflection(node: Undone<N.ImportDeclaration>) {
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,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/types.ts
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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}},
Expand Down
Expand Up @@ -24,7 +24,7 @@
}
}
],
"reflection": "module",
"module": true,
"importKind": "type",
"source": {
"type": "StringLiteral",
Expand Down
Expand Up @@ -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}},
Expand Down
Expand Up @@ -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}},
Expand Down
Expand Up @@ -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}},
Expand Down
Expand Up @@ -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}},
Expand All @@ -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}},
Expand Down
Expand Up @@ -21,7 +21,7 @@
}
}
],
"reflection": "module",
"module": true,
"importKind": "value",
"source": {
"type": "StringLiteral",
Expand All @@ -47,7 +47,7 @@
}
}
],
"reflection": null,
"module": false,
"importKind": "value",
"source": {
"type": "StringLiteral",
Expand Down
Expand Up @@ -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}},
Expand All @@ -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}},
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/ast-types/generated/index.ts
Expand Up @@ -855,7 +855,7 @@ export interface ImportDeclaration extends BaseNode {
source: StringLiteral;
assertions?: Array<ImportAttribute> | null;
importKind?: "type" | "typeof" | "value" | null;
reflection?: "module" | null;
module?: boolean | null;
}

export interface ImportDefaultSpecifier extends BaseNode {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-types/src/definitions/core.ts
Expand Up @@ -1689,9 +1689,9 @@ defineType("ImportDeclaration", {
assertEach(assertNodeType("ImportAttribute")),
),
},
reflection: {
module: {
optional: true,
validate: assertOneOf("module"),
validate: assertValueType("boolean"),
},
specifiers: {
validate: chain(
Expand Down

0 comments on commit f6ba14e

Please sign in to comment.