Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use lookahead when parsing dynamic import or import.meta #9983

Merged
merged 1 commit into from May 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 15 additions & 18 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -875,19 +875,19 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "Super");

case tt._import:
if (this.lookahead().type === tt.dot) {
return this.parseImportMetaProperty();
node = this.startNode();
this.next();

if (this.match(tt.dot)) {
return this.parseImportMetaProperty(node);
}

this.expectPlugin("dynamicImport");
this.expectPlugin("dynamicImport", node.start);

node = this.startNode();
this.next();
if (!this.match(tt.parenL)) {
this.unexpected(null, tt.parenL);
}
return this.finishNode(node, "Import");

case tt._this:
node = this.startNode();
this.next();
Expand Down Expand Up @@ -1125,20 +1125,17 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "MetaProperty");
}

parseImportMetaProperty(): N.MetaProperty {
const node = this.startNode();
const id = this.parseIdentifier(true);
parseImportMetaProperty(node: N.MetaProperty): N.MetaProperty {
const id = this.createIdentifier(this.startNodeAtNode(node), "import");
this.expect(tt.dot);

if (id.name === "import") {
if (this.isContextual("meta")) {
this.expectPlugin("importMeta");
} else if (!this.hasPlugin("importMeta")) {
this.raise(
id.start,
`Dynamic imports require a parameter: import('a.js')`,
);
}
if (this.isContextual("meta")) {
this.expectPlugin("importMeta");
} else if (!this.hasPlugin("importMeta")) {
this.raise(
id.start,
`Dynamic imports require a parameter: import('a.js')`,
);
}

if (!this.inModule) {
Expand Down