[7.0] Change for-await to use new AST (#5321)
This commit is contained in:
committed by
Henry Zhu
parent
ca78da6501
commit
7c62278dcd
@@ -84,10 +84,9 @@ const buildForXStatement = function (op) {
|
||||
return function (node: Object) {
|
||||
this.word("for");
|
||||
this.space();
|
||||
if (op === "await") {
|
||||
if (op === "of" && node.await) {
|
||||
this.word("await");
|
||||
this.space();
|
||||
op = "of";
|
||||
}
|
||||
this.token("(");
|
||||
|
||||
@@ -103,7 +102,6 @@ const buildForXStatement = function (op) {
|
||||
|
||||
export const ForInStatement = buildForXStatement("in");
|
||||
export const ForOfStatement = buildForXStatement("of");
|
||||
export const ForAwaitStatement = buildForXStatement("await");
|
||||
|
||||
export function DoWhileStatement(node: Object) {
|
||||
this.word("do");
|
||||
|
||||
@@ -41,8 +41,9 @@ const awaitVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
ForAwaitStatement(path, { file, wrapAwait }) {
|
||||
ForOfStatement(path, { file, wrapAwait }) {
|
||||
const { node } = path;
|
||||
if (!node.await) return;
|
||||
|
||||
const build = rewriteForAwait(path, {
|
||||
getAsyncIterator: file.addHelper("asyncIterator"),
|
||||
|
||||
@@ -18,11 +18,11 @@ async function a() {
|
||||
for ({ a } in {}) {}
|
||||
for ({ a } of []) {}
|
||||
async function a() {
|
||||
for ({ a } of []) {}
|
||||
for await ({ a } of []) {}
|
||||
}
|
||||
|
||||
for (a in {}) {}
|
||||
for (a of []) {}
|
||||
async function a() {
|
||||
for (a of []) {}
|
||||
for await (a of []) {}
|
||||
}
|
||||
|
||||
@@ -694,21 +694,6 @@ See also `t.isFile(node, opts)` and `t.assertFile(node, opts)`.
|
||||
|
||||
---
|
||||
|
||||
### forAwaitStatement
|
||||
```javascript
|
||||
t.forAwaitStatement(left, right, body)
|
||||
```
|
||||
|
||||
See also `t.isForAwaitStatement(node, opts)` and `t.assertForAwaitStatement(node, opts)`.
|
||||
|
||||
Aliases: `Scopable`, `Statement`, `For`, `BlockParent`, `Loop`, `ForXStatement`
|
||||
|
||||
- `left`: `VariableDeclaration | LVal` (required)
|
||||
- `right`: `Expression` (required)
|
||||
- `body`: `Statement` (required)
|
||||
|
||||
---
|
||||
|
||||
### forInStatement
|
||||
```javascript
|
||||
t.forInStatement(left, right, body)
|
||||
@@ -726,7 +711,7 @@ Aliases: `Scopable`, `Statement`, `For`, `BlockParent`, `Loop`, `ForXStatement`
|
||||
|
||||
### forOfStatement
|
||||
```javascript
|
||||
t.forOfStatement(left, right, body)
|
||||
t.forOfStatement(left, right, body, await)
|
||||
```
|
||||
|
||||
See also `t.isForOfStatement(node, opts)` and `t.assertForOfStatement(node, opts)`.
|
||||
@@ -736,6 +721,7 @@ Aliases: `Scopable`, `Statement`, `For`, `BlockParent`, `Loop`, `ForXStatement`
|
||||
- `left`: `VariableDeclaration | LVal` (required)
|
||||
- `right`: `Expression` (required)
|
||||
- `body`: `Statement` (required)
|
||||
- `await`: `boolean` (default: `false`)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -178,6 +178,10 @@ defineType("ForOfStatement", {
|
||||
},
|
||||
body: {
|
||||
validate: assertNodeType("Statement")
|
||||
},
|
||||
await: {
|
||||
default: false,
|
||||
validate: assertValueType("boolean")
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,22 +11,6 @@ defineType("AwaitExpression", {
|
||||
}
|
||||
});
|
||||
|
||||
defineType("ForAwaitStatement", {
|
||||
visitor: ["left", "right", "body"],
|
||||
aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
|
||||
fields: {
|
||||
left: {
|
||||
validate: assertNodeType("VariableDeclaration", "LVal")
|
||||
},
|
||||
right: {
|
||||
validate: assertNodeType("Expression")
|
||||
},
|
||||
body: {
|
||||
validate: assertNodeType("Statement")
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
defineType("BindExpression", {
|
||||
visitor: ["object", "callee"],
|
||||
aliases: ["Expression"],
|
||||
|
||||
Reference in New Issue
Block a user