diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index e9b4cc32c37f..a06e09089033 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -291,7 +291,7 @@ export default (superClass: Class): Class => if (this.match(tt._import)) { this.next(); - if (!this.isContextual("type") && !this.isContextual("typeof")) { + if (!this.isContextual("type") && !this.match(tt._typeof)) { this.unexpected( this.state.lastTokStart, "Imports within a `declare module` body must always be `import type` or `import typeof`", diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js b/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js index 58b33359229d..2ea3d918132d 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js +++ b/packages/babel-parser/test/fixtures/flow/declare-module/import/input.js @@ -1 +1,4 @@ -declare module "M" { import type T from "TM"; } +declare module "M" { + import type T from "TM"; + import typeof U from "UM"; +} diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json index 0cfbb39aac09..f7bb57172e32 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/import/output.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "sourceType": "module", @@ -32,15 +32,15 @@ { "type": "DeclareModule", "start": 0, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "id": { @@ -66,59 +66,59 @@ "body": { "type": "BlockStatement", "start": 19, - "end": 47, + "end": 78, "loc": { "start": { "line": 1, "column": 19 }, "end": { - "line": 1, - "column": 47 + "line": 4, + "column": 1 } }, "body": [ { "type": "ImportDeclaration", - "start": 21, - "end": 45, + "start": 23, + "end": 47, "loc": { "start": { - "line": 1, - "column": 21 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 45 + "line": 2, + "column": 26 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { - "line": 1, - "column": 33 + "line": 2, + "column": 14 }, "end": { - "line": 1, - "column": 34 + "line": 2, + "column": 15 } }, "local": { "type": "Identifier", - "start": 33, - "end": 34, + "start": 35, + "end": 36, "loc": { "start": { - "line": 1, - "column": 33 + "line": 2, + "column": 14 }, "end": { - "line": 1, - "column": 34 + "line": 2, + "column": 15 }, "identifierName": "T" }, @@ -129,16 +129,16 @@ "importKind": "type", "source": { "type": "StringLiteral", - "start": 40, - "end": 44, + "start": 42, + "end": 46, "loc": { "start": { - "line": 1, - "column": 40 + "line": 2, + "column": 21 }, "end": { - "line": 1, - "column": 44 + "line": 2, + "column": 25 } }, "extra": { @@ -147,6 +147,76 @@ }, "value": "TM" } + }, + { + "type": "ImportDeclaration", + "start": 50, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "local": { + "type": "Identifier", + "start": 64, + "end": 65, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "U" + }, + "name": "U" + } + } + ], + "importKind": "typeof", + "source": { + "type": "StringLiteral", + "start": 71, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "extra": { + "rawValue": "UM", + "raw": "\"UM\"" + }, + "value": "UM" + } } ] },