From 3f9f6c8c4b84d5531db1565ac4fee405f2671a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 21 Sep 2022 10:01:14 -0400 Subject: [PATCH] Update flow/ts integration errors --- .../babel-parser/src/plugins/flow/index.ts | 4 +- .../src/plugins/typescript/index.ts | 4 +- .../invalid-flow-type-import-2/output.json | 2 +- .../invalid-flow-typeof-import-1/input.mjs | 1 + .../invalid-flow-typeof-import-1/options.json | 8 ++++ .../invalid-flow-typeof-import-2/input.mjs | 1 + .../invalid-flow-typeof-import-2/options.json | 4 ++ .../invalid-flow-typeof-import-2/output.json | 42 +++++++++++++++++++ .../invalid-ts-type-import-1/output.json | 2 +- 9 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/input.mjs create mode 100644 packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/input.mjs create mode 100644 packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/output.json diff --git a/packages/babel-parser/src/plugins/flow/index.ts b/packages/babel-parser/src/plugins/flow/index.ts index 0c919d1a135c..734cc22ef88f 100644 --- a/packages/babel-parser/src/plugins/flow/index.ts +++ b/packages/babel-parser/src/plugins/flow/index.ts @@ -164,6 +164,8 @@ const FlowErrors = ParseErrorEnum`flow`({ }) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`, GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.", + ImportReflectionHasImportType: + "An `import module` declaration can not use `type` or `typeof` keyword.", ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.", InexactInsideExact: @@ -2732,7 +2734,7 @@ export default (superClass: typeof Parser) => checkImportReflection(node: Undone) { super.checkImportReflection(node); if (node.module && node.importKind !== "value") { - this.raise(Errors.ImportReflectionNotBinding, { + this.raise(FlowErrors.ImportReflectionHasImportType, { 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 08d4d23b161d..b333b92c44ac 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -122,6 +122,8 @@ const TSErrors = ParseErrorEnum`typescript`({ ExpectedAmbientAfterExportDeclare: "'export declare' must be followed by an ambient declaration.", ImportAliasHasImportType: "An import alias can not use 'import type'.", + ImportReflectionHasImportType: + "An `import module` declaration can not use `type` modifier", IncompatibleModifiers: ({ modifiers, }: { @@ -2616,7 +2618,7 @@ export default (superClass: ClassWithMixin) => checkImportReflection(node: Undone) { super.checkImportReflection(node); if (node.module && node.importKind !== "value") { - this.raise(Errors.ImportReflectionNotBinding, { + this.raise(TSErrors.ImportReflectionHasImportType, { at: node.specifiers[0].loc.start, }); } 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 0c260f33343d..1e45993a703d 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 @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":44,"index":44}}, "errors": [ - "SyntaxError: Only `import module x from \"./module\"` is valid. (1:19)" + "SyntaxError: An `import module` declaration can not use `type` or `typeof` keyword. (1:19)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/input.mjs b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/input.mjs new file mode 100644 index 000000000000..36d70c71a925 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/input.mjs @@ -0,0 +1 @@ +import typeof module foo from "./module.wasm"; diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/options.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/options.json new file mode 100644 index 000000000000..bfd6a7a73ddd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-1/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + "importReflection", + "flow" + ], + "sourceType": "module", + "throws": "Unexpected token, expected \"from\" (1:21)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/input.mjs b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/input.mjs new file mode 100644 index 000000000000..08a67d55b3c7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/input.mjs @@ -0,0 +1 @@ +import module typeof foo from "./module.wasm"; diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/options.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/options.json new file mode 100644 index 000000000000..2dd1ff29f752 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["importReflection", "flow"], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/output.json b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/output.json new file mode 100644 index 000000000000..fffe18921787 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-reflection/invalid-flow-typeof-import-2/output.json @@ -0,0 +1,42 @@ +{ + "type": "File", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":46,"index":46}}, + "errors": [ + "SyntaxError: An `import module` declaration can not use `type` or `typeof` keyword. (1:21)" + ], + "program": { + "type": "Program", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":46,"index":46}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":46,"index":46}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":21,"end":24,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":24,"index":24}}, + "local": { + "type": "Identifier", + "start":21,"end":24,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":24,"index":24},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "module": true, + "importKind": "typeof", + "source": { + "type": "StringLiteral", + "start":30,"end":45,"loc":{"start":{"line":1,"column":30,"index":30},"end":{"line":1,"column":45,"index":45}}, + "extra": { + "rawValue": "./module.wasm", + "raw": "\"./module.wasm\"" + }, + "value": "./module.wasm" + } + } + ], + "directives": [] + } +} 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 a20a970323e1..c443420a3c87 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 @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":44,"index":44}}, "errors": [ - "SyntaxError: Only `import module x from \"./module\"` is valid. (1:19)" + "SyntaxError: An `import module` declaration can not use `type` modifier (1:19)" ], "program": { "type": "Program",