From 999b655ca6ccb7f092b0ef608f843e8e21ff04d9 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 17 Jan 2017 20:34:20 +0100 Subject: [PATCH] =?UTF-8?q?Disallow=20import=20type=20{=20type=20a=20}=20f?= =?UTF-8?q?rom=20=E2=80=A6=20(#305)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flowconfig | 1 + src/plugins/flow.js | 4 ++++ .../flow/type-imports/invalid-import-type-shorthand/actual.js | 2 ++ .../type-imports/invalid-import-type-shorthand/options.json | 3 +++ 4 files changed, 10 insertions(+) create mode 100644 test/fixtures/flow/type-imports/invalid-import-type-shorthand/actual.js create mode 100644 test/fixtures/flow/type-imports/invalid-import-type-shorthand/options.json 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)" +}