Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* parse async do expressions * add test cases * update test fixtures * chore: add syntax-async-do-expressions * generater support * fix: do not transform async do expressions * chore: add asyncDoExpressions to missing plugin helpers * update ast types * add more test cases * throw when asyncDoExpressions is enabled but not doExpressions * avoid add parentheses for async do expressions * address review comments * chore: update parser typings
- Loading branch information
1 parent
f30c99a
commit 28d7442
Showing
76 changed files
with
897 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/babel-generator/test/fixtures/async-do-expressions/basic/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
async do { | ||
1; | ||
}; | ||
|
||
(async do {}); |
4 changes: 4 additions & 0 deletions
4
packages/babel-generator/test/fixtures/async-do-expressions/basic/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
async do { | ||
1; | ||
}; | ||
async do {}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/async-do-expressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["asyncDoExpressions", "doExpressions"] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* leading comments | ||
*/async do | ||
{ 1 } + 0; |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"retainLines": true | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/async-do-expressions/retain-lines/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* leading comments | ||
*/async do | ||
{1;} + 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...r/test/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(async do {x}) |
6 changes: 6 additions & 0 deletions
6
...st/fixtures/experimental/_no-plugin/async-do-expressions-with-do-expressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"throws": "This experimental syntax requires enabling the parser plugin: 'asyncDoExpressions' (1:7)", | ||
"plugins": [ | ||
"doExpressions" | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(async do {x}) |
4 changes: 4 additions & 0 deletions
4
...ages/babel-parser/test/fixtures/experimental/_no-plugin/async-do-expressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"throws": "This experimental syntax requires enabling the parser plugin: 'doExpressions' (1:7)", | ||
"plugins": [] | ||
} |
5 changes: 5 additions & 0 deletions
5
...el-parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
async | ||
do { | ||
42 | ||
} | ||
while (false); |
51 changes: 51 additions & 0 deletions
51
...parser/test/fixtures/experimental/async-do-expressions/asi-async-and-do-while/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":14}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":14}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"}, | ||
"name": "async" | ||
} | ||
}, | ||
{ | ||
"type": "DoWhileStatement", | ||
"start":6,"end":32,"loc":{"start":{"line":2,"column":0},"end":{"line":5,"column":14}}, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":9,"end":17,"loc":{"start":{"line":2,"column":3},"end":{"line":4,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":13,"end":15,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":4}}, | ||
"expression": { | ||
"type": "NumericLiteral", | ||
"start":13,"end":15,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":4}}, | ||
"extra": { | ||
"rawValue": 42, | ||
"raw": "42" | ||
}, | ||
"value": 42 | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"test": { | ||
"type": "BooleanLiteral", | ||
"start":25,"end":30,"loc":{"start":{"line":5,"column":7},"end":{"line":5,"column":12}}, | ||
"value": false | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...el-parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
async do { | ||
42 | ||
} | ||
while (false); |
55 changes: 55 additions & 0 deletions
55
...parser/test/fixtures/experimental/async-do-expressions/asi-async-do-and-while/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":14}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":14}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"expression": { | ||
"type": "DoExpression", | ||
"start":6,"end":17,"loc":{"start":{"line":1,"column":6},"end":{"line":3,"column":1}}, | ||
"async": true, | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":9,"end":17,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":13,"end":15,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, | ||
"expression": { | ||
"type": "NumericLiteral", | ||
"start":13,"end":15,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, | ||
"extra": { | ||
"rawValue": 42, | ||
"raw": "42" | ||
}, | ||
"value": 42 | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "WhileStatement", | ||
"start":18,"end":32,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":14}}, | ||
"test": { | ||
"type": "BooleanLiteral", | ||
"start":25,"end":30,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":12}}, | ||
"value": false | ||
}, | ||
"body": { | ||
"type": "EmptyStatement", | ||
"start":31,"end":32,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":14}} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
async | ||
do { | ||
42 | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/experimental/async-do-expressions/asi/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Unexpected token, expected \"while\" (4:1)" | ||
} |
5 changes: 5 additions & 0 deletions
5
...bel-parser/test/fixtures/experimental/async-do-expressions/conditional-statement/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let x = async do { | ||
if (foo()) { f() } | ||
else if (bar()) { g() } | ||
else { h() } | ||
}; |
Oops, something went wrong.