Skip to content

Commit

Permalink
Support async iteration statement for-await-of introduced in ES2018
Browse files Browse the repository at this point in the history
  • Loading branch information
twada authored and michaelficarra committed May 21, 2018
1 parent 582a413 commit d3b88db
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@
};

CodeGenerator.prototype.generateIterationForStatement = function (operator, stmt, flags) {
var result = ['for' + space + '('], that = this;
var result = ['for' + space + (stmt.await ? 'await' + space : '') + '('], that = this;
withIndent(function () {
if (stmt.left.type === Syntax.VariableDeclaration) {
withIndent(function () {
Expand Down
72 changes: 72 additions & 0 deletions test/harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -6208,6 +6208,78 @@ data = {
"async": true
}
},
},

'ES2018 for-await-of': {
'async function f() {\n for await (const x of ait) {\n console.log(x);\n }\n}': {
generateFrom: {
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "f"
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ForOfStatement",
"left": {
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "x"
},
"init": null
}
],
"kind": "const"
},
"right": {
"type": "Identifier",
"name": "ait"
},
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "console"
},
"property": {
"type": "Identifier",
"name": "log"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"name": "x"
}
]
}
}
]
},
"await": true
}
]
},
"generator": false,
"async": true
}
}

}
};

Expand Down

0 comments on commit d3b88db

Please sign in to comment.