Skip to content

Commit

Permalink
Update flow/ts integration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 21, 2022
1 parent 7d6a04d commit 3f9f6c8
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/babel-parser/src/plugins/flow/index.ts
Expand Up @@ -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:
Expand Down Expand Up @@ -2732,7 +2734,7 @@ export default (superClass: typeof Parser) =>
checkImportReflection(node: Undone<N.ImportDeclaration>) {
super.checkImportReflection(node);
if (node.module && node.importKind !== "value") {
this.raise(Errors.ImportReflectionNotBinding, {
this.raise(FlowErrors.ImportReflectionHasImportType, {
at: node.specifiers[0].loc.start,
});
}
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -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,
}: {
Expand Down Expand Up @@ -2616,7 +2618,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
checkImportReflection(node: Undone<N.ImportDeclaration>) {
super.checkImportReflection(node);
if (node.module && node.importKind !== "value") {
this.raise(Errors.ImportReflectionNotBinding, {
this.raise(TSErrors.ImportReflectionHasImportType, {
at: node.specifiers[0].loc.start,
});
}
Expand Down
Expand Up @@ -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",
Expand Down
@@ -0,0 +1 @@
import typeof module foo from "./module.wasm";
@@ -0,0 +1,8 @@
{
"plugins": [
"importReflection",
"flow"
],
"sourceType": "module",
"throws": "Unexpected token, expected \"from\" (1:21)"
}
@@ -0,0 +1 @@
import module typeof foo from "./module.wasm";
@@ -0,0 +1,4 @@
{
"plugins": ["importReflection", "flow"],
"sourceType": "module"
}
@@ -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": []
}
}
Expand Up @@ -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",
Expand Down

0 comments on commit 3f9f6c8

Please sign in to comment.