diff --git a/.flowconfig b/.flowconfig index 10b5f18a48..ec70beff84 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,6 +1,7 @@ [ignore] .*/lib/.* .*/test/.* +.*/build/.* [include] diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 3609acb30b..94d5ae4b97 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -1223,6 +1223,10 @@ export default function (instance) { specifier.local = specifier.imported.__clone(); } + if (node.importKind !== "value" && specifier.importKind !== null) { + this.raise(firstIdentLoc, "`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`"); + } + this.checkLVal(specifier.local, true, undefined, "import specifier"); node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); }; diff --git a/test/fixtures/flow/type-imports/invalid-import-type-shorthand/actual.js b/test/fixtures/flow/type-imports/invalid-import-type-shorthand/actual.js new file mode 100644 index 0000000000..5fa51659c7 --- /dev/null +++ b/test/fixtures/flow/type-imports/invalid-import-type-shorthand/actual.js @@ -0,0 +1,2 @@ +import typeof {typeof t} from "foo"; +import type {type t} from "foo"; diff --git a/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json b/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json new file mode 100644 index 0000000000..d516d5fb7b --- /dev/null +++ b/test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json @@ -0,0 +1,3 @@ +{ + "throws": "`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` (1:15)" +}