Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Fix parsing yield with dynamicImport (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism authored and hzoo committed Feb 28, 2017
1 parent cd133ff commit 09bb9bc
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pp.getExpression = function() {
// the AST node that the inner parser gave them in another node.

// Parse a full expression. The optional arguments are used to
// forbid the `in` operator (in for loops initalization expressions)
// forbid the `in` operator (in for loops initialization expressions)
// and provide reference for storing '=' operator inside shorthand
// property assignment in contexts where both object expression
// and object pattern might appear (so it's possible to raise
Expand Down Expand Up @@ -1095,7 +1095,11 @@ pp.parseAwait = function (node) {
pp.parseYield = function () {
const node = this.startNode();
this.next();
if (this.match(tt.semi) || this.canInsertSemicolon() || (!this.match(tt.star) && !this.state.type.startsExpr)) {
if (
this.match(tt.semi) ||
this.canInsertSemicolon() ||
(!this.match(tt.star) && !this.state.type.startsExpr)
) {
node.delegate = false;
node.argument = null;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const keywords = {
"class": new KeywordTokenType("class"),
"extends": new KeywordTokenType("extends", { beforeExpr }),
"export": new KeywordTokenType("export"),
"import": new KeywordTokenType("import"),
"import": new KeywordTokenType("import", { startsExpr }),
"yield": new KeywordTokenType("yield", { beforeExpr, startsExpr }),
"null": new KeywordTokenType("null", { startsExpr }),
"true": new KeywordTokenType("true", { startsExpr }),
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/experimental/dynamic-import/generator/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function* a() {
yield import('http');
}
171 changes: 171 additions & 0 deletions test/fixtures/experimental/dynamic-import/generator/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"type": "File",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "a"
},
"name": "a"
},
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 14,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 18,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 23
}
},
"expression": {
"type": "YieldExpression",
"start": 18,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 22
}
},
"delegate": false,
"argument": {
"type": "CallExpression",
"start": 24,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 22
}
},
"callee": {
"type": "Import",
"start": 24,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 14
}
}
},
"arguments": [
{
"type": "StringLiteral",
"start": 31,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 21
}
},
"extra": {
"rawValue": "http",
"raw": "'http'"
},
"value": "http"
}
]
}
}
}
],
"directives": []
}
}
],
"directives": []
}
}

0 comments on commit 09bb9bc

Please sign in to comment.