-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/parser): Parse
await using
in for head (#8775)
**Related issue:** - Closes #8774
- Loading branch information
1 parent
cd06af3
commit 53fd09c
Showing
25 changed files
with
532 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"explicitResourceManagement": true, | ||
"syntax": "ecmascript", | ||
"jsx": true, | ||
}, | ||
"target": "es2022", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": true | ||
} |
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,21 @@ | ||
const logClean = function () { | ||
return { | ||
[Symbol.dispose]() { | ||
console.log("clean in sync"); | ||
}, | ||
[Symbol.asyncDispose]() { | ||
console.log("clean in async"); | ||
}, | ||
}; | ||
}; | ||
|
||
async function foo() { | ||
using a = logClean(); | ||
await using b = logClean(); | ||
for (using a of [logClean(), logClean()]) { | ||
} | ||
for (await using a of [logClean(), logClean()]) { | ||
} | ||
} | ||
|
||
foo(); |
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,53 @@ | ||
import { _ as _dispose } from "@swc/helpers/_/_dispose"; | ||
import { _ as _using } from "@swc/helpers/_/_using"; | ||
const logClean = function() { | ||
return { | ||
[Symbol.dispose] () { | ||
console.log("clean in sync"); | ||
}, | ||
[Symbol.asyncDispose] () { | ||
console.log("clean in async"); | ||
} | ||
}; | ||
}; | ||
async function foo() { | ||
try { | ||
var _stack = []; | ||
var a = _using(_stack, logClean()); | ||
var b = _using(_stack, logClean(), true); | ||
for (const a of [ | ||
logClean(), | ||
logClean() | ||
]){ | ||
try { | ||
var _stack1 = []; | ||
{} | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
} finally{ | ||
_dispose(_stack1, _error, _hasError); | ||
} | ||
} | ||
for (const a of [ | ||
logClean(), | ||
logClean() | ||
]){ | ||
try { | ||
var _stack2 = []; | ||
{} | ||
} catch (_) { | ||
var _error1 = _; | ||
var _hasError1 = true; | ||
} finally{ | ||
_dispose(_stack2, _error1, _hasError1); | ||
} | ||
} | ||
} catch (_) { | ||
var _error2 = _; | ||
var _hasError2 = true; | ||
} finally{ | ||
await _dispose(_stack, _error2, _hasError2); | ||
} | ||
} | ||
foo(); |
62 changes: 53 additions & 9 deletions
62
...es/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).1.normal.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 |
---|---|---|
@@ -1,10 +1,54 @@ | ||
//// [awaitUsingDeclarationsInForAwaitOf.ts] | ||
//! | ||
//! x Expected ';', got 'd1' | ||
//! ,-[1:1] | ||
//! 1 | async function main() { | ||
//! 2 | for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) { | ||
//! : ^^ | ||
//! 3 | } | ||
//! 4 | } | ||
//! `---- | ||
import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; | ||
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; | ||
import { _ as _dispose } from "@swc/helpers/_/_dispose"; | ||
function main() { | ||
return _main.apply(this, arguments); | ||
} | ||
function _main() { | ||
_main = _async_to_generator(function*() { | ||
{ | ||
var _iteratorAbruptCompletion = false, _didIteratorError = false, _iteratorError; | ||
try { | ||
for(var _iterator = _async_iterator([ | ||
{ | ||
[Symbol.asyncDispose] () { | ||
return _async_to_generator(function*() {})(); | ||
} | ||
}, | ||
{ | ||
[Symbol.dispose] () {} | ||
}, | ||
null, | ||
undefined | ||
]), _step; _iteratorAbruptCompletion = !(_step = yield _iterator.next()).done; _iteratorAbruptCompletion = false){ | ||
let _value = _step.value; | ||
const d1 = _value; | ||
try { | ||
var _stack = []; | ||
{} | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
} finally{ | ||
_dispose(_stack, _error, _hasError); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally{ | ||
try { | ||
if (_iteratorAbruptCompletion && _iterator.return != null) { | ||
yield _iterator.return(); | ||
} | ||
} finally{ | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
return _main.apply(this, arguments); | ||
} |
12 changes: 3 additions & 9 deletions
12
.../swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2015).2.minified.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 |
---|---|---|
@@ -1,10 +1,4 @@ | ||
//// [awaitUsingDeclarationsInForAwaitOf.ts] | ||
//! | ||
//! x Expected ';', got 'd1' | ||
//! ,-[1:1] | ||
//! 1 | async function main() { | ||
//! 2 | for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) { | ||
//! : ^^ | ||
//! 3 | } | ||
//! 4 | } | ||
//! `---- | ||
import "@swc/helpers/_/_async_iterator"; | ||
import "@swc/helpers/_/_async_to_generator"; | ||
import "@swc/helpers/_/_dispose"; |
32 changes: 23 additions & 9 deletions
32
...es/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).1.normal.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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
//// [awaitUsingDeclarationsInForAwaitOf.ts] | ||
//! | ||
//! x Expected ';', got 'd1' | ||
//! ,-[1:1] | ||
//! 1 | async function main() { | ||
//! 2 | for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) { | ||
//! : ^^ | ||
//! 3 | } | ||
//! 4 | } | ||
//! `---- | ||
import { _ as _dispose } from "@swc/helpers/_/_dispose"; | ||
async function main() { | ||
for await (const d1 of [ | ||
{ | ||
async [Symbol.asyncDispose] () {} | ||
}, | ||
{ | ||
[Symbol.dispose] () {} | ||
}, | ||
null, | ||
undefined | ||
]){ | ||
try { | ||
var _stack = []; | ||
{} | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
} finally{ | ||
_dispose(_stack, _error, _hasError); | ||
} | ||
} | ||
} |
10 changes: 1 addition & 9 deletions
10
.../swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2017).2.minified.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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
//// [awaitUsingDeclarationsInForAwaitOf.ts] | ||
//! | ||
//! x Expected ';', got 'd1' | ||
//! ,-[1:1] | ||
//! 1 | async function main() { | ||
//! 2 | for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) { | ||
//! : ^^ | ||
//! 3 | } | ||
//! 4 | } | ||
//! `---- | ||
import "@swc/helpers/_/_dispose"; |
32 changes: 23 additions & 9 deletions
32
...es/swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).1.normal.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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
//// [awaitUsingDeclarationsInForAwaitOf.ts] | ||
//! | ||
//! x Expected ';', got 'd1' | ||
//! ,-[1:1] | ||
//! 1 | async function main() { | ||
//! 2 | for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) { | ||
//! : ^^ | ||
//! 3 | } | ||
//! 4 | } | ||
//! `---- | ||
import { _ as _dispose } from "@swc/helpers/_/_dispose"; | ||
async function main() { | ||
for await (const d1 of [ | ||
{ | ||
async [Symbol.asyncDispose] () {} | ||
}, | ||
{ | ||
[Symbol.dispose] () {} | ||
}, | ||
null, | ||
undefined | ||
]){ | ||
try { | ||
var _stack = []; | ||
{} | ||
} catch (_) { | ||
var _error = _; | ||
var _hasError = true; | ||
} finally{ | ||
_dispose(_stack, _error, _hasError); | ||
} | ||
} | ||
} |
10 changes: 1 addition & 9 deletions
10
.../swc/tests/tsc-references/awaitUsingDeclarationsInForAwaitOf(target=es2022).2.minified.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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
//// [awaitUsingDeclarationsInForAwaitOf.ts] | ||
//! | ||
//! x Expected ';', got 'd1' | ||
//! ,-[1:1] | ||
//! 1 | async function main() { | ||
//! 2 | for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) { | ||
//! : ^^ | ||
//! 3 | } | ||
//! 4 | } | ||
//! `---- | ||
import "@swc/helpers/_/_dispose"; |
Oops, something went wrong.