New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse await using
declarations
#15520
Merged
nicolo-ribaudo
merged 15 commits into
babel:feat-7.22.0/explicit-resource-management
from
JLHwung:parse-await-using
May 17, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
431f5d3
simplify isAsyncFunction
JLHwung fef32c7
add more test cases for explicit-resource-management
JLHwung 892de2e
add await using AST definition
JLHwung b396838
parse await using declaration
JLHwung d948c9a
generate await using declaration
JLHwung 377b63c
register await using as const declaration
JLHwung 6789062
add syntax plugin
JLHwung 1890dc3
add syntax plugin to standalone
JLHwung 7c6f9fa
add invalid await using binding pattern cases
JLHwung 1f24171
update typings
JLHwung 3077cb0
update git clean fix command
JLHwung c738957
add new test cases
JLHwung 867229a
remove syntax-async-explicit-resource-management
JLHwung dc2db16
merge asyncExplicitResourceManagement with explicitResourceManagement
JLHwung 885d997
update typings
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/await-using-declarations/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,3 @@ | ||
async function f() { | ||
/*0*/await/*1*/using/*2*/b/*3*/=/*4*/f()/*5*/; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/await-using-declarations/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,3 @@ | ||
async function f() { | ||
/*0*/await using /*2*/b /*3*/ = /*4*/f() /*5*/; /*1*/ | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/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 @@ | ||
async function f() { | ||
/*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/=/*6*/x/*7*/;/*8*/;/*9*/)/*10*/; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/await-using-declarations/for-using-init/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 @@ | ||
async function f() { | ||
/*0*/for /*1*/ /*8*/ /*9*/ ( /*2*/await using /*4*/b /*5*/ = /*6*/x /*3*/ /*7*/;;) /*10*/; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/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,8 @@ | ||
async function f() { | ||
{ | ||
/*0*/for/*1*/(/*2*/await/*3*/using/*4*/b/*5*/of/*6*/x/*7*/)/*8*/; | ||
} | ||
{ | ||
/*0*/for/*1*/await/*2*/(/*3*/await/*4*/using/*5*/b/*6*/of/*7*/x/*8*/)/*9*/; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-generator/test/fixtures/await-using-declarations/for-using-of/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,8 @@ | ||
async function f() { | ||
{ | ||
/*0*/for /*1*/ ( /*2*/await using /*4*/b /*3*/ /*5*/ of /*6*/x /*7*/) /*8*/; | ||
} | ||
{ | ||
/*0*/for /*1*/ /*2*/ await ( /*3*/await using /*5*/b /*4*/ /*6*/ of /*7*/x /*8*/) /*9*/; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/await-using-declarations/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": ["explicitResourceManagement"] | ||
} |
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 |
---|---|---|
|
@@ -126,6 +126,7 @@ | |
}, | ||
{ | ||
"enum": [ | ||
"asyncDoExpressions", | ||
"asyncGenerators", | ||
"bigInt", | ||
"classPrivateMethods", | ||
|
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
3 changes: 3 additions & 0 deletions
3
...ages/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/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 @@ | ||
async function f() { | ||
await using in foo; | ||
} |
55 changes: 55 additions & 0 deletions
55
...s/babel-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-in/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":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":44,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":44}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":19,"end":44,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":44}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":23,"end":42,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":21,"index":42}}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start":23,"end":41,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":20,"index":41}}, | ||
"left": { | ||
"type": "AwaitExpression", | ||
"start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, | ||
"argument": { | ||
"type": "Identifier", | ||
"start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, | ||
"name": "using" | ||
} | ||
}, | ||
"operator": "in", | ||
"right": { | ||
"type": "Identifier", | ||
"start":38,"end":41,"loc":{"start":{"line":2,"column":17,"index":38},"end":{"line":2,"column":20,"index":41},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...el-parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/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 @@ | ||
async function f() { | ||
await using instanceof foo; | ||
} |
55 changes: 55 additions & 0 deletions
55
...parser/test/fixtures/es2017/async-functions/valid-await-expr-using-instanceof/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":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":52}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":1,"column":16,"index":16},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":19,"end":52,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":3,"column":1,"index":52}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":23,"end":50,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":29,"index":50}}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start":23,"end":49,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":28,"index":49}}, | ||
"left": { | ||
"type": "AwaitExpression", | ||
"start":23,"end":34,"loc":{"start":{"line":2,"column":2,"index":23},"end":{"line":2,"column":13,"index":34}}, | ||
"argument": { | ||
"type": "Identifier", | ||
"start":29,"end":34,"loc":{"start":{"line":2,"column":8,"index":29},"end":{"line":2,"column":13,"index":34},"identifierName":"using"}, | ||
"name": "using" | ||
} | ||
}, | ||
"operator": "instanceof", | ||
"right": { | ||
"type": "Identifier", | ||
"start":46,"end":49,"loc":{"start":{"line":2,"column":25,"index":46},"end":{"line":2,"column":28,"index":49},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
.../experimental/_no-plugin/explicit-resource-management-variable-declaration-async/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 @@ | ||
async function f() { | ||
await using reader = getReader(); | ||
} |
3 changes: 3 additions & 0 deletions
3
...erimental/_no-plugin/explicit-resource-management-variable-declaration-async/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": "This experimental syntax requires enabling the parser plugin: \"explicitResourceManagement\". (2:2)" | ||
} |
9 changes: 9 additions & 0 deletions
9
...experimental/async-explicit-resource-management/invalid-duplicate-using-bindings/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,9 @@ | ||
async function f() { | ||
{ | ||
await using f, f = foo(); | ||
} | ||
{ | ||
await using g = foo(); | ||
await using g = foo(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test case (to test both with the plugin enabled and disabled):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, the parser is working as expected, so added new test cases.