diff --git a/crates/jsdoc/tests/fixture.rs b/crates/jsdoc/tests/fixture.rs index 5118214a6c07..845f623c29c8 100644 --- a/crates/jsdoc/tests/fixture.rs +++ b/crates/jsdoc/tests/fixture.rs @@ -141,6 +141,8 @@ impl Comments for SwcComments { } fn add_pure_comment(&self, pos: BytePos) { + assert_ne!(pos, BytePos(0), "cannot add pure comment to zero position"); + let mut leading = self.leading.entry(pos).or_default(); let pure_comment = Comment { kind: CommentKind::Block, diff --git a/crates/swc/tests/exec/issues-8xxx/8155/.swcrc b/crates/swc/tests/exec/issues-8xxx/8155/.swcrc new file mode 100644 index 000000000000..b4c38b681349 --- /dev/null +++ b/crates/swc/tests/exec/issues-8xxx/8155/.swcrc @@ -0,0 +1,24 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true, + "tsx": false + }, + "transform": { + "legacyDecorator": true + }, + "target": "es5", + // "loose": false, + "minify": { + "compress": false, + "mangle": false + }, + "loose": false + }, + "module": { + "type": "es6" + }, + "minify": false, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/exec/issues-8xxx/8155/exec.js b/crates/swc/tests/exec/issues-8xxx/8155/exec.js new file mode 100644 index 000000000000..21c8f0516a68 --- /dev/null +++ b/crates/swc/tests/exec/issues-8xxx/8155/exec.js @@ -0,0 +1,16 @@ +const someFn = (xx, x, y) => [x, y]; + +const getArray = () => [1, 2, 3]; + +const goodFunction = async () => { + const rb = await getArray(); + const rc = await getArray(); + console.log(someFn(1, rb, rc)); +} + +const badFunction = async () => { + console.log(someFn(1, await getArray(), await getArray())) +} + +goodFunction(); +badFunction(); \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8155/1/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8155/1/input/.swcrc new file mode 100644 index 000000000000..35b9a14cc8db --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8155/1/input/.swcrc @@ -0,0 +1,19 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true, + "tsx": false + }, + "transform": { + "legacyDecorator": true + }, + "target": "es2016", + "minify": { + "compress": true + }, + "loose": false, + "externalHelpers": false + }, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8155/1/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8155/1/input/1.js new file mode 100644 index 000000000000..21c8f0516a68 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8155/1/input/1.js @@ -0,0 +1,16 @@ +const someFn = (xx, x, y) => [x, y]; + +const getArray = () => [1, 2, 3]; + +const goodFunction = async () => { + const rb = await getArray(); + const rc = await getArray(); + console.log(someFn(1, rb, rc)); +} + +const badFunction = async () => { + console.log(someFn(1, await getArray(), await getArray())) +} + +goodFunction(); +badFunction(); \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8155/1/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8155/1/output/1.js new file mode 100644 index 000000000000..e9098a2f7960 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8155/1/output/1.js @@ -0,0 +1,20 @@ +var _ref, _ref1; +import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; +let someFn = (xx, x, y)=>[ + x, + y + ], getArray = ()=>[ + 1, + 2, + 3 + ], goodFunction = (_ref = _async_to_generator(function*() { + let rb = yield getArray(), rc = yield getArray(); + console.log(someFn(1, rb, rc)); +}), function() { + return _ref.apply(this, arguments); +}), badFunction = (_ref1 = _async_to_generator(function*() { + console.log(someFn(1, (yield getArray()), (yield getArray()))); +}), function() { + return _ref1.apply(this, arguments); +}); +goodFunction(), badFunction(); diff --git a/crates/swc/tests/fixture/issues-8xxx/8155/2/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8155/2/input/.swcrc new file mode 100644 index 000000000000..e5fc4d3c02f8 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8155/2/input/.swcrc @@ -0,0 +1,16 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true, + "tsx": false + }, + "transform": { + "legacyDecorator": true + }, + "target": "es2016", + "loose": false, + "externalHelpers": false + }, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8155/2/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8155/2/input/1.js new file mode 100644 index 000000000000..21c8f0516a68 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8155/2/input/1.js @@ -0,0 +1,16 @@ +const someFn = (xx, x, y) => [x, y]; + +const getArray = () => [1, 2, 3]; + +const goodFunction = async () => { + const rb = await getArray(); + const rc = await getArray(); + console.log(someFn(1, rb, rc)); +} + +const badFunction = async () => { + console.log(someFn(1, await getArray(), await getArray())) +} + +goodFunction(); +badFunction(); \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8155/2/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8155/2/output/1.js new file mode 100644 index 000000000000..d9cd06f6d12d --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8155/2/output/1.js @@ -0,0 +1,30 @@ +import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; +const someFn = (xx, x, y)=>[ + x, + y + ]; +const getArray = ()=>[ + 1, + 2, + 3 + ]; +const goodFunction = function() { + var _ref = _async_to_generator(function*() { + const rb = yield getArray(); + const rc = yield getArray(); + console.log(someFn(1, rb, rc)); + }); + return function goodFunction() { + return _ref.apply(this, arguments); + }; +}(); +const badFunction = function() { + var _ref = _async_to_generator(function*() { + console.log(someFn(1, (yield getArray()), (yield getArray()))); + }); + return function badFunction() { + return _ref.apply(this, arguments); + }; +}(); +goodFunction(); +badFunction(); diff --git a/crates/swc/tests/tsc-references/asyncArrowFunction10_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncArrowFunction10_es5.2.minified.js index f40558828a07..cc7929ec445f 100644 --- a/crates/swc/tests/tsc-references/asyncArrowFunction10_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncArrowFunction10_es5.2.minified.js @@ -1,3 +1,10 @@ //// [asyncArrowFunction10_es5.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}); diff --git a/crates/swc/tests/tsc-references/asyncArrowFunction10_es6.2.minified.js b/crates/swc/tests/tsc-references/asyncArrowFunction10_es6.2.minified.js index c60b9d405bcb..256709ccfe44 100644 --- a/crates/swc/tests/tsc-references/asyncArrowFunction10_es6.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncArrowFunction10_es6.2.minified.js @@ -1,2 +1,3 @@ //// [asyncArrowFunction10_es6.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; +_async_to_generator(function*() {}); diff --git a/crates/swc/tests/tsc-references/asyncArrowFunction1_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncArrowFunction1_es5.2.minified.js index 3ef432144774..0814e8a21860 100644 --- a/crates/swc/tests/tsc-references/asyncArrowFunction1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncArrowFunction1_es5.2.minified.js @@ -1,3 +1,10 @@ //// [asyncArrowFunction1_es5.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}); diff --git a/crates/swc/tests/tsc-references/asyncArrowFunction1_es6.2.minified.js b/crates/swc/tests/tsc-references/asyncArrowFunction1_es6.2.minified.js index 2c95d5f4f725..663ebbb05d52 100644 --- a/crates/swc/tests/tsc-references/asyncArrowFunction1_es6.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncArrowFunction1_es6.2.minified.js @@ -1,2 +1,3 @@ //// [asyncArrowFunction1_es6.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; +_async_to_generator(function*() {}); diff --git a/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es5.2.minified.js index 9265d5ed5f76..efcffa015520 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es5.2.minified.js @@ -3,4 +3,81 @@ var M; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -M || (M = {}); +_async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + p + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + mp + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + mp + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + p + ]; + }); +}), function(M) { + function _f1() { + return (_f1 = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })).apply(this, arguments); + } + M.f1 = function() { + return _f1.apply(this, arguments); + }; +}(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es6.2.minified.js b/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es6.2.minified.js index 040848e36b1c..16c603790e70 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es6.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwaitIsolatedModules_es6.2.minified.js @@ -1,4 +1,19 @@ //// [asyncAwaitIsolatedModules_es6.ts] var M; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -M || (M = {}); +_async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() { + return p; +}), _async_to_generator(function*() { + return mp; +}), _async_to_generator(function*() { + return mp; +}), _async_to_generator(function*() { + return p; +}), function(M) { + function _f1() { + return (_f1 = _async_to_generator(function*() {})).apply(this, arguments); + } + M.f1 = function() { + return _f1.apply(this, arguments); + }; +}(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/asyncAwait_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncAwait_es5.2.minified.js index 341af5328c8e..329c20b0d5c8 100644 --- a/crates/swc/tests/tsc-references/asyncAwait_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwait_es5.2.minified.js @@ -3,4 +3,81 @@ var M; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; -M || (M = {}); +_async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + p + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + mp + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + mp + ]; + }); +}), _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + p + ]; + }); +}), function(M) { + function _f1() { + return (_f1 = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); + })).apply(this, arguments); + } + M.f1 = function() { + return _f1.apply(this, arguments); + }; +}(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/asyncAwait_es6.2.minified.js b/crates/swc/tests/tsc-references/asyncAwait_es6.2.minified.js index 4cbb09eba2b7..854a0c852f3f 100644 --- a/crates/swc/tests/tsc-references/asyncAwait_es6.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwait_es6.2.minified.js @@ -1,4 +1,19 @@ //// [asyncAwait_es6.ts] var M; import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; -M || (M = {}); +_async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() {}), _async_to_generator(function*() { + return p; +}), _async_to_generator(function*() { + return mp; +}), _async_to_generator(function*() { + return mp; +}), _async_to_generator(function*() { + return p; +}), function(M) { + function _f1() { + return (_f1 = _async_to_generator(function*() {})).apply(this, arguments); + } + M.f1 = function() { + return _f1.apply(this, arguments); + }; +}(M || (M = {})); diff --git a/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es5.2.minified.js index 3b752dc096d0..1f70e9a31150 100644 --- a/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es5.2.minified.js @@ -1,3 +1,34 @@ //// [asyncUnParenthesizedArrowFunction_es5.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_async_to_generator(function(i) { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + someOtherFunction(i) + ]; + case 1: + return [ + 2, + _state.sent() + ]; + } + }); +}), _async_to_generator(function(i) { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + someOtherFunction(i) + ]; + case 1: + return [ + 2, + _state.sent() + ]; + } + }); +}); diff --git a/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es6.2.minified.js b/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es6.2.minified.js index 895c164ec2ad..b4b4949af17d 100644 --- a/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es6.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncUnParenthesizedArrowFunction_es6.2.minified.js @@ -1,2 +1,7 @@ //// [asyncUnParenthesizedArrowFunction_es6.ts] import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator"; +_async_to_generator(function*(i) { + return yield someOtherFunction(i); +}), _async_to_generator(function*(i) { + return yield someOtherFunction(i); +}); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015.2.minified.js index 1a21697b4ffa..7e6cc9db62c5 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es2015.2.minified.js @@ -1,21 +1,44 @@ //// [F1.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() {}); //// [F2.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() { + yield; +}); //// [F3.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() { + yield 1; +}); //// [F4.ts] import { _ as _async_generator_delegate } from "@swc/helpers/_/_async_generator_delegate"; import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() { + yield* _async_generator_delegate(_async_iterator([ + 1 + ]), _await_async_generator); +}); //// [F5.ts] import { _ as _async_generator_delegate } from "@swc/helpers/_/_async_generator_delegate"; import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() { + yield* _async_generator_delegate(_async_iterator(_wrap_async_generator(function*() { + yield 1; + })()), _await_async_generator); +}); //// [F6.ts] import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() { + yield _await_async_generator(1); +}); //// [F7.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; +_wrap_async_generator(function*() { + return 1; +}); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5.2.minified.js index eee397aee848..f75ef963c22d 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.functionExpressions.es5.2.minified.js @@ -1,12 +1,48 @@ //// [F1.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2 + ]; + }); +}); //// [F2.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4 + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); +}); //// [F3.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + 1 + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); +}); //// [F4.ts] import { _ as _async_generator_delegate } from "@swc/helpers/_/_async_generator_delegate"; import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; @@ -14,6 +50,23 @@ import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generat import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; import { _ as _ts_values } from "@swc/helpers/_/_ts_values"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 5, + _ts_values(_async_generator_delegate(_async_iterator([ + 1 + ]), _await_async_generator)) + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); +}); //// [F5.ts] import { _ as _async_generator_delegate } from "@swc/helpers/_/_async_generator_delegate"; import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator"; @@ -21,10 +74,62 @@ import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generat import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; import { _ as _ts_values } from "@swc/helpers/_/_ts_values"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 5, + _ts_values(_async_generator_delegate(_async_iterator(_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + 1 + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })()), _await_async_generator)) + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); +}); //// [F6.ts] import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator"; import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _await_async_generator(1) + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); +}); //// [F7.ts] import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator"; import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator"; +_wrap_async_generator(function() { + return _ts_generator(this, function(_state) { + return [ + 2, + 1 + ]; + }); +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3AMD.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3AMD.2.minified.js index ba52310173b7..86ecb47de179 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3AMD.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3AMD.2.minified.js @@ -1 +1,156 @@ //// [test.ts] +define([ + "require", + "exports", + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_class_call_check", + "@swc/helpers/_/_interop_require_wildcard", + "@swc/helpers/_/_ts_generator" +], function(require, exports, _async_to_generator, _class_call_check, _interop_require_wildcard, _ts_generator) { + function fn() { + return _fn.apply(this, arguments); + } + function _fn() { + return (_fn = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); + } + Object.defineProperty(exports, "__esModule", { + value: !0 + }), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); + }(exports, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } + }); + var _ref, cl1 = function() { + function cl1() { + _class_call_check._(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; + }(), obj = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }, cl2 = function cl2() { + _class_call_check._(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; + }, l = (_ref = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // FIVE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }), function() { + return _ref.apply(this, arguments); + }); +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3CJS.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3CJS.2.minified.js index bbef36263215..9bbc1665c7e8 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3CJS.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3CJS.2.minified.js @@ -1,7 +1,113 @@ //// [test.ts] -exports, exports; -var _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _ts_generator = require("@swc/helpers/_/_ts_generator"); -_async_to_generator._(function() { +Object.defineProperty(exports, "__esModule", { + value: !0 +}), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); +}(exports, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } +}); +var _ref, _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _class_call_check = require("@swc/helpers/_/_class_call_check"), _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _ts_generator = require("@swc/helpers/_/_ts_generator"); +function fn() { + return _fn.apply(this, arguments); +} +function _fn() { + return (_fn = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); +} +var cl1 = function() { + function cl1() { + _class_call_check._(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; +}(), obj = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) +}, cl2 = function cl2() { + _class_call_check._(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; +}, l = (_ref = _async_to_generator._(function() { return _ts_generator._(this, function(_state) { switch(_state.label){ case 0: @@ -17,4 +123,6 @@ _async_to_generator._(function() { ]; } }); +}), function() { + return _ref.apply(this, arguments); }); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3System.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3System.2.minified.js index ba52310173b7..66c66454a205 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3System.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3System.2.minified.js @@ -1 +1,115 @@ //// [test.ts] +System.register([ + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_class_call_check", + "@swc/helpers/_/_ts_generator" +], function(_export, _context) { + var _async_to_generator, _class_call_check, _ts_generator; + function _fn() { + return (_fn = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); + } + return _export("fn", function() { + return _fn.apply(this, arguments); + }), { + setters: [ + function(_async_to_generator1) { + _async_to_generator = _async_to_generator1._; + }, + function(_class_call_check1) { + _class_call_check = _class_call_check1._; + }, + function(_ts_generator1) { + _ts_generator = _ts_generator1._; + } + ], + execute: function() { + var _ref; + _export("cl1", function() { + function cl1() { + _class_call_check(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; + }()), _export("obj", { + m: /*#__PURE__*/ _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }), _export("cl2", function cl2() { + _class_call_check(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; + }), _export("l", (_ref = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // FIVE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }), function() { + return _ref.apply(this, arguments); + })); + } + }; +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3UMD.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3UMD.2.minified.js index ba52310173b7..a8774dfd46e1 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES3UMD.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES3UMD.2.minified.js @@ -1 +1,126 @@ //// [test.ts] +var global, factory; +global = this, factory = function(exports1, _async_to_generator, _class_call_check, _interop_require_wildcard, _ts_generator) { + function fn() { + return _fn.apply(this, arguments); + } + function _fn() { + return (_fn = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); + } + Object.defineProperty(exports1, "__esModule", { + value: !0 + }), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); + }(exports1, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } + }); + var _ref, cl1 = function() { + function cl1() { + _class_call_check._(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; + }(), obj = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }, cl2 = function cl2() { + _class_call_check._(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; + }, l = (_ref = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // FIVE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }), function() { + return _ref.apply(this, arguments); + }); +}, "object" == typeof module && "object" == typeof module.exports ? factory(exports, require("@swc/helpers/_/_async_to_generator"), require("@swc/helpers/_/_class_call_check"), require("@swc/helpers/_/_interop_require_wildcard"), require("@swc/helpers/_/_ts_generator")) : "function" == typeof define && define.amd ? define([ + "exports", + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_class_call_check", + "@swc/helpers/_/_interop_require_wildcard", + "@swc/helpers/_/_ts_generator" +], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.testTs = {}, global.asyncToGenerator, global.classCallCheck, global.interopRequireWildcard, global.tsGenerator); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5AMD.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5AMD.2.minified.js index ba52310173b7..86ecb47de179 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5AMD.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5AMD.2.minified.js @@ -1 +1,156 @@ //// [test.ts] +define([ + "require", + "exports", + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_class_call_check", + "@swc/helpers/_/_interop_require_wildcard", + "@swc/helpers/_/_ts_generator" +], function(require, exports, _async_to_generator, _class_call_check, _interop_require_wildcard, _ts_generator) { + function fn() { + return _fn.apply(this, arguments); + } + function _fn() { + return (_fn = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); + } + Object.defineProperty(exports, "__esModule", { + value: !0 + }), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); + }(exports, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } + }); + var _ref, cl1 = function() { + function cl1() { + _class_call_check._(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; + }(), obj = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }, cl2 = function cl2() { + _class_call_check._(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; + }, l = (_ref = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + new Promise(function(resolve, reject) { + return require([ + "./test" + ], function(m) { + return resolve(/*#__PURE__*/ _interop_require_wildcard._(m)); + }, reject); + }) // FIVE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }), function() { + return _ref.apply(this, arguments); + }); +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5CJS.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5CJS.2.minified.js index bbef36263215..9bbc1665c7e8 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5CJS.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5CJS.2.minified.js @@ -1,7 +1,113 @@ //// [test.ts] -exports, exports; -var _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _ts_generator = require("@swc/helpers/_/_ts_generator"); -_async_to_generator._(function() { +Object.defineProperty(exports, "__esModule", { + value: !0 +}), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); +}(exports, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } +}); +var _ref, _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _class_call_check = require("@swc/helpers/_/_class_call_check"), _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _ts_generator = require("@swc/helpers/_/_ts_generator"); +function fn() { + return _fn.apply(this, arguments); +} +function _fn() { + return (_fn = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); +} +var cl1 = function() { + function cl1() { + _class_call_check._(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; +}(), obj = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) +}, cl2 = function cl2() { + _class_call_check._(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + Promise.resolve().then(function() { + return /*#__PURE__*/ _interop_require_wildcard._(require("./test")); + }) // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; +}, l = (_ref = _async_to_generator._(function() { return _ts_generator._(this, function(_state) { switch(_state.label){ case 0: @@ -17,4 +123,6 @@ _async_to_generator._(function() { ]; } }); +}), function() { + return _ref.apply(this, arguments); }); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5System.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5System.2.minified.js index ba52310173b7..66c66454a205 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5System.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5System.2.minified.js @@ -1 +1,115 @@ //// [test.ts] +System.register([ + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_class_call_check", + "@swc/helpers/_/_ts_generator" +], function(_export, _context) { + var _async_to_generator, _class_call_check, _ts_generator; + function _fn() { + return (_fn = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); + } + return _export("fn", function() { + return _fn.apply(this, arguments); + }), { + setters: [ + function(_async_to_generator1) { + _async_to_generator = _async_to_generator1._; + }, + function(_class_call_check1) { + _class_call_check = _class_call_check1._; + }, + function(_ts_generator1) { + _ts_generator = _ts_generator1._; + } + ], + execute: function() { + var _ref; + _export("cl1", function() { + function cl1() { + _class_call_check(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; + }()), _export("obj", { + m: /*#__PURE__*/ _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }), _export("cl2", function cl2() { + _class_call_check(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; + }), _export("l", (_ref = _async_to_generator(function() { + return _ts_generator(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + _context.import("./test") // FIVE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }), function() { + return _ref.apply(this, arguments); + })); + } + }; +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5UMD.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5UMD.2.minified.js index ba52310173b7..a8774dfd46e1 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES5UMD.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES5UMD.2.minified.js @@ -1 +1,126 @@ //// [test.ts] +var global, factory; +global = this, factory = function(exports1, _async_to_generator, _class_call_check, _interop_require_wildcard, _ts_generator) { + function fn() { + return _fn.apply(this, arguments); + } + function _fn() { + return (_fn = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // ONE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })).apply(this, arguments); + } + Object.defineProperty(exports1, "__esModule", { + value: !0 + }), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); + }(exports1, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } + }); + var _ref, cl1 = function() { + function cl1() { + _class_call_check._(this, cl1); + } + return cl1.prototype.m = function() { + return _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // TWO + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + })(); + }, cl1; + }(), obj = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // THREE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }, cl2 = function cl2() { + _class_call_check._(this, cl2), this.p = { + m: /*#__PURE__*/ _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // FOUR + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }) + }; + }, l = (_ref = _async_to_generator._(function() { + return _ts_generator._(this, function(_state) { + switch(_state.label){ + case 0: + return [ + 4, + import("./test") // FIVE + ]; + case 1: + return _state.sent(), [ + 2 + ]; + } + }); + }), function() { + return _ref.apply(this, arguments); + }); +}, "object" == typeof module && "object" == typeof module.exports ? factory(exports, require("@swc/helpers/_/_async_to_generator"), require("@swc/helpers/_/_class_call_check"), require("@swc/helpers/_/_interop_require_wildcard"), require("@swc/helpers/_/_ts_generator")) : "function" == typeof define && define.amd ? define([ + "exports", + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_class_call_check", + "@swc/helpers/_/_interop_require_wildcard", + "@swc/helpers/_/_ts_generator" +], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.testTs = {}, global.asyncToGenerator, global.classCallCheck, global.interopRequireWildcard, global.tsGenerator); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6AMD.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6AMD.2.minified.js index ba52310173b7..98785801b1ee 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6AMD.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6AMD.2.minified.js @@ -1 +1,82 @@ //// [test.ts] +define([ + "require", + "exports", + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_interop_require_wildcard" +], function(require, exports, _async_to_generator, _interop_require_wildcard) { + var _ref; + function fn() { + return _fn.apply(this, arguments); + } + function _fn() { + return (_fn = _async_to_generator._(function*() { + yield new Promise((resolve, reject)=>require([ + "./test" + ], (m)=>resolve(/*#__PURE__*/ _interop_require_wildcard._(m)), reject)) // ONE + ; + })).apply(this, arguments); + } + Object.defineProperty(exports, "__esModule", { + value: !0 + }), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); + }(exports, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } + }); + class cl1 { + m() { + return _async_to_generator._(function*() { + yield new Promise((resolve, reject)=>require([ + "./test" + ], (m)=>resolve(/*#__PURE__*/ _interop_require_wildcard._(m)), reject)) // TWO + ; + })(); + } + } + let obj = { + m: /*#__PURE__*/ _async_to_generator._(function*() { + yield new Promise((resolve, reject)=>require([ + "./test" + ], (m)=>resolve(/*#__PURE__*/ _interop_require_wildcard._(m)), reject)) // THREE + ; + }) + }; + class cl2 { + constructor(){ + this.p = { + m: /*#__PURE__*/ _async_to_generator._(function*() { + yield new Promise((resolve, reject)=>require([ + "./test" + ], (m)=>resolve(/*#__PURE__*/ _interop_require_wildcard._(m)), reject)) // FOUR + ; + }) + }; + } + } + let l = (_ref = _async_to_generator._(function*() { + yield new Promise((resolve, reject)=>require([ + "./test" + ], (m)=>resolve(/*#__PURE__*/ _interop_require_wildcard._(m)), reject)) // FIVE + ; + }), function() { + return _ref.apply(this, arguments); + }); +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6CJS.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6CJS.2.minified.js index 4d3ed48d3a02..1c31ac396806 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6CJS.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6CJS.2.minified.js @@ -1,7 +1,66 @@ //// [test.ts] -exports, exports; +var _ref; +Object.defineProperty(exports, "__esModule", { + value: !0 +}), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); +}(exports, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } +}); const _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"); -_async_to_generator._(function*() { +function fn() { + return _fn.apply(this, arguments); +} +function _fn() { + return (_fn = _async_to_generator._(function*() { + yield Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./test"))) // ONE + ; + })).apply(this, arguments); +} +class cl1 { + m() { + return _async_to_generator._(function*() { + yield Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./test"))) // TWO + ; + })(); + } +} +const obj = { + m: /*#__PURE__*/ _async_to_generator._(function*() { + yield Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./test"))) // THREE + ; + }) +}; +class cl2 { + constructor(){ + this.p = { + m: /*#__PURE__*/ _async_to_generator._(function*() { + yield Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./test"))) // FOUR + ; + }) + }; + } +} +const l = (_ref = _async_to_generator._(function*() { yield Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("./test"))) // FIVE ; +}), function() { + return _ref.apply(this, arguments); }); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6System.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6System.2.minified.js index ba52310173b7..aaaefe584d46 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6System.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6System.2.minified.js @@ -1 +1,55 @@ //// [test.ts] +System.register([ + "@swc/helpers/_/_async_to_generator" +], function(_export, _context) { + var _async_to_generator; + function _fn() { + return (_fn = _async_to_generator(function*() { + yield _context.import('./test') // ONE + ; + })).apply(this, arguments); + } + return _export({ + fn: function() { + return _fn.apply(this, arguments); + }, + cl1: void 0, + cl2: void 0 + }), { + setters: [ + function(_async_to_generator1) { + _async_to_generator = _async_to_generator1._; + } + ], + execute: function() { + var _ref; + _export("cl1", class { + m() { + return _async_to_generator(function*() { + yield _context.import('./test') // TWO + ; + })(); + } + }), _export("obj", { + m: /*#__PURE__*/ _async_to_generator(function*() { + yield _context.import('./test') // THREE + ; + }) + }), _export("cl2", class { + constructor(){ + this.p = { + m: /*#__PURE__*/ _async_to_generator(function*() { + yield _context.import('./test') // FOUR + ; + }) + }; + } + }), _export("l", (_ref = _async_to_generator(function*() { + yield _context.import('./test') // FIVE + ; + }), function() { + return _ref.apply(this, arguments); + })); + } + }; +}); diff --git a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6UMD.2.minified.js b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6UMD.2.minified.js index ba52310173b7..40fee6fec379 100644 --- a/crates/swc/tests/tsc-references/importCallExpressionAsyncES6UMD.2.minified.js +++ b/crates/swc/tests/tsc-references/importCallExpressionAsyncES6UMD.2.minified.js @@ -1 +1,72 @@ //// [test.ts] +var global, factory; +global = this, factory = function(exports1, _async_to_generator, _interop_require_wildcard) { + var _ref; + function fn() { + return _fn.apply(this, arguments); + } + function _fn() { + return (_fn = _async_to_generator._(function*() { + yield import('./test') // ONE + ; + })).apply(this, arguments); + } + Object.defineProperty(exports1, "__esModule", { + value: !0 + }), function(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: !0, + get: all[name] + }); + }(exports1, { + cl1: function() { + return cl1; + }, + cl2: function() { + return cl2; + }, + fn: function() { + return fn; + }, + l: function() { + return l; + }, + obj: function() { + return obj; + } + }); + class cl1 { + m() { + return _async_to_generator._(function*() { + yield import('./test') // TWO + ; + })(); + } + } + let obj = { + m: /*#__PURE__*/ _async_to_generator._(function*() { + yield import('./test') // THREE + ; + }) + }; + class cl2 { + constructor(){ + this.p = { + m: /*#__PURE__*/ _async_to_generator._(function*() { + yield import('./test') // FOUR + ; + }) + }; + } + } + let l = (_ref = _async_to_generator._(function*() { + yield import('./test') // FIVE + ; + }), function() { + return _ref.apply(this, arguments); + }); +}, "object" == typeof module && "object" == typeof module.exports ? factory(exports, require("@swc/helpers/_/_async_to_generator"), require("@swc/helpers/_/_interop_require_wildcard")) : "function" == typeof define && define.amd ? define([ + "exports", + "@swc/helpers/_/_async_to_generator", + "@swc/helpers/_/_interop_require_wildcard" +], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.testTs = {}, global.asyncToGenerator, global.interopRequireWildcard); diff --git a/crates/swc/tests/vercel/full/next-31419/1/output/index.js b/crates/swc/tests/vercel/full/next-31419/1/output/index.js index 8578309714f1..a8e5a97bb1c2 100644 --- a/crates/swc/tests/vercel/full/next-31419/1/output/index.js +++ b/crates/swc/tests/vercel/full/next-31419/1/output/index.js @@ -24,19 +24,19 @@ Promise.all(assignAll).then((r = e(function(r) { ]; } }); - }, s = 'DELETE FROM "TABLE" WHERE "UUID" IN ( ', i = [], r); + }, s = 'DELETE FROM "TABLE" WHERE "UUID" IN ( ', i = [], r)i.push(c); o = 0, u.label = 1; case 1: if (!(o < i.length)) return [ 3, 4 ]; - return(a = i[o], [ + return a = i[o], [ 5, n(e(a)) - ]); + ]; case 2: - u.label = 3; + u.sent(), u.label = 3; case 3: return o++, [ 3, diff --git a/crates/swc_common/src/comments.rs b/crates/swc_common/src/comments.rs index 38671f57b07a..3482d9cf2347 100644 --- a/crates/swc_common/src/comments.rs +++ b/crates/swc_common/src/comments.rs @@ -317,6 +317,8 @@ where } fn add_pure_comment(&self, pos: BytePos) { + assert_ne!(pos, BytePos(0), "cannot add pure comment to zero position"); + if let Some(c) = self { c.add_pure_comment(pos) } @@ -439,6 +441,8 @@ impl Comments for SingleThreadedComments { } fn add_pure_comment(&self, pos: BytePos) { + assert_ne!(pos, BytePos(0), "cannot add pure comment to zero position"); + let mut leading_map = self.leading.borrow_mut(); let leading = leading_map.entry(pos).or_default(); let pure_comment = Comment { diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index 0304b82eb5b7..8220a8e44e02 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -1164,11 +1164,15 @@ impl Generator { .unwrap() .make_member(quote_ident!("concat")) .as_callee(), - args: expressions - .take() - .into_iter() - .map(|expr| ExprOrSpread { spread: None, expr }) - .collect(), + args: vec![Box::new(Expr::Array(ArrayLit { + span: DUMMY_SP, + elems: expressions + .take() + .into_iter() + .map(|expr| Some(ExprOrSpread { spread: None, expr })) + .collect(), + })) + .as_arg()], type_args: Default::default(), })) } else { diff --git a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs index bb0e864a102d..4adc278dfed3 100644 --- a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs +++ b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs @@ -1,7 +1,9 @@ use std::iter; use serde::Deserialize; -use swc_common::{comments::Comments, util::take::Take, Mark, Spanned, SyntaxContext, DUMMY_SP}; +use swc_common::{ + comments::Comments, util::take::Take, Mark, Span, Spanned, SyntaxContext, DUMMY_SP, +}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, helper_expr, perf::Check}; use swc_ecma_transforms_macros::fast_path; @@ -359,7 +361,11 @@ impl Actual { *expr = wrapper.into(); if !in_iife { if let Some(c) = &mut self.comments { - c.add_pure_comment(expr.span().lo) + let mut lo = expr.span().lo; + if lo.is_dummy() { + lo = Span::dummy_with_cmt().lo; + } + c.add_pure_comment(lo); } } } @@ -377,7 +383,11 @@ impl Actual { *expr = wrapper.into(); if !in_iife { if let Some(c) = &mut self.comments { - c.add_pure_comment(expr.span().lo) + let mut lo = expr.span().lo; + if lo.is_dummy() { + lo = Span::dummy_with_cmt().lo; + } + c.add_pure_comment(lo) } } } diff --git a/crates/swc_ecma_minifier/src/metadata/mod.rs b/crates/swc_ecma_minifier/src/metadata/mod.rs index c6a5636239fd..5e3d6dfe2258 100644 --- a/crates/swc_ecma_minifier/src/metadata/mod.rs +++ b/crates/swc_ecma_minifier/src/metadata/mod.rs @@ -85,7 +85,9 @@ impl VisitMut for InfoMarker<'_> { _ => false, } { - n.span = n.span.apply_mark(self.marks.pure); + if !n.span.is_dummy_ignoring_cmt() { + n.span = n.span.apply_mark(self.marks.pure); + } } else if let Some(pure_fns) = &self.pure_funcs { if let Callee::Expr(e) = &n.callee { // Check for pure_funcs @@ -305,6 +307,10 @@ where } fn has_flag(comments: Option<&dyn Comments>, span: Span, text: &'static str) -> bool { + if span.is_dummy_ignoring_cmt() { + return false; + } + find_comment(comments, span, |c| { if c.kind == CommentKind::Block { for line in c.text.lines() { diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8173/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/8173/input.js new file mode 100644 index 000000000000..0443efcd7d6d --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8173/input.js @@ -0,0 +1,59 @@ +"use strict"; +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); + } +} +function _async_to_generator(fn) { + return function () { + var self = this, args = arguments; + return new Promise(function (resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} +const someFn = (xx, x, y) => [ + x, + y +]; +const getArray = () => [ + 1, + 2, + 3 +]; +const goodFunction = function () { + var _ref = _async_to_generator(function* () { + const rb = yield getArray(); + const rc = yield getArray(); + console.log(someFn(1, rb, rc)); + }); + return function goodFunction() { + return _ref.apply(this, arguments); + }; +}(); +const badFunction = function () { + var _ref = _async_to_generator(function* () { + console.log(someFn(1, (yield getArray()), (yield getArray()))); + }); + return function badFunction() { + return _ref.apply(this, arguments); + }; +}(); +goodFunction(); +badFunction(); diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8173/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/8173/output.js new file mode 100644 index 000000000000..6ed0858d61d7 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/8173/output.js @@ -0,0 +1,44 @@ +"use strict"; +var _ref, _ref1; +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg), value = info.value; + } catch (error) { + reject(error); + return; + } + info.done ? resolve(value) : Promise.resolve(value).then(_next, _throw); +} +function _async_to_generator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(void 0); + }); + }; +} +const someFn = (xx, x, y)=>[ + x, + y + ], getArray = ()=>[ + 1, + 2, + 3 + ], goodFunction = (_ref = _async_to_generator(function*() { + const rb = yield getArray(), rc = yield getArray(); + console.log(someFn(1, rb, rc)); +}), function() { + return _ref.apply(this, arguments); +}), badFunction = (_ref1 = _async_to_generator(function*() { + console.log(someFn(1, (yield getArray()), (yield getArray()))); +}), function() { + return _ref1.apply(this, arguments); +}); +goodFunction(), badFunction(); diff --git a/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-8155/exec.js b/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-8155/exec.js new file mode 100644 index 000000000000..76fdf1f8cc6d --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/async-to-generator/issue-8155/exec.js @@ -0,0 +1,16 @@ +const someFn = (xx, x, y) => [x, y]; + +const getArray = () => [1, 2, 3]; + +const goodFunction = async () => { + const rb = await getArray(); + const rc = await getArray(); + console.log(someFn(1, rb, rc)); +} + +const badFunction = async () => { + console.log(someFn(1, await getArray(), await getArray())) +} + +goodFunction(); +badFunction();