Allow imports in declare module (#315)

* Allow imports in declare module {}

* Rename bodyElement to bodyNode
This commit is contained in:
Daniel Tschinder
2017-01-20 22:19:50 +01:00
committed by GitHub
parent f2df08e253
commit d5cd2c3231
7 changed files with 177 additions and 5 deletions

View File

@@ -1016,7 +1016,7 @@ pp.parseExportSpecifiers = function () {
// Parses import declaration.
pp.parseImport = function (node) {
this.next();
this.eat(tt._import);
// import '...'
if (this.match(tt.string)) {

View File

@@ -95,11 +95,22 @@ pp.flowParseDeclareModule = function (node) {
const body = bodyNode.body = [];
this.expect(tt.braceL);
while (!this.match(tt.braceR)) {
const node2 = this.startNode();
let bodyNode = this.startNode();
this.expectContextual("declare", "Unexpected token. Only declares are allowed inside declare module");
if (this.match(tt._import)) {
const lookahead = this.lookahead();
if (lookahead.value !== "type" && lookahead.value !== "typeof") {
this.unexpected(null, "Imports within a `declare module` body must always be `import type` or `import typeof`");
}
body.push(this.flowParseDeclare(node2));
this.parseImport(bodyNode);
} else {
this.expectContextual("declare", "Only declares and type imports are allowed inside declare module");
bodyNode = this.flowParseDeclare(bodyNode, true);
}
body.push(bodyNode);
}
this.expect(tt.braceR);