[dynamic-import] Implementing import() syntax (#163)
This commit is contained in:
committed by
Henry Zhu
parent
4c445fd5f8
commit
c63c1bc728
@@ -302,6 +302,9 @@ pp.parseSubscripts = function (base, startPos, startLoc, noCalls) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
node.callee = base;
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
|
||||
if (node.callee.type === "Import" && node.arguments.length !== 1) {
|
||||
this.raise(node.start, "import() requires exactly one argument");
|
||||
}
|
||||
base = this.finishNode(node, "CallExpression");
|
||||
|
||||
if (possibleAsync && this.shouldParseAsyncArrow()) {
|
||||
@@ -387,6 +390,16 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
|
||||
}
|
||||
return this.finishNode(node, "Super");
|
||||
|
||||
case tt._import:
|
||||
if (!this.hasPlugin("dynamicImport")) this.unexpected();
|
||||
|
||||
node = this.startNode();
|
||||
this.next();
|
||||
if (!this.match(tt.parenL)) {
|
||||
this.unexpected();
|
||||
}
|
||||
return this.finishNode(node, "Import");
|
||||
|
||||
case tt._this:
|
||||
node = this.startNode();
|
||||
this.next();
|
||||
|
||||
@@ -98,6 +98,8 @@ pp.parseStatement = function (declaration, topLevel) {
|
||||
case tt.semi: return this.parseEmptyStatement(node);
|
||||
case tt._export:
|
||||
case tt._import:
|
||||
if (this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL) break;
|
||||
|
||||
if (!this.options.allowImportExportEverywhere) {
|
||||
if (!topLevel) {
|
||||
this.raise(this.state.start, "'import' and 'export' may only appear at the top level");
|
||||
|
||||
Reference in New Issue
Block a user