diff --git a/Cargo.lock b/Cargo.lock index e32a3093340..cbb8f09145b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3454,6 +3454,7 @@ dependencies = [ "once_cell", "phf", "rayon", + "rustc-hash", "serde", "smallvec", "swc_atoms", diff --git a/crates/swc/tests/exec.rs b/crates/swc/tests/exec.rs index 4962ae00d90..2fea9275507 100644 --- a/crates/swc/tests/exec.rs +++ b/crates/swc/tests/exec.rs @@ -213,6 +213,8 @@ fn test_file_with_opts( idx, res.code ); + println!("external_helpers: {:?}", opts.config.jsc.external_helpers); + println!("target: {:?}", opts.config.jsc.target.unwrap()); let actual_stdout = stdout_of( &res.code, diff --git a/crates/swc/tests/exec/issues-4xxx/4405/1/exec.js b/crates/swc/tests/exec/issues-4xxx/4405/1/exec.js new file mode 100644 index 00000000000..24f8fd99989 --- /dev/null +++ b/crates/swc/tests/exec/issues-4xxx/4405/1/exec.js @@ -0,0 +1,18 @@ +async function* asyncGenerator( +) { + for (let i = 5; i < 10; i++) { + yield new Promise((res) => setTimeout(() => res({ success: true }), 5)); + } + yield { success: true }; +} + +async function* execute( +) { + yield* asyncGenerator(); +} + +(async () => { + for await (const p of execute()) { + console.log(await p); + } +})(); \ No newline at end of file diff --git a/crates/swc/tests/exec/issues-4xxx/4405/2/exec.js b/crates/swc/tests/exec/issues-4xxx/4405/2/exec.js new file mode 100644 index 00000000000..aeef20fc768 --- /dev/null +++ b/crates/swc/tests/exec/issues-4xxx/4405/2/exec.js @@ -0,0 +1,21 @@ + +class Foo { + method1() { + console.log('Foo.method1'); + } + method2() { + console.log('Foo.method2'); + } +} + +class Bar extends Foo { + method2() { + console.log('Bar.method2: 1'); + super.method2(); + console.log('Bar.method2: 2'); + } +} + +const bar = new Bar(); + +bar.method2() \ No newline at end of file diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js index 45e67e023a9..ef09f7ff675 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js @@ -27,9 +27,9 @@ class C3 { class C4 { f() { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); })(); } } @@ -37,9 +37,9 @@ class C4 { class C5 { f() { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); })(); } } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js index 5c0e256c86f..428b7346d2c 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js @@ -87,9 +87,9 @@ var C4 = /*#__PURE__*/ function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -114,7 +114,7 @@ var C5 = /*#__PURE__*/ function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -125,7 +125,7 @@ var C5 = /*#__PURE__*/ function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js index 91ecfc3d4f2..1ef3dc74d13 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js @@ -70,9 +70,9 @@ var C1 = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -93,7 +93,7 @@ var C1 = function() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -103,7 +103,7 @@ var C1 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js index 0338fea6010..280319fff4d 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js @@ -27,9 +27,9 @@ class C3 { class C4 { f() { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); })(); } } @@ -37,9 +37,9 @@ class C4 { class C5 { f() { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); })(); } } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js index 9fe8d2f0e11..9df1838c735 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js @@ -87,9 +87,9 @@ var C4 = /*#__PURE__*/ function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -114,7 +114,7 @@ var C5 = /*#__PURE__*/ function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -125,7 +125,7 @@ var C5 = /*#__PURE__*/ function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js index 91ecfc3d4f2..1ef3dc74d13 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js @@ -70,9 +70,9 @@ var C1 = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -93,7 +93,7 @@ var C1 = function() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -103,7 +103,7 @@ var C1 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js index e904bac314f..acf6ba17b84 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js @@ -27,9 +27,9 @@ class C3 { class C4 { f() { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); })(); } } @@ -37,9 +37,9 @@ class C4 { class C5 { f() { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); })(); } } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js index fb85bf82d16..f3a88c37fbf 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js @@ -87,9 +87,9 @@ var C4 = /*#__PURE__*/ function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -114,7 +114,7 @@ var C5 = /*#__PURE__*/ function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -125,7 +125,7 @@ var C5 = /*#__PURE__*/ function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js index 91ecfc3d4f2..1ef3dc74d13 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js @@ -70,9 +70,9 @@ var C1 = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -93,7 +93,7 @@ var C1 = function() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -103,7 +103,7 @@ var C1 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es2015.1.normal.js index f18aa016cb1..9b6f1cfb94b 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es2015.1.normal.js @@ -35,9 +35,9 @@ function f4() { function _f4() { _f4 = // @filename: F4.ts swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _f4.apply(this, arguments); } @@ -47,9 +47,9 @@ function f5() { function _f5() { _f5 = // @filename: F5.ts swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _f5.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es5.1.normal.js index c9bb54c601a..363277b4743 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2015_es5.1.normal.js @@ -72,9 +72,9 @@ function _f4() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -95,7 +95,7 @@ function _f5() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -106,7 +106,7 @@ function _f5() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es2015.1.normal.js index 4682a36a8dc..db12cae4053 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es2015.1.normal.js @@ -35,9 +35,9 @@ function f4() { function _f4() { _f4 = // @filename: F4.ts swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _f4.apply(this, arguments); } @@ -47,9 +47,9 @@ function f5() { function _f5() { _f5 = // @filename: F5.ts swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _f5.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es5.1.normal.js index cad75365a75..1dbf7cf1e9d 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es2018_es5.1.normal.js @@ -72,9 +72,9 @@ function _f4() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -95,7 +95,7 @@ function _f5() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -106,7 +106,7 @@ function _f5() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es2015.1.normal.js index 7a498f51205..8d5d39e1254 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es2015.1.normal.js @@ -35,9 +35,9 @@ function f4() { function _f4() { _f4 = // @filename: F4.ts swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _f4.apply(this, arguments); } @@ -47,9 +47,9 @@ function f5() { function _f5() { _f5 = // @filename: F5.ts swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _f5.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es5.1.normal.js index bb8fcb2f8f4..f70d1a429ea 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionDeclarations.es5_es5.1.normal.js @@ -72,9 +72,9 @@ function _f4() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -95,7 +95,7 @@ function _f5() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -106,7 +106,7 @@ function _f5() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.1.normal.js index 8c98090b43f..7cbf5410c84 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.1.normal.js @@ -29,9 +29,9 @@ const f3 = function() { // @filename: F4.ts const f4 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function f4() { return _ref.apply(this, arguments); @@ -40,9 +40,9 @@ const f4 = function() { // @filename: F5.ts const f5 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function f5() { return _ref.apply(this, arguments); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.2.minified.js index 473ccb19fdd..41e79e2ce7d 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es2015.2.minified.js @@ -4,13 +4,13 @@ swcHelpers.wrapAsyncGenerator(function*() {}), swcHelpers.wrapAsyncGenerator(fun }), swcHelpers.wrapAsyncGenerator(function*() { yield 1; }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield swcHelpers.awaitAsyncGenerator(1); }), swcHelpers.wrapAsyncGenerator(function*() { diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.1.normal.js index f85648af3a8..1f16f0ad808 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.1.normal.js @@ -66,9 +66,9 @@ var f4 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -88,7 +88,7 @@ var f5 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -99,7 +99,7 @@ var f5 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.2.minified.js index b29a883239d..a6cd96699ad 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015_es5.2.minified.js @@ -40,9 +40,9 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -55,7 +55,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -65,7 +65,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.1.normal.js index c9e2e2924eb..0c481b9f460 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.1.normal.js @@ -29,9 +29,9 @@ const f3 = function() { // @filename: F4.ts const f4 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function f4() { return _ref.apply(this, arguments); @@ -40,9 +40,9 @@ const f4 = function() { // @filename: F5.ts const f5 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function f5() { return _ref.apply(this, arguments); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.2.minified.js index 473ccb19fdd..41e79e2ce7d 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es2015.2.minified.js @@ -4,13 +4,13 @@ swcHelpers.wrapAsyncGenerator(function*() {}), swcHelpers.wrapAsyncGenerator(fun }), swcHelpers.wrapAsyncGenerator(function*() { yield 1; }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield swcHelpers.awaitAsyncGenerator(1); }), swcHelpers.wrapAsyncGenerator(function*() { diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.1.normal.js index 8f5dafe982d..0e54f0c1bca 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.1.normal.js @@ -66,9 +66,9 @@ var f4 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -88,7 +88,7 @@ var f5 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -99,7 +99,7 @@ var f5 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.2.minified.js index b29a883239d..a6cd96699ad 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2018_es5.2.minified.js @@ -40,9 +40,9 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -55,7 +55,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -65,7 +65,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.1.normal.js index 25b8b61c614..5948fdcff15 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.1.normal.js @@ -29,9 +29,9 @@ const f3 = function() { // @filename: F4.ts const f4 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function f4() { return _ref.apply(this, arguments); @@ -40,9 +40,9 @@ const f4 = function() { // @filename: F5.ts const f5 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function f5() { return _ref.apply(this, arguments); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.2.minified.js index 473ccb19fdd..41e79e2ce7d 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es2015.2.minified.js @@ -4,13 +4,13 @@ swcHelpers.wrapAsyncGenerator(function*() {}), swcHelpers.wrapAsyncGenerator(fun }), swcHelpers.wrapAsyncGenerator(function*() { yield 1; }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield swcHelpers.awaitAsyncGenerator(1); }), swcHelpers.wrapAsyncGenerator(function*() { diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.1.normal.js index 579d5879f6a..41bbeef992b 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.1.normal.js @@ -66,9 +66,9 @@ var f4 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -88,7 +88,7 @@ var f5 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -99,7 +99,7 @@ var f5 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.2.minified.js index b29a883239d..a6cd96699ad 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5_es5.2.minified.js @@ -40,9 +40,9 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -55,7 +55,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -65,7 +65,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es2015.1.normal.js index 7d5e5718f9d..375275fb009 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es2015.1.normal.js @@ -27,9 +27,9 @@ const o3 = { const o4 = { f () { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); })(); } }; @@ -37,9 +37,9 @@ const o4 = { const o5 = { f () { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); })(); } }; diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es5.1.normal.js index 7437db04bfa..a24d44d3aea 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2015_es5.1.normal.js @@ -64,9 +64,9 @@ var o4 = { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -85,7 +85,7 @@ var o5 = { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -96,7 +96,7 @@ var o5 = { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es2015.1.normal.js index f959b58ff44..2368f42e643 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es2015.1.normal.js @@ -27,9 +27,9 @@ const o3 = { const o4 = { f () { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); })(); } }; @@ -37,9 +37,9 @@ const o4 = { const o5 = { f () { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); })(); } }; diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es5.1.normal.js index 48b051c8012..67e5b2a34a7 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es2018_es5.1.normal.js @@ -64,9 +64,9 @@ var o4 = { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -85,7 +85,7 @@ var o5 = { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -96,7 +96,7 @@ var o5 = { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es2015.1.normal.js index 3a45e5a1999..b335e6b15c9 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es2015.1.normal.js @@ -27,9 +27,9 @@ const o3 = { const o4 = { f () { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* [ + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ]; + ]), swcHelpers.awaitAsyncGenerator); })(); } }; @@ -37,9 +37,9 @@ const o4 = { const o5 = { f () { return swcHelpers.wrapAsyncGenerator(function*() { - const x = yield* swcHelpers.wrapAsyncGenerator(function*() { + const x = yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); })(); } }; diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es5.1.normal.js index ee8f75342e1..d8b0a9ba2fe 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.objectLiteralMethods.es5_es5.1.normal.js @@ -64,9 +64,9 @@ var o4 = { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx.t0; case 2: @@ -85,7 +85,7 @@ var o5 = { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -96,7 +96,7 @@ var o5 = { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: x = _ctx1.t0; case 2: diff --git a/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js b/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js index 90f3b85e77f..728294bc594 100644 --- a/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/generatorAssignability_es2015.1.normal.js @@ -134,11 +134,11 @@ function f2() { function _f2() { _f2 = swcHelpers.wrapAsyncGenerator(function*() { // yield* over iterable - yield* g1; // error - yield* g3; // ok + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g1), swcHelpers.awaitAsyncGenerator); // error + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g3), swcHelpers.awaitAsyncGenerator); // ok // yield* over asynciterable - yield* g4; // error - yield* g6; // ok + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g4), swcHelpers.awaitAsyncGenerator); // error + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g6), swcHelpers.awaitAsyncGenerator); // ok }); return _f2.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js b/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js index f468883571b..e6c5d77a9f7 100644 --- a/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/generatorAssignability_es5.1.normal.js @@ -345,14 +345,14 @@ function _f2() { while(1)switch(_ctx.prev = _ctx.next){ case 0: // yield* over iterable - return _ctx.delegateYield(g1, "t0", 1); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g1), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: - return _ctx.delegateYield(g3, "t1", 2); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g3), swcHelpers.awaitAsyncGenerator), "t1", 2); case 2: // yield* over asynciterable - return _ctx.delegateYield(g4, "t2", 3); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g4), swcHelpers.awaitAsyncGenerator), "t2", 3); case 3: - return _ctx.delegateYield(g6, "t3", 4); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(g6), swcHelpers.awaitAsyncGenerator), "t3", 4); case 4: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.1.normal.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.1.normal.js index b23471a2ff1..37eafdcedf0 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.1.normal.js @@ -51,10 +51,10 @@ function inferReturnType6() { } function _inferReturnType6() { _inferReturnType6 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _inferReturnType6.apply(this, arguments); } @@ -63,9 +63,9 @@ function inferReturnType7() { } function _inferReturnType7() { _inferReturnType7 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _inferReturnType7.apply(this, arguments); } @@ -74,9 +74,9 @@ function inferReturnType8() { } function _inferReturnType8() { _inferReturnType8 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _inferReturnType8.apply(this, arguments); } @@ -98,10 +98,10 @@ const assignability2 = function() { }(); const assignability3 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability3() { return _ref.apply(this, arguments); @@ -109,9 +109,9 @@ const assignability3 = function() { }(); const assignability4 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability4() { return _ref.apply(this, arguments); @@ -119,9 +119,9 @@ const assignability4 = function() { }(); const assignability5 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function assignability5() { return _ref.apply(this, arguments); @@ -145,10 +145,10 @@ const assignability7 = function() { }(); const assignability8 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability8() { return _ref.apply(this, arguments); @@ -156,9 +156,9 @@ const assignability8 = function() { }(); const assignability9 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability9() { return _ref.apply(this, arguments); @@ -166,9 +166,9 @@ const assignability9 = function() { }(); const assignability10 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function assignability10() { return _ref.apply(this, arguments); @@ -192,10 +192,10 @@ const assignability12 = function() { }(); const assignability13 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability13() { return _ref.apply(this, arguments); @@ -203,9 +203,9 @@ const assignability13 = function() { }(); const assignability14 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability14() { return _ref.apply(this, arguments); @@ -213,9 +213,9 @@ const assignability14 = function() { }(); const assignability15 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function assignability15() { return _ref.apply(this, arguments); @@ -244,10 +244,10 @@ function explicitReturnType3() { } function _explicitReturnType3() { _explicitReturnType3 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType3.apply(this, arguments); } @@ -256,9 +256,9 @@ function explicitReturnType4() { } function _explicitReturnType4() { _explicitReturnType4 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType4.apply(this, arguments); } @@ -267,9 +267,9 @@ function explicitReturnType5() { } function _explicitReturnType5() { _explicitReturnType5 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType5.apply(this, arguments); } @@ -296,10 +296,10 @@ function explicitReturnType8() { } function _explicitReturnType8() { _explicitReturnType8 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType8.apply(this, arguments); } @@ -308,9 +308,9 @@ function explicitReturnType9() { } function _explicitReturnType9() { _explicitReturnType9 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType9.apply(this, arguments); } @@ -319,9 +319,9 @@ function explicitReturnType10() { } function _explicitReturnType10() { _explicitReturnType10 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType10.apply(this, arguments); } @@ -348,10 +348,10 @@ function explicitReturnType13() { } function _explicitReturnType13() { _explicitReturnType13 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType13.apply(this, arguments); } @@ -360,9 +360,9 @@ function explicitReturnType14() { } function _explicitReturnType14() { _explicitReturnType14 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType14.apply(this, arguments); } @@ -371,9 +371,9 @@ function explicitReturnType15() { } function _explicitReturnType15() { _explicitReturnType15 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType15.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.2.minified.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.2.minified.js index 4e98a80c845..0ef61f23b6b 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es2015.2.minified.js @@ -4,50 +4,50 @@ swcHelpers.wrapAsyncGenerator(function*() { }), swcHelpers.wrapAsyncGenerator(function*() { yield Promise.resolve(1); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield 1; }), swcHelpers.wrapAsyncGenerator(function*() { yield Promise.resolve(1); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield 1; }), swcHelpers.wrapAsyncGenerator(function*() { yield Promise.resolve(1); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield 1; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.1.normal.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.1.normal.js index 83f5ec9db6f..bb907ccc0c8 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.1.normal.js @@ -101,10 +101,10 @@ function _inferReturnType6() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -121,9 +121,9 @@ function _inferReturnType7() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -140,7 +140,7 @@ function _inferReturnType8() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -151,7 +151,7 @@ function _inferReturnType8() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx1.stop(); @@ -199,10 +199,10 @@ var assignability3 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -218,9 +218,9 @@ var assignability4 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -236,7 +236,7 @@ var assignability5 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx2) { while(1)switch(_ctx2.prev = _ctx2.next){ case 0: - return _ctx2.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx2.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -247,7 +247,7 @@ var assignability5 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx2.stop(); @@ -297,10 +297,10 @@ var assignability8 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -316,9 +316,9 @@ var assignability9 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -334,7 +334,7 @@ var assignability10 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx3) { while(1)switch(_ctx3.prev = _ctx3.next){ case 0: - return _ctx3.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx3.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -345,7 +345,7 @@ var assignability10 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx3.stop(); @@ -395,10 +395,10 @@ var assignability13 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -414,9 +414,9 @@ var assignability14 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -432,7 +432,7 @@ var assignability15 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx4) { while(1)switch(_ctx4.prev = _ctx4.next){ case 0: - return _ctx4.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx4.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -443,7 +443,7 @@ var assignability15 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx4.stop(); @@ -498,10 +498,10 @@ function _explicitReturnType3() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -518,9 +518,9 @@ function _explicitReturnType4() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -537,7 +537,7 @@ function _explicitReturnType5() { return regeneratorRuntime.wrap(function _callee$(_ctx5) { while(1)switch(_ctx5.prev = _ctx5.next){ case 0: - return _ctx5.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx5.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -548,7 +548,7 @@ function _explicitReturnType5() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx5.stop(); @@ -601,10 +601,10 @@ function _explicitReturnType8() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -621,9 +621,9 @@ function _explicitReturnType9() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -640,7 +640,7 @@ function _explicitReturnType10() { return regeneratorRuntime.wrap(function _callee$(_ctx6) { while(1)switch(_ctx6.prev = _ctx6.next){ case 0: - return _ctx6.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx6.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -651,7 +651,7 @@ function _explicitReturnType10() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx6.stop(); @@ -704,10 +704,10 @@ function _explicitReturnType13() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -724,9 +724,9 @@ function _explicitReturnType14() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -743,7 +743,7 @@ function _explicitReturnType15() { return regeneratorRuntime.wrap(function _callee$(_ctx7) { while(1)switch(_ctx7.prev = _ctx7.next){ case 0: - return _ctx7.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx7.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -754,7 +754,7 @@ function _explicitReturnType15() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx7.stop(); diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.2.minified.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.2.minified.js index 1c57f91e8d3..2543e68106f 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.1_es5.2.minified.js @@ -24,10 +24,10 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -37,9 +37,9 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -49,7 +49,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -59,7 +59,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx1.stop(); @@ -89,10 +89,10 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -102,9 +102,9 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -114,7 +114,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx2) { for(;;)switch(_ctx2.prev = _ctx2.next){ case 0: - return _ctx2.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx2.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -124,7 +124,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx2.stop(); @@ -154,10 +154,10 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ 1, 2 - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -167,9 +167,9 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ Promise.resolve(1) - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -179,7 +179,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx3) { for(;;)switch(_ctx3.prev = _ctx3.next){ case 0: - return _ctx3.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx3.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -189,7 +189,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx3.stop(); diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.1.normal.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.1.normal.js index 6cc0f39cebd..50b12769c34 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.1.normal.js @@ -7,7 +7,7 @@ function _inferReturnType1() { // @lib: esnext // @noEmit: true swcHelpers.wrapAsyncGenerator(function*() { - yield* {}; + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator({}), swcHelpers.awaitAsyncGenerator); }); return _inferReturnType1.apply(this, arguments); } @@ -16,7 +16,7 @@ function inferReturnType2() { } function _inferReturnType2() { _inferReturnType2 = swcHelpers.wrapAsyncGenerator(function*() { - yield* inferReturnType2(); + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(inferReturnType2()), swcHelpers.awaitAsyncGenerator); }); return _inferReturnType2.apply(this, arguments); } @@ -25,10 +25,10 @@ function inferReturnType3() { } function _inferReturnType3() { _inferReturnType3 = swcHelpers.wrapAsyncGenerator(function*() { - yield* Promise.resolve([ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(Promise.resolve([ 1, 2 - ]); + ])), swcHelpers.awaitAsyncGenerator); }); return _inferReturnType3.apply(this, arguments); } @@ -42,10 +42,10 @@ const assignability1 = function() { }(); const assignability2 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability2() { return _ref.apply(this, arguments); @@ -53,9 +53,9 @@ const assignability2 = function() { }(); const assignability3 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function assignability3() { return _ref.apply(this, arguments); @@ -71,10 +71,10 @@ const assignability4 = function() { }(); const assignability5 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability5() { return _ref.apply(this, arguments); @@ -82,9 +82,9 @@ const assignability5 = function() { }(); const assignability6 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function assignability6() { return _ref.apply(this, arguments); @@ -100,10 +100,10 @@ const assignability7 = function() { }(); const assignability8 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return function assignability8() { return _ref.apply(this, arguments); @@ -111,9 +111,9 @@ const assignability8 = function() { }(); const assignability9 = function() { var _ref = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return function assignability9() { return _ref.apply(this, arguments); @@ -133,10 +133,10 @@ function explicitReturnType2() { } function _explicitReturnType2() { _explicitReturnType2 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType2.apply(this, arguments); } @@ -145,9 +145,9 @@ function explicitReturnType3() { } function _explicitReturnType3() { _explicitReturnType3 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType3.apply(this, arguments); } @@ -165,10 +165,10 @@ function explicitReturnType5() { } function _explicitReturnType5() { _explicitReturnType5 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType5.apply(this, arguments); } @@ -177,9 +177,9 @@ function explicitReturnType6() { } function _explicitReturnType6() { _explicitReturnType6 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType6.apply(this, arguments); } @@ -197,10 +197,10 @@ function explicitReturnType8() { } function _explicitReturnType8() { _explicitReturnType8 = swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType8.apply(this, arguments); } @@ -209,9 +209,9 @@ function explicitReturnType9() { } function _explicitReturnType9() { _explicitReturnType9 = swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); return _explicitReturnType9.apply(this, arguments); } @@ -247,7 +247,7 @@ function yieldStar() { } function _yieldStar() { _yieldStar = swcHelpers.wrapAsyncGenerator(function*() { - yield* {}; + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator({}), swcHelpers.awaitAsyncGenerator); }); return _yieldStar.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.2.minified.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.2.minified.js index b5fac271a4a..09a1a759b09 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es2015.2.minified.js @@ -1,42 +1,42 @@ import * as swcHelpers from "@swc/helpers"; function _inferReturnType2() { return (_inferReturnType2 = swcHelpers.wrapAsyncGenerator(function*() { - yield* function() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(function() { return _inferReturnType2.apply(this, arguments); - }(); + }()), swcHelpers.awaitAsyncGenerator); })).apply(this, arguments); } swcHelpers.wrapAsyncGenerator(function*() { yield "a"; }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield "a"; }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { yield "a"; }), swcHelpers.wrapAsyncGenerator(function*() { - yield* [ + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ]; + ]), swcHelpers.awaitAsyncGenerator); }), swcHelpers.wrapAsyncGenerator(function*() { - yield* swcHelpers.wrapAsyncGenerator(function*() { + yield* swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(function*() { yield "a"; - })(); + })()), swcHelpers.awaitAsyncGenerator); }); diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.1.normal.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.1.normal.js index 019cb25b82d..51a18ddc3fd 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.1.normal.js @@ -11,7 +11,7 @@ function _inferReturnType1() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield({}, "t0", 1); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator({}), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -28,7 +28,7 @@ function _inferReturnType2() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield(inferReturnType2(), "t0", 1); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(inferReturnType2()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -45,10 +45,10 @@ function _inferReturnType3() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield(Promise.resolve([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(Promise.resolve([ 1, 2 - ]), "t0", 1); + ])), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -79,10 +79,10 @@ var assignability2 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -98,7 +98,7 @@ var assignability3 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx1) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -109,7 +109,7 @@ var assignability3 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx1.stop(); @@ -142,10 +142,10 @@ var assignability5 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -161,7 +161,7 @@ var assignability6 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx2) { while(1)switch(_ctx2.prev = _ctx2.next){ case 0: - return _ctx2.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx2.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -172,7 +172,7 @@ var assignability6 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx2.stop(); @@ -205,10 +205,10 @@ var assignability8 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -224,7 +224,7 @@ var assignability9 = function() { return regeneratorRuntime.wrap(function _callee$(_ctx3) { while(1)switch(_ctx3.prev = _ctx3.next){ case 0: - return _ctx3.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx3.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -235,7 +235,7 @@ var assignability9 = function() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx3.stop(); @@ -272,10 +272,10 @@ function _explicitReturnType2() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -292,7 +292,7 @@ function _explicitReturnType3() { return regeneratorRuntime.wrap(function _callee$(_ctx4) { while(1)switch(_ctx4.prev = _ctx4.next){ case 0: - return _ctx4.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx4.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -303,7 +303,7 @@ function _explicitReturnType3() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx4.stop(); @@ -338,10 +338,10 @@ function _explicitReturnType5() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -358,7 +358,7 @@ function _explicitReturnType6() { return regeneratorRuntime.wrap(function _callee$(_ctx5) { while(1)switch(_ctx5.prev = _ctx5.next){ case 0: - return _ctx5.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx5.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -369,7 +369,7 @@ function _explicitReturnType6() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx5.stop(); @@ -404,10 +404,10 @@ function _explicitReturnType8() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -424,7 +424,7 @@ function _explicitReturnType9() { return regeneratorRuntime.wrap(function _callee$(_ctx6) { while(1)switch(_ctx6.prev = _ctx6.next){ case 0: - return _ctx6.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx6.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: @@ -435,7 +435,7 @@ function _explicitReturnType9() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx6.stop(); @@ -506,7 +506,7 @@ function _yieldStar() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield({}, "t0", 1); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator({}), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.2.minified.js b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.2.minified.js index 74818125255..76d1aba5e80 100644 --- a/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/types.asyncGenerators.es2018.2_es5.2.minified.js @@ -8,7 +8,7 @@ function _inferReturnType2() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield(inferReturnType2(), "t0", 1); + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(inferReturnType2()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -30,10 +30,10 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -43,7 +43,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - return _ctx1.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx1.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -53,7 +53,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx1.stop(); @@ -73,10 +73,10 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -86,7 +86,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx2) { for(;;)switch(_ctx2.prev = _ctx2.next){ case 0: - return _ctx2.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx2.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -96,7 +96,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx2.stop(); @@ -116,10 +116,10 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.delegateYield([ + return _ctx.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator([ "a", "b" - ], "t0", 1); + ]), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx.stop(); @@ -129,7 +129,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx3) { for(;;)switch(_ctx3.prev = _ctx3.next){ case 0: - return _ctx3.delegateYield(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { + return _ctx3.delegateYield(swcHelpers.asyncGeneratorDelegate(swcHelpers.asyncIterator(swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: @@ -139,7 +139,7 @@ swcHelpers.wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return _ctx.stop(); } }, _callee); - }))(), "t0", 1); + }))()), swcHelpers.awaitAsyncGenerator), "t0", 1); case 1: case "end": return _ctx3.stop(); diff --git a/crates/swc_ecma_minifier/src/pass/mangle_names/real_impl.rs b/crates/swc_ecma_minifier/src/pass/mangle_names/real_impl.rs index a4c3c116453..63071de3f48 100644 --- a/crates/swc_ecma_minifier/src/pass/mangle_names/real_impl.rs +++ b/crates/swc_ecma_minifier/src/pass/mangle_names/real_impl.rs @@ -7,9 +7,10 @@ use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, visit_obj_and_computed, Visit, VisitMut, VisitMutWith, VisitWith, }; +use tracing::info; use super::{analyzer::Analyzer, preserver::idents_to_preserve}; -use crate::{marks::Marks, option::MangleOptions}; +use crate::{debug::dump, marks::Marks, option::MangleOptions}; pub(crate) fn name_mangler(options: MangleOptions, _marks: Marks) -> impl VisitMut { Mangler { @@ -88,14 +89,21 @@ impl VisitMut for Mangler { fn visit_mut_module(&mut self, m: &mut Module) { self.preserved = idents_to_preserve(self.options.clone(), &*m); - if self.contains_eval(m) { - m.visit_mut_children_with(self); - return; + if option_env!("DEBUG_MANGLER") == Some("1") { + info!("Before: {}", dump(&*m, true)); } - let map = self.get_map(m); + if self.contains_eval(m) { + m.visit_mut_children_with(self); + } else { + let map = self.get_map(m); - m.visit_mut_with(&mut rename(&map)); + m.visit_mut_with(&mut rename(&map)); + } + + if option_env!("DEBUG_MANGLER") == Some("1") { + info!("After: {}", dump(&*m, true)); + } } fn visit_mut_script(&mut self, s: &mut Script) { diff --git a/crates/swc_ecma_minifier/tests/full/helpers/1/input.js b/crates/swc_ecma_minifier/tests/full/helpers/1/input.js new file mode 100644 index 00000000000..40d98309cf3 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/full/helpers/1/input.js @@ -0,0 +1,17 @@ +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} + +export default asyncGeneratorStep \ No newline at end of file diff --git a/crates/swc_ecma_minifier/tests/full/helpers/1/output.js b/crates/swc_ecma_minifier/tests/full/helpers/1/output.js new file mode 100644 index 00000000000..6bb321703a4 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/full/helpers/1/output.js @@ -0,0 +1 @@ +export default function(c,d,e,f,g,h,i){try{var a=c[h](i),b=a.value}catch(j){e(j);return}a.done?d(b):Promise.resolve(b).then(f,g)} diff --git a/crates/swc_ecma_transforms_base/Cargo.toml b/crates/swc_ecma_transforms_base/Cargo.toml index f8b4c77cc3d..dd8a6b67fb0 100644 --- a/crates/swc_ecma_transforms_base/Cargo.toml +++ b/crates/swc_ecma_transforms_base/Cargo.toml @@ -16,25 +16,26 @@ bench = false concurrent = ["rayon", "swc_ecma_utils/concurrent"] [dependencies] -better_scoped_tls = {version = "0.1.0", path = "../better_scoped_tls"} +better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" } once_cell = "1.10.0" -phf = {version = "0.10", features = ["macros"]} -rayon = {version = "1", optional = true} -serde = {version = "1", features = ["derive"]} +phf = { version = "0.10", features = ["macros"] } +rayon = { version = "1", optional = true } +rustc-hash = "1.1.0" +serde = { version = "1", features = ["derive"] } smallvec = "1.8.0" -swc_atoms = {version = "0.2", path = "../swc_atoms"} -swc_common = { version = "0.17.23", path = "../swc_common"} -swc_ecma_ast = {version = "0.76.0", path = "../swc_ecma_ast"} -swc_ecma_parser = {version = "0.102.0", path = "../swc_ecma_parser"} -swc_ecma_utils = {version = "0.82.0", path = "../swc_ecma_utils"} -swc_ecma_visit = {version = "0.62.0", path = "../swc_ecma_visit"} +swc_atoms = { version = "0.2", path = "../swc_atoms" } +swc_common = { version = "0.17.23", path = "../swc_common" } +swc_ecma_ast = { version = "0.76.0", path = "../swc_ecma_ast" } +swc_ecma_parser = { version = "0.102.0", path = "../swc_ecma_parser" } +swc_ecma_utils = { version = "0.82.0", path = "../swc_ecma_utils" } +swc_ecma_visit = { version = "0.62.0", path = "../swc_ecma_visit" } tracing = "0.1.32" [dev-dependencies] criterion = "0.3" -swc_ecma_codegen = {version = "0.105.0", path = "../swc_ecma_codegen"} -swc_ecma_transforms_macros = {version = "0.3.0", path = "../swc_ecma_transforms_macros"} -testing = {version = "0.19.0", path = "../testing"} +swc_ecma_codegen = { version = "0.105.0", path = "../swc_ecma_codegen" } +swc_ecma_transforms_macros = { version = "0.3.0", path = "../swc_ecma_transforms_macros" } +testing = { version = "0.19.0", path = "../testing" } [[bench]] harness = false diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index c0353bbeb0d..2a00a07eba7 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -1,7 +1,12 @@ -use std::sync::atomic::{AtomicBool, Ordering}; +use std::{ + mem::replace, + sync::atomic::{AtomicBool, Ordering}, +}; use once_cell::sync::Lazy; -use swc_common::{FileName, FilePathMapping, Mark, SourceMap, DUMMY_SP}; +use rustc_hash::FxHashMap; +use swc_atoms::JsWord; +use swc_common::{FileName, FilePathMapping, Mark, SourceMap, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmts, quote_ident, quote_str, DropSpan}; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; @@ -16,37 +21,46 @@ macro_rules! enable_helper { }}; } +fn parse(code: &str) -> Vec { + let cm = SourceMap::new(FilePathMapping::empty()); + + let fm = cm.new_source_file(FileName::Custom(stringify!($name).into()), code.into()); + + swc_ecma_parser::parse_file_as_script( + &fm, + Default::default(), + Default::default(), + None, + &mut vec![], + ) + .map(|mut script| { + script.body.visit_mut_with(&mut DropSpan { + preserve_ctxt: false, + }); + script.body + }) + .map_err(|e| { + unreachable!("Error occurred while parsing error: {:?}", e); + }) + .unwrap() +} + macro_rules! add_to { ($buf:expr, $name:ident, $b:expr, $mark:expr) => {{ static STMTS: Lazy> = Lazy::new(|| { - let cm = SourceMap::new(FilePathMapping::empty()); let code = include_str!(concat!("./_", stringify!($name), ".js")); - let fm = cm.new_source_file(FileName::Custom(stringify!($name).into()), code.into()); - - let stmts = swc_ecma_parser::parse_file_as_script( - &fm, - Default::default(), - Default::default(), - None, - &mut vec![], - ) - .map(|mut script| { - script.body.visit_mut_with(&mut DropSpan { - preserve_ctxt: false, - }); - script.body - }) - .map_err(|e| { - unreachable!("Error occurred while parsing error: {:?}", e); - }) - .unwrap(); - stmts + parse(&code) }); let enable = $b.load(Ordering::Relaxed); if enable { $buf.extend(STMTS.iter().cloned().map(|mut stmt| { - stmt.visit_mut_with(&mut Marker($mark)); + stmt.visit_mut_with(&mut Marker { + base: SyntaxContext::empty().apply_mark($mark), + decls: Default::default(), + + decl_ctxt: SyntaxContext::empty().apply_mark(Mark::new()), + }); stmt })) } @@ -352,13 +366,44 @@ impl VisitMut for InjectHelpers { } } -struct Marker(Mark); +struct Marker { + base: SyntaxContext, + decls: FxHashMap, + + decl_ctxt: SyntaxContext, +} impl VisitMut for Marker { noop_visit_mut_type!(); + fn visit_mut_fn_decl(&mut self, n: &mut FnDecl) { + let old_decl_ctxt = replace( + &mut self.decl_ctxt, + SyntaxContext::empty().apply_mark(Mark::new()), + ); + let old_decls = self.decls.clone(); + + n.visit_mut_children_with(self); + + self.decls = old_decls; + self.decl_ctxt = old_decl_ctxt; + } + + fn visit_mut_fn_expr(&mut self, n: &mut FnExpr) { + let old_decl_ctxt = replace( + &mut self.decl_ctxt, + SyntaxContext::empty().apply_mark(Mark::new()), + ); + let old_decls = self.decls.clone(); + + n.visit_mut_children_with(self); + + self.decls = old_decls; + self.decl_ctxt = old_decl_ctxt; + } + fn visit_mut_ident(&mut self, i: &mut Ident) { - i.span = i.span.apply_mark(self.0); + i.span.ctxt = self.decls.get(&i.sym).copied().unwrap_or(self.base); } fn visit_mut_member_prop(&mut self, p: &mut MemberProp) { @@ -367,11 +412,35 @@ impl VisitMut for Marker { } } + fn visit_mut_param(&mut self, n: &mut Param) { + if let Pat::Ident(i) = &n.pat { + self.decls.insert(i.id.sym.clone(), self.decl_ctxt); + } + + n.visit_mut_children_with(self); + } + + fn visit_mut_prop_name(&mut self, n: &mut PropName) { + if let PropName::Computed(e) = n { + e.visit_mut_with(self); + } + } + fn visit_mut_super_prop(&mut self, p: &mut SuperProp) { if let SuperProp::Computed(p) = p { p.visit_mut_with(self); } } + + fn visit_mut_var_declarator(&mut self, v: &mut VarDeclarator) { + if let Pat::Ident(i) = &v.name { + if &*i.id.sym != "_typeof" { + self.decls.insert(i.id.sym.clone(), self.decl_ctxt); + } + } + + v.visit_mut_children_with(self); + } } #[cfg(test)] diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index 9db920134e0..71f22b915c0 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -3,7 +3,7 @@ use std::iter; use serde::Deserialize; use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_transforms_base::{helper, perf::Check}; +use swc_ecma_transforms_base::{helper, helper_expr, perf::Check}; use swc_ecma_transforms_macros::fast_path; use swc_ecma_utils::{ contains_this_expr, @@ -405,27 +405,58 @@ impl VisitMut for AsyncFnBodyHandler { fn visit_mut_expr(&mut self, expr: &mut Expr) { expr.visit_mut_children_with(self); - if let Expr::Await(AwaitExpr { span, arg }) = expr { - if self.is_async_generator { - let callee = helper!(await_async_generator, "awaitAsyncGenerator"); + match expr { + Expr::Yield(YieldExpr { + span, + arg: Some(arg), + delegate: true, + }) => { + let callee = helper!(async_generator_delegate, "asyncGeneratorDelegate"); let arg = Box::new(Expr::Call(CallExpr { span: *span, callee, - args: vec![arg.take().as_arg()], + args: vec![ + CallExpr { + span: DUMMY_SP, + callee: helper!(async_iterator, "asyncIterator"), + args: vec![arg.take().as_arg()], + type_args: Default::default(), + } + .as_arg(), + helper_expr!(await_async_generator, "awaitAsyncGenerator").as_arg(), + ], type_args: Default::default(), })); *expr = Expr::Yield(YieldExpr { span: *span, - delegate: false, + delegate: true, arg: Some(arg), }) - } else { - *expr = Expr::Yield(YieldExpr { - span: *span, - delegate: false, - arg: Some(arg.take()), - }) } + + Expr::Await(AwaitExpr { span, arg }) => { + if self.is_async_generator { + let callee = helper!(await_async_generator, "awaitAsyncGenerator"); + let arg = Box::new(Expr::Call(CallExpr { + span: *span, + callee, + args: vec![arg.take().as_arg()], + type_args: Default::default(), + })); + *expr = Expr::Yield(YieldExpr { + span: *span, + delegate: false, + arg: Some(arg), + }) + } else { + *expr = Expr::Yield(YieldExpr { + span: *span, + delegate: false, + arg: Some(arg.take()), + }) + } + } + _ => {} } } diff --git a/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-4405/exec.js b/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-4405/exec.js new file mode 100644 index 00000000000..24f8fd99989 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-4405/exec.js @@ -0,0 +1,18 @@ +async function* asyncGenerator( +) { + for (let i = 5; i < 10; i++) { + yield new Promise((res) => setTimeout(() => res({ success: true }), 5)); + } + yield { success: true }; +} + +async function* execute( +) { + yield* asyncGenerator(); +} + +(async () => { + for await (const p of execute()) { + console.log(await p); + } +})(); \ No newline at end of file diff --git a/package.json b/package.json index f7e06e963f6..7eda455fe8a 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "@babel/preset-typescript": "^7.13.0", "@babel/types": "^7.14.0", "@napi-rs/cli": "^2.4.5", - "@swc/helpers": "^0.2.10", + "@swc/helpers": "^0.3.8", "@taplo/cli": "^0.3.2", "@types/jest": "^26.0.23", "@types/node": "^14.14.41", diff --git a/yarn.lock b/yarn.lock index b0362b25c9a..cdc9faf365e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1537,10 +1537,10 @@ resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.146.tgz#e9010b06fbfebdc745d2dd324b752ddd4f685bc9" integrity sha512-P45vAh0hR9dISIceSv6MkypjT0WduLWB4U8LPoCneeAw7mA1U7liS0Uu1PeiafxQVMWg8SNyIJFDcSg/haLJgg== -"@swc/helpers@^0.2.10": - version "0.2.12" - resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.2.12.tgz#cd54624dd685f7832b50dd7ce119ddc4eb2585ad" - integrity sha512-hsPGC/U/0xe/WghMeSgyFsq9nNPfA5oY1Il2AaeAJcu/vTm4Bv8o9ev4eAgxcA61i5WWp72amN20XVyxWwM5aQ== +"@swc/helpers@^0.3.8": + version "0.3.8" + resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.3.8.tgz#5b9ecf4ee480ca00f1ffbc2d1a5d4eed0d1afe81" + integrity sha512-aWItSZvJj4+GI6FWkjZR13xPNPctq2RRakzo+O6vN7bC2yjwdg5EFpgaSAUn95b7BGSgcflvzVDPoKmJv24IOg== "@taplo/cli@^0.3.2": version "0.3.2"