From 67286032b1bd75ef1dac51201fe5ff65143f565a Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 14 Nov 2022 07:52:34 +0800 Subject: [PATCH] fix(es/compat): Improve `destructuring` pass (#6412) --- .../issues-1xxx/1449/case1/output/index.js | 6 +- .../pr-1579/checkingExtend/output/index.js | 3 +- .../issues-2xxx/2964/case-5/output/index.ts | 5 +- .../fixture/issues-6xxx/6306/input/index.js | 2 + .../fixture/issues-6xxx/6306/output/index.js | 3 + .../fixture/issues-6xxx/6330/input/input.js | 1 + .../fixture/issues-6xxx/6330/output/input.js | 4 ++ .../fixture/issues-6xxx/6390/input/input.js | 5 ++ .../fixture/issues-6xxx/6390/output/input.js | 7 ++ .../fixture/issues-6xxx/6392/1/input/index.js | 1 + .../issues-6xxx/6392/1/output/index.js | 2 + .../fixture/issues-6xxx/6392/2/input/index.js | 8 +++ .../issues-6xxx/6392/2/output/index.js | 7 ++ .../asyncWithVarShadowing_es6.1.normal.js | 3 +- .../declarationsAndAssignments.1.normal.js | 22 +++--- ...estructuringAssignabilityCheck.1.normal.js | 12 ++-- ...tructuringAssignabilityCheck.2.minified.js | 10 +-- ...EvaluationOrder(target=es2015).1.normal.js | 3 +- ...aluationOrder(target=es2015).2.minified.js | 3 +- ...ingEvaluationOrder(target=es5).1.normal.js | 4 +- ...gEvaluationOrder(target=es5).2.minified.js | 6 +- ...turingParameterDeclaration7ES5.1.normal.js | 10 +-- ...rameterDeclaration7ES5iterable.1.normal.js | 10 +-- .../destructuringVoid.1.normal.js | 4 +- .../destructuringVoid.2.minified.js | 4 +- ...tructuringVoidStrictNullChecks.1.normal.js | 4 +- ...ucturingVoidStrictNullChecks.2.minified.js | 4 +- .../emptyAssignmentPatterns01_ES5.1.normal.js | 6 +- ...mptyAssignmentPatterns01_ES5.2.minified.js | 3 +- ...signmentPatterns01_ES5iterable.1.normal.js | 6 +- ...gnmentPatterns01_ES5iterable.2.minified.js | 3 +- .../emptyAssignmentPatterns02_ES5.1.normal.js | 9 +-- ...mptyAssignmentPatterns02_ES5.2.minified.js | 3 +- ...signmentPatterns02_ES5iterable.1.normal.js | 9 +-- ...gnmentPatterns02_ES5iterable.2.minified.js | 3 +- .../emptyAssignmentPatterns03_ES5.1.normal.js | 6 +- ...mptyAssignmentPatterns03_ES5.2.minified.js | 3 +- ...signmentPatterns03_ES5iterable.1.normal.js | 6 +- ...gnmentPatterns03_ES5iterable.2.minified.js | 3 +- .../emptyAssignmentPatterns04_ES5.1.normal.js | 9 +-- ...mptyAssignmentPatterns04_ES5.2.minified.js | 5 +- ...signmentPatterns04_ES5iterable.1.normal.js | 9 +-- ...gnmentPatterns04_ES5iterable.2.minified.js | 5 +- ...bjectBindingPatternParameter01.1.normal.js | 4 +- ...bjectBindingPatternParameter02.1.normal.js | 4 +- ...bjectBindingPatternParameter03.1.normal.js | 4 +- ...bjectBindingPatternParameter04.1.normal.js | 6 +- ...clarationBindingPatterns01_ES5.1.normal.js | 38 +++++------ ...arationBindingPatterns01_ES5.2.minified.js | 25 ++----- ...nBindingPatterns01_ES5iterable.1.normal.js | 38 +++++------ ...indingPatterns01_ES5iterable.2.minified.js | 25 ++----- .../genericObjectRest.1.normal.js | 3 +- .../missingAndExcessProperties.1.normal.js | 21 +++--- ...ckedIndexedAccessDestructuring.1.normal.js | 3 +- ...edIndexedAccessDestructuring.2.minified.js | 3 +- .../nonPrimitiveAccessProperty.1.normal.js | 3 +- .../nonPrimitiveAccessProperty.2.minified.js | 3 +- .../tsc-references/objectRest.1.normal.js | 5 +- .../tsc-references/objectRest.2.minified.js | 5 +- .../objectRestAssignment.1.normal.js | 5 +- .../objectRestAssignment.2.minified.js | 5 +- ...privateNameAndObjectRestSpread.1.normal.js | 5 +- .../privateWriteOnlyAccessorRead.1.normal.js | 5 +- ...privateWriteOnlyAccessorRead.2.minified.js | 9 +-- ...nStaticMembers1(target=es2015).1.normal.js | 3 +- ...taticMembers1(target=es2015).2.minified.js | 3 +- ...nStaticMembers2(target=es2015).1.normal.js | 3 +- ...taticMembers2(target=es2015).2.minified.js | 3 +- .../tsc-references/unknownType1.1.normal.js | 3 +- .../helpers/_object_destructuring_empty.js | 4 ++ .../src/helpers/mod.rs | 1 + .../src/es2015/destructuring.rs | 68 +++++++------------ .../src/es2018/object_rest_spread.rs | 11 ++- .../tests/es2015_destructuring.rs | 4 +- .../tests/es2018_object_rest_spread.rs | 51 +++++++------- .../src/_object_destructuring_empty.mjs | 4 ++ 76 files changed, 328 insertions(+), 290 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-6xxx/6306/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6306/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6330/input/input.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6330/output/input.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6390/input/input.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6390/output/input.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6392/1/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6392/1/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6392/2/input/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6392/2/output/index.js create mode 100644 crates/swc_ecma_transforms_base/src/helpers/_object_destructuring_empty.js create mode 100644 packages/swc-helpers/src/_object_destructuring_empty.mjs diff --git a/crates/swc/tests/fixture/issues-1xxx/1449/case1/output/index.js b/crates/swc/tests/fixture/issues-1xxx/1449/case1/output/index.js index 5076a66a0d21..825d3c99ed68 100644 --- a/crates/swc/tests/fixture/issues-1xxx/1449/case1/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/1449/case1/output/index.js @@ -1,14 +1,14 @@ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _ts_generator from "@swc/helpers/src/_ts_generator.mjs"; function foo() { return _foo.apply(this, arguments); } function _foo() { _foo = _async_to_generator(function() { - var tmp, _ref, _ref; + var tmp, ref; return _ts_generator(this, function(_state) { - tmp = baz.bar, _ref = tmp === void 0 ? {} : tmp, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")); + tmp = baz.bar, ref = _object_destructuring_empty(tmp === void 0 ? {} : tmp); return [ 2 ]; diff --git a/crates/swc/tests/fixture/issues-1xxx/pr-1579/checkingExtend/output/index.js b/crates/swc/tests/fixture/issues-1xxx/pr-1579/checkingExtend/output/index.js index 340adb20654c..14fedfabcaf2 100644 --- a/crates/swc/tests/fixture/issues-1xxx/pr-1579/checkingExtend/output/index.js +++ b/crates/swc/tests/fixture/issues-1xxx/pr-1579/checkingExtend/output/index.js @@ -1,3 +1,4 @@ import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; var a = {}; -var b = _extends({}, a); +var b = _extends({}, _object_destructuring_empty(a)); diff --git a/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts index 9b3f59bc79bd..68605db0373a 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2964/case-5/output/index.ts @@ -14,9 +14,10 @@ _export(exports, { foo: ()=>foo }); const _extends = require("@swc/helpers/lib/_extends.js").default; +const _objectDestructuringEmpty = require("@swc/helpers/lib/_object_destructuring_empty.js").default; const a = 1; const b = 2; -var foo = _extends({}, { +var foo = _extends({}, _objectDestructuringEmpty({ a: 1, b: 2 -}); +})); diff --git a/crates/swc/tests/fixture/issues-6xxx/6306/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6306/input/index.js new file mode 100644 index 000000000000..cd7e49d48c56 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6306/input/index.js @@ -0,0 +1,2 @@ +"use strict"; +x = {} = null; diff --git a/crates/swc/tests/fixture/issues-6xxx/6306/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6306/output/index.js new file mode 100644 index 000000000000..f1606c205fd4 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6306/output/index.js @@ -0,0 +1,3 @@ +"use strict"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +x = _object_destructuring_empty(null); diff --git a/crates/swc/tests/fixture/issues-6xxx/6330/input/input.js b/crates/swc/tests/fixture/issues-6xxx/6330/input/input.js new file mode 100644 index 000000000000..c0fe3a97c223 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6330/input/input.js @@ -0,0 +1 @@ +new (function ({}) {})(); diff --git a/crates/swc/tests/fixture/issues-6xxx/6330/output/input.js b/crates/swc/tests/fixture/issues-6xxx/6330/output/input.js new file mode 100644 index 000000000000..284b36aaf84b --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6330/output/input.js @@ -0,0 +1,4 @@ +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +new function(param) { + var ref = _object_destructuring_empty(param); +}(); diff --git a/crates/swc/tests/fixture/issues-6xxx/6390/input/input.js b/crates/swc/tests/fixture/issues-6xxx/6390/input/input.js new file mode 100644 index 000000000000..5bad11473a51 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6390/input/input.js @@ -0,0 +1,5 @@ +var { ...x } = null; +var { ...y } = undefined; + +var z; +({...z} = null); \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6390/output/input.js b/crates/swc/tests/fixture/issues-6xxx/6390/output/input.js new file mode 100644 index 000000000000..4d723d8c5a9b --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6390/output/input.js @@ -0,0 +1,7 @@ +import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +var x = _extends({}, _object_destructuring_empty(null)); +var y = _extends({}, _object_destructuring_empty(undefined)); +var z; +var _tmp; +_tmp = null, z = _extends({}, _object_destructuring_empty(_tmp)), _tmp; diff --git a/crates/swc/tests/fixture/issues-6xxx/6392/1/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6392/1/input/index.js new file mode 100644 index 000000000000..ff8fe35a497c --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6392/1/input/index.js @@ -0,0 +1 @@ +let {} = x; diff --git a/crates/swc/tests/fixture/issues-6xxx/6392/1/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6392/1/output/index.js new file mode 100644 index 000000000000..25244c2a3630 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6392/1/output/index.js @@ -0,0 +1,2 @@ +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +var ref = _object_destructuring_empty(x); diff --git a/crates/swc/tests/fixture/issues-6xxx/6392/2/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6392/2/input/index.js new file mode 100644 index 000000000000..e9c1687056e1 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6392/2/input/index.js @@ -0,0 +1,8 @@ +let x = 42; + +function f() { + let {} = x; + console.log(x); +} + +f(); diff --git a/crates/swc/tests/fixture/issues-6xxx/6392/2/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6392/2/output/index.js new file mode 100644 index 000000000000..90fab4757200 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6392/2/output/index.js @@ -0,0 +1,7 @@ +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +var x = 42; +function f() { + var ref = _object_destructuring_empty(x); + console.log(x); +} +f(); diff --git a/crates/swc/tests/tsc-references/asyncWithVarShadowing_es6.1.normal.js b/crates/swc/tests/tsc-references/asyncWithVarShadowing_es6.1.normal.js index d191248c951c..4da024748e8f 100644 --- a/crates/swc/tests/tsc-references/asyncWithVarShadowing_es6.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncWithVarShadowing_es6.1.normal.js @@ -2,6 +2,7 @@ // https://github.com/Microsoft/TypeScript/issues/20461 import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; function fn1(x) { return _fn1.apply(this, arguments); } @@ -97,7 +98,7 @@ function fn11(x) { } function _fn11() { _fn11 = _async_to_generator(function*(x) { - var x = _extends({}, y); + var x = _extends({}, _object_destructuring_empty(y)); }); return _fn11.apply(this, arguments); } diff --git a/crates/swc/tests/tsc-references/declarationsAndAssignments.1.normal.js b/crates/swc/tests/tsc-references/declarationsAndAssignments.1.normal.js index 31f6831269c2..89893a9bc525 100644 --- a/crates/swc/tests/tsc-references/declarationsAndAssignments.1.normal.js +++ b/crates/swc/tests/tsc-references/declarationsAndAssignments.1.normal.js @@ -1,6 +1,6 @@ //// [declarationsAndAssignments.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; import _to_array from "@swc/helpers/src/_to_array.mjs"; function f0() { var _ref = [ @@ -33,10 +33,10 @@ function f1() { var z; } function f2() { - var _ref = { + var ref = _object_destructuring_empty({ x: 5, y: "hello" - }, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")); // Ok, empty binding pattern means nothing + }); // Ok, empty binding pattern means nothing var x = { x: 5, y: "hello" @@ -45,24 +45,24 @@ function f2() { x: 5, y: "hello" }.y; // Error, no x in target - var _ref1 = { + var _ref = { x: 5, y: "hello" - }, x = _ref1.x, y = _ref1.y; + }, x = _ref.x, y = _ref.y; var x; var y; - var _ref2 = { + var _ref1 = { x: 5, y: "hello" - }, a = _ref2.x; // Error, no y in target - var _ref3 = { + }, a = _ref1.x; // Error, no y in target + var _ref2 = { x: 5, y: "hello" - }, b = _ref3.y; // Error, no x in target - var _ref4 = { + }, b = _ref2.y; // Error, no x in target + var _ref3 = { x: 5, y: "hello" - }, a = _ref4.x, b = _ref4.y; + }, a = _ref3.x, b = _ref3.y; var a; var b; } diff --git a/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.1.normal.js b/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.1.normal.js index 786e1d0d3710..47a3dfa12483 100644 --- a/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.1.normal.js @@ -1,23 +1,23 @@ //// [destructuringAssignabilityCheck.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; var _ref = _sliced_to_array({}, 0); // should be error -var undefined = undefined !== null ? undefined : _throw(new TypeError("Cannot destructure undefined")); // error correctly +var ref = _object_destructuring_empty(undefined); // error correctly (function(param) { var _param = _sliced_to_array(param, 0); return 0; })({}); // should be error (function(param) { - var param = param !== null ? param : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(param); return 0; })(undefined); // should be error function foo(param) { - var param = param !== null ? param : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(param); return 0; } function bar(param) { var _param = _sliced_to_array(param, 0); return 0; } -var _ref1 = 1, _ref1 = _ref1 !== null ? _ref1 : _throw(new TypeError("Cannot destructure undefined")); -var _ref2 = _sliced_to_array({}, 0); +var ref1 = _object_destructuring_empty(1); +var _ref1 = _sliced_to_array({}, 0); diff --git a/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.2.minified.js b/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.2.minified.js index daaa21caf033..c0bbe8d3d20d 100644 --- a/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringAssignabilityCheck.2.minified.js @@ -1,10 +1,4 @@ //// [destructuringAssignabilityCheck.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; -_sliced_to_array({}, 0); -var undefined = undefined; -_sliced_to_array({}, 0), function(param) { - var param = null !== param ? param : _throw(new TypeError("Cannot destructure undefined")); -}(undefined); -var _ref = 1, _ref = null !== _ref ? _ref : _throw(new TypeError("Cannot destructure undefined")); -_sliced_to_array({}, 0); +_sliced_to_array({}, 0), _object_destructuring_empty(void 0), _sliced_to_array({}, 0), _object_destructuring_empty(void 0), _object_destructuring_empty(1), _sliced_to_array({}, 0); diff --git a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).1.normal.js index 268d63f16648..1af7d5d8cc21 100644 --- a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).1.normal.js @@ -1,6 +1,7 @@ //// [destructuringEvaluationOrder.ts] // https://github.com/microsoft/TypeScript/issues/39205 import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; let trace = []; @@ -23,4 +24,4 @@ let _ref1 = [ { x: 1 } -], [{}, b = a] = _ref1, a = _extends({}, _ref1[0]); +], [{}, b = a] = _ref1, a = _extends({}, _object_destructuring_empty(_ref1[0])); diff --git a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).2.minified.js index 9ba045803299..b33f666cc343 100644 --- a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es2015).2.minified.js @@ -1,5 +1,6 @@ //// [destructuringEvaluationOrder.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; let trace = [], order = (n)=>trace.push(n), [{ [order(1)]: x } = order(0)] = [], [{ [order(1)]: y } = order(0)] = [ @@ -12,4 +13,4 @@ let _ref1 = [ { x: 1 } -], [{}, b = a] = _ref1, a = _extends({}, _ref1[0]); +], [{}, b = a] = _ref1, a = _extends({}, _object_destructuring_empty(_ref1[0])); diff --git a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).1.normal.js b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).1.normal.js index 3793fccac709..4184b23784f0 100644 --- a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).1.normal.js @@ -1,9 +1,9 @@ //// [destructuringEvaluationOrder.ts] // https://github.com/microsoft/TypeScript/issues/39205 import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; var trace = []; var order = function(n) { @@ -25,4 +25,4 @@ var _ref5 = [ { x: 1 } -], _ref6 = _sliced_to_array(_ref5, 2), _ref_ = _ref6[0], _ref_ = _ref_ !== null ? _ref_ : _throw(new TypeError("Cannot destructure undefined")), tmp3 = _ref6[1], b = tmp3 === void 0 ? a : tmp3, a = _extends({}, _ref5[0]); +], _ref6 = _sliced_to_array(_ref5, 2), ref = _object_destructuring_empty(_ref6[0]), tmp3 = _ref6[1], b = tmp3 === void 0 ? a : tmp3, a = _extends({}, _object_destructuring_empty(_ref5[0])); diff --git a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).2.minified.js b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).2.minified.js index 3394bad5f4ba..3cdd60a0021e 100644 --- a/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringEvaluationOrder(target=es5).2.minified.js @@ -1,8 +1,8 @@ //// [destructuringEvaluationOrder.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; var trace = [], order = function(n) { return trace.push(n); @@ -18,5 +18,5 @@ var _ref1 = [ { x: 1 } -], _ref2 = _sliced_to_array(_ref1, 2), _ref_ = _ref2[0], _ref_ = null !== _ref_ ? _ref_ : _throw(new TypeError("Cannot destructure undefined")); -_ref2[1], _extends({}, _ref1[0]); +], _ref2 = _sliced_to_array(_ref1, 2); +_object_destructuring_empty(_ref2[0]), _ref2[1], _extends({}, _object_destructuring_empty(_ref1[0])); diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5.1.normal.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5.1.normal.js index 9474993cb2fb..2d1601439ab7 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5.1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5.1.normal.js @@ -1,14 +1,14 @@ //// [destructuringParameterDeclaration7ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; -function foo(_$param, param) { - var _$param = _$param !== null ? _$param : _throw(new TypeError("Cannot destructure undefined")), foo = param.foo, bar = param.bar; +function foo(param, param1) { + var ref = _object_destructuring_empty(param), foo = param1.foo, bar = param1.bar; } function baz(param, param1) { var _param = _sliced_to_array(param, 0), foo = param1.foo, bar = param1.bar; } -function one(param, _$param) { - var _param = _sliced_to_array(param, 0), _$param = _$param !== null ? _$param : _throw(new TypeError("Cannot destructure undefined")); +function one(param, param1) { + var _param = _sliced_to_array(param, 0), ref = _object_destructuring_empty(param1); } function two(param, param1) { var _param = _sliced_to_array(param, 0), _param1 = _sliced_to_array(param1, 3), a = _param1[0], b = _param1[1], c = _param1[2]; diff --git a/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5iterable.1.normal.js b/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5iterable.1.normal.js index 56a20b7490eb..e7e8ab90179d 100644 --- a/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5iterable.1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringParameterDeclaration7ES5iterable.1.normal.js @@ -1,14 +1,14 @@ //// [destructuringParameterDeclaration7ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; -function foo(_$param, param) { - var _$param = _$param !== null ? _$param : _throw(new TypeError("Cannot destructure undefined")), foo = param.foo, bar = param.bar; +function foo(param, param1) { + var ref = _object_destructuring_empty(param), foo = param1.foo, bar = param1.bar; } function baz(param, param1) { var _param = _sliced_to_array(param, 0), foo = param1.foo, bar = param1.bar; } -function one(param, _$param) { - var _param = _sliced_to_array(param, 0), _$param = _$param !== null ? _$param : _throw(new TypeError("Cannot destructure undefined")); +function one(param, param1) { + var _param = _sliced_to_array(param, 0), ref = _object_destructuring_empty(param1); } function two(param, param1) { var _param = _sliced_to_array(param, 0), _param1 = _sliced_to_array(param1, 3), a = _param1[0], b = _param1[1], c = _param1[2]; diff --git a/crates/swc/tests/tsc-references/destructuringVoid.1.normal.js b/crates/swc/tests/tsc-references/destructuringVoid.1.normal.js index b0bd1d0aa410..1376baaa3ce4 100644 --- a/crates/swc/tests/tsc-references/destructuringVoid.1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringVoid.1.normal.js @@ -1,3 +1,3 @@ //// [destructuringVoid.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; -var v = v !== null ? v : _throw(new TypeError("Cannot destructure undefined")); +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +var ref = _object_destructuring_empty(v); diff --git a/crates/swc/tests/tsc-references/destructuringVoid.2.minified.js b/crates/swc/tests/tsc-references/destructuringVoid.2.minified.js index 5b0499c1e0f5..e0cadefc974c 100644 --- a/crates/swc/tests/tsc-references/destructuringVoid.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringVoid.2.minified.js @@ -1,3 +1,3 @@ //// [destructuringVoid.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; -var v = null !== v ? v : _throw(new TypeError("Cannot destructure undefined")); +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +_object_destructuring_empty(v); diff --git a/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.1.normal.js b/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.1.normal.js index c93bdde7a22b..55d481ecf026 100644 --- a/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.1.normal.js +++ b/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.1.normal.js @@ -1,3 +1,3 @@ //// [destructuringVoidStrictNullChecks.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; -var v = v !== null ? v : _throw(new TypeError("Cannot destructure undefined")); +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +var ref = _object_destructuring_empty(v); diff --git a/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.2.minified.js b/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.2.minified.js index eaf182ff6548..36b147a4869e 100644 --- a/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.2.minified.js +++ b/crates/swc/tests/tsc-references/destructuringVoidStrictNullChecks.2.minified.js @@ -1,3 +1,3 @@ //// [destructuringVoidStrictNullChecks.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; -var v = null !== v ? v : _throw(new TypeError("Cannot destructure undefined")); +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +_object_destructuring_empty(v); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.1.normal.js index bce336e68a14..cbb80d076a2d 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.1.normal.js @@ -1,10 +1,10 @@ //// [emptyAssignmentPatterns01_ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; +_object_destructuring_empty(a); var ref; -ref = a, ref; -var ref1; -ref1 = _sliced_to_array(a, 0), ref1; +ref = _sliced_to_array(a, 0), ref; var _ref = [ 1, 2 diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.2.minified.js index 604191c41e2e..1d2dfd96f867 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns01_ES5.ts] var a; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -_sliced_to_array(a, 0); +_object_destructuring_empty(a), _sliced_to_array(a, 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.1.normal.js index ffc56c1012cb..e4fb46259b36 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.1.normal.js @@ -1,7 +1,7 @@ //// [emptyAssignmentPatterns01_ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; +_object_destructuring_empty(a); var ref; -ref = a, ref; -var ref1; -ref1 = _sliced_to_array(a, 0), ref1; +ref = _sliced_to_array(a, 0), ref; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.2.minified.js index 2dcc901b7775..e4cf33cc9aee 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns01_ES5iterable.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns01_ES5iterable.ts] var a; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -_sliced_to_array(a, 0); +_object_destructuring_empty(a), _sliced_to_array(a, 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.1.normal.js index b23eb6a2dc54..2e5dc97bddbf 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.1.normal.js @@ -1,8 +1,9 @@ //// [emptyAssignmentPatterns02_ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; var x, y, z, a1, a2, a3; -var ref, ref1; -ref1 = (ref = a, x = ref.x, y = ref.y, z = ref.z, ref), ref1; -var ref2, ref3; -ref3 = _sliced_to_array((ref2 = _sliced_to_array(a, 3), a1 = ref2[0], a2 = ref2[1], a3 = ref2[2], ref2), 0), ref3; +var ref; +_object_destructuring_empty((ref = a, x = ref.x, y = ref.y, z = ref.z, ref)); +var ref1, ref2; +ref2 = _sliced_to_array((ref1 = _sliced_to_array(a, 3), a1 = ref1[0], a2 = ref1[1], a3 = ref1[2], ref1), 0), ref2; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.2.minified.js index 7bf7236da568..4c2bb9edfdd1 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns02_ES5.ts] var a, ref; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -a.x, a.y, a.z, _sliced_to_array(((ref = _sliced_to_array(a, 3))[0], ref[1], ref[2], ref), 0); +_object_destructuring_empty((a.x, a.y, a.z, a)), _sliced_to_array(((ref = _sliced_to_array(a, 3))[0], ref[1], ref[2], ref), 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.1.normal.js index 729f3e0a3ef2..15998446c178 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.1.normal.js @@ -1,8 +1,9 @@ //// [emptyAssignmentPatterns02_ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; var x, y, z, a1, a2, a3; -var ref, ref1; -ref1 = (ref = a, x = ref.x, y = ref.y, z = ref.z, ref), ref1; -var ref2, ref3; -ref3 = _sliced_to_array((ref2 = _sliced_to_array(a, 3), a1 = ref2[0], a2 = ref2[1], a3 = ref2[2], ref2), 0), ref3; +var ref; +_object_destructuring_empty((ref = a, x = ref.x, y = ref.y, z = ref.z, ref)); +var ref1, ref2; +ref2 = _sliced_to_array((ref1 = _sliced_to_array(a, 3), a1 = ref1[0], a2 = ref1[1], a3 = ref1[2], ref1), 0), ref2; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.2.minified.js index 35db6b6b0553..5c23f0e9f6a6 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns02_ES5iterable.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns02_ES5iterable.ts] var a, ref; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -a.x, a.y, a.z, _sliced_to_array(((ref = _sliced_to_array(a, 3))[0], ref[1], ref[2], ref), 0); +_object_destructuring_empty((a.x, a.y, a.z, a)), _sliced_to_array(((ref = _sliced_to_array(a, 3))[0], ref[1], ref[2], ref), 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.1.normal.js index 4b6c73de3c37..dce5538ec575 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.1.normal.js @@ -1,7 +1,7 @@ //// [emptyAssignmentPatterns03_ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; +_object_destructuring_empty(_object_destructuring_empty(a)); var ref, ref1; -ref1 = (ref = a, ref), ref1; -var ref2, ref3; -ref3 = _sliced_to_array((ref2 = _sliced_to_array(a, 0), ref2), 0), ref3; +ref1 = _sliced_to_array((ref = _sliced_to_array(a, 0), ref), 0), ref1; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.2.minified.js index bd3c125ec3bf..4621b8afd11d 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns03_ES5.ts] var a; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -_sliced_to_array(_sliced_to_array(a, 0), 0); +_object_destructuring_empty(_object_destructuring_empty(a)), _sliced_to_array(_sliced_to_array(a, 0), 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.1.normal.js index c036fecd997f..d7d51cb930f2 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.1.normal.js @@ -1,7 +1,7 @@ //// [emptyAssignmentPatterns03_ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; +_object_destructuring_empty(_object_destructuring_empty(a)); var ref, ref1; -ref1 = (ref = a, ref), ref1; -var ref2, ref3; -ref3 = _sliced_to_array((ref2 = _sliced_to_array(a, 0), ref2), 0), ref3; +ref1 = _sliced_to_array((ref = _sliced_to_array(a, 0), ref), 0), ref1; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.2.minified.js index d8010b784036..c06bff5d95ed 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns03_ES5iterable.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns03_ES5iterable.ts] var a; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -_sliced_to_array(_sliced_to_array(a, 0), 0); +_object_destructuring_empty(_object_destructuring_empty(a)), _sliced_to_array(_sliced_to_array(a, 0), 0); diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.1.normal.js index 1b4f5672feca..e2501f8c5de7 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.1.normal.js @@ -1,8 +1,9 @@ //// [emptyAssignmentPatterns04_ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; var x, y, z, a1, a2, a3; -var ref, ref1; -ref1 = (ref = a, ref), x = ref1.x, y = ref1.y, z = ref1.z, ref1; -var ref2, ref3; -ref3 = _sliced_to_array((ref2 = _sliced_to_array(a, 0), ref2), 3), a1 = ref3[0], a2 = ref3[1], a3 = ref3[2], ref3; +var ref; +ref = _object_destructuring_empty(a), x = ref.x, y = ref.y, z = ref.z, ref; +var ref1, ref2; +ref2 = _sliced_to_array((ref1 = _sliced_to_array(a, 0), ref1), 3), a1 = ref2[0], a2 = ref2[1], a3 = ref2[2], ref2; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.2.minified.js index 69b33f69e32b..d0495319bbc9 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns04_ES5.ts] -var a, ref; +var a, ref, ref1; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -a.x, a.y, a.z, (ref = _sliced_to_array(_sliced_to_array(a, 0), 3))[0], ref[1], ref[2]; +(ref = _object_destructuring_empty(a)).x, ref.y, ref.z, (ref1 = _sliced_to_array(_sliced_to_array(a, 0), 3))[0], ref1[1], ref1[2]; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.1.normal.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.1.normal.js index dcf98eded261..b577bd38bea6 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.1.normal.js @@ -1,8 +1,9 @@ //// [emptyAssignmentPatterns04_ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; var a; var x, y, z, a1, a2, a3; -var ref, ref1; -ref1 = (ref = a, ref), x = ref1.x, y = ref1.y, z = ref1.z, ref1; -var ref2, ref3; -ref3 = _sliced_to_array((ref2 = _sliced_to_array(a, 0), ref2), 3), a1 = ref3[0], a2 = ref3[1], a3 = ref3[2], ref3; +var ref; +ref = _object_destructuring_empty(a), x = ref.x, y = ref.y, z = ref.z, ref; +var ref1, ref2; +ref2 = _sliced_to_array((ref1 = _sliced_to_array(a, 0), ref1), 3), a1 = ref2[0], a2 = ref2[1], a3 = ref2[2], ref2; diff --git a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.2.minified.js b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.2.minified.js index 9c869cab183c..12a0982edf2c 100644 --- a/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyAssignmentPatterns04_ES5iterable.2.minified.js @@ -1,4 +1,5 @@ //// [emptyAssignmentPatterns04_ES5iterable.ts] -var a, ref; +var a, ref, ref1; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -a.x, a.y, a.z, (ref = _sliced_to_array(_sliced_to_array(a, 0), 3))[0], ref[1], ref[2]; +(ref = _object_destructuring_empty(a)).x, ref.y, ref.z, (ref1 = _sliced_to_array(_sliced_to_array(a, 0), 3))[0], ref1[1], ref1[2]; diff --git a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter01.1.normal.js b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter01.1.normal.js index e179055dfdaa..c80bc5cd7abc 100644 --- a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter01.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter01.1.normal.js @@ -1,6 +1,6 @@ //// [emptyObjectBindingPatternParameter01.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; function f(param) { - var param = param !== null ? param : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(param); var x, y, z; } diff --git a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter02.1.normal.js b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter02.1.normal.js index 4e883cf956c6..db3b3f21c5d0 100644 --- a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter02.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter02.1.normal.js @@ -1,6 +1,6 @@ //// [emptyObjectBindingPatternParameter02.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; function f(a, param) { - var param = param !== null ? param : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(param); var x, y, z; } diff --git a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter03.1.normal.js b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter03.1.normal.js index e66e868d47c6..63dcc395c510 100644 --- a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter03.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter03.1.normal.js @@ -1,6 +1,6 @@ //// [emptyObjectBindingPatternParameter03.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; function f(param, a) { - var param = param !== null ? param : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(param); var x, y, z; } diff --git a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter04.1.normal.js b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter04.1.normal.js index ed790dcb577f..fc68eac292e5 100644 --- a/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter04.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyObjectBindingPatternParameter04.1.normal.js @@ -1,10 +1,10 @@ //// [emptyObjectBindingPatternParameter04.ts] -import _throw from "@swc/helpers/src/_throw.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; function f() { - var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : { + var ref = _object_destructuring_empty(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : { a: 1, b: "2", c: true - }, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")); + }); var x, y, z; } diff --git a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.1.normal.js b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.1.normal.js index 2a788b145ba1..42a07ed6a616 100644 --- a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.1.normal.js @@ -1,35 +1,35 @@ //// [emptyVariableDeclarationBindingPatterns01_ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; (function() { var f = function f() { - var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref2.p, _ref3 = tmp === void 0 ? a : tmp, _ref3 = _ref3 !== null ? _ref3 : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a), _ref = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref1 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref1.p, ref1 = _object_destructuring_empty(tmp === void 0 ? a : tmp); return function() { - var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref2.p, _ref3 = tmp === void 0 ? a : tmp, _ref3 = _ref3 !== null ? _ref3 : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a), _ref = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref1 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref1.p, ref1 = _object_destructuring_empty(tmp === void 0 ? a : tmp); return a; }; }; var a; - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(a); + var ref1 = _object_destructuring_empty(a); + var ref2 = _object_destructuring_empty(a); var _a = _sliced_to_array(a, 0); var _a1 = _sliced_to_array(a, 0); var _a2 = _sliced_to_array(a, 0); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")), _a3 = _sliced_to_array(a, 0); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")), _a4 = _sliced_to_array(a, 0); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")), _a5 = _sliced_to_array(a, 0); - var _a_p1 = a.p1, _a_p1 = _a_p1 !== null ? _a_p1 : _throw(new TypeError("Cannot destructure undefined")), _a_p2 = _sliced_to_array(a.p2, 0); - var _a_p11 = a.p1, _a_p11 = _a_p11 !== null ? _a_p11 : _throw(new TypeError("Cannot destructure undefined")), _a_p21 = _sliced_to_array(a.p2, 0); - var _a_p12 = a.p1, _a_p12 = _a_p12 !== null ? _a_p12 : _throw(new TypeError("Cannot destructure undefined")), _a_p22 = _sliced_to_array(a.p2, 0); - for(var _ref = {}, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = {}, _ref1 = _ref1 !== null ? _ref1 : _throw(new TypeError("Cannot destructure undefined")); false; void 0){} + var ref3 = _object_destructuring_empty(a), _a3 = _sliced_to_array(a, 0); + var ref4 = _object_destructuring_empty(a), _a4 = _sliced_to_array(a, 0); + var ref5 = _object_destructuring_empty(a), _a5 = _sliced_to_array(a, 0); + var ref6 = _object_destructuring_empty(a.p1), _a_p2 = _sliced_to_array(a.p2, 0); + var ref7 = _object_destructuring_empty(a.p1), _a_p21 = _sliced_to_array(a.p2, 0); + var ref8 = _object_destructuring_empty(a.p1), _a_p22 = _sliced_to_array(a.p2, 0); + for(var ref9 = _object_destructuring_empty({}), ref10 = _object_destructuring_empty({}); false; void 0){} })(); (function() { var ns = []; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { for(var _iterator = ns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var _step_value = _step.value, _step_value = _step_value !== null ? _step_value : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(_step.value); } } catch (err) { _didIteratorError = true; @@ -48,7 +48,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; try { for(var _iterator1 = ns[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var _step_value1 = _step1.value, _step_value1 = _step_value1 !== null ? _step_value1 : _throw(new TypeError("Cannot destructure undefined")); + var ref1 = _object_destructuring_empty(_step1.value); } } catch (err) { _didIteratorError1 = true; @@ -67,7 +67,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; try { for(var _iterator2 = ns[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ - var _step_value2 = _step2.value, _step_value2 = _step_value2 !== null ? _step_value2 : _throw(new TypeError("Cannot destructure undefined")); + var ref2 = _object_destructuring_empty(_step2.value); } } catch (err) { _didIteratorError2 = true; @@ -86,7 +86,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined; try { for(var _iterator3 = ns[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){ - var _step_value3 = _sliced_to_array(_step3.value, 0); + var _step_value = _sliced_to_array(_step3.value, 0); } } catch (err) { _didIteratorError3 = true; @@ -105,7 +105,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = undefined; try { for(var _iterator4 = ns[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true){ - var _step_value4 = _sliced_to_array(_step4.value, 0); + var _step_value1 = _sliced_to_array(_step4.value, 0); } } catch (err) { _didIteratorError4 = true; @@ -124,7 +124,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion5 = true, _didIteratorError5 = false, _iteratorError5 = undefined; try { for(var _iterator5 = ns[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true){ - var _step_value5 = _sliced_to_array(_step5.value, 0); + var _step_value2 = _sliced_to_array(_step5.value, 0); } } catch (err) { _didIteratorError5 = true; diff --git a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.2.minified.js b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.2.minified.js index d93d48f581f7..06a8381e99b5 100644 --- a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5.2.minified.js @@ -1,26 +1,13 @@ //// [emptyVariableDeclarationBindingPatterns01_ES5.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; !function() { - var a, a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")), a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")), a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0), _sliced_to_array(a, 0), _sliced_to_array(a, 0); - var a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0); - var a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0); - var a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0); - var _a_p1 = a.p1, _a_p1 = null !== _a_p1 ? _a_p1 : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a.p2, 0); - var _a_p11 = a.p1, _a_p11 = null !== _a_p11 ? _a_p11 : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a.p2, 0); - var _a_p12 = a.p1, _a_p12 = null !== _a_p12 ? _a_p12 : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a.p2, 0); - var _ref = {}, _ref = null !== _ref ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = {}, _ref1 = null !== _ref1 ? _ref1 : _throw(new TypeError("Cannot destructure undefined")); + var a; + _object_destructuring_empty(a), _object_destructuring_empty(a), _object_destructuring_empty(a), _sliced_to_array(a, 0), _sliced_to_array(a, 0), _sliced_to_array(a, 0), _object_destructuring_empty(a), _sliced_to_array(a, 0), _object_destructuring_empty(a), _sliced_to_array(a, 0), _object_destructuring_empty(a), _sliced_to_array(a, 0), _object_destructuring_empty(a.p1), _sliced_to_array(a.p2, 0), _object_destructuring_empty(a.p1), _sliced_to_array(a.p2, 0), _object_destructuring_empty(a.p1), _sliced_to_array(a.p2, 0), _object_destructuring_empty({}), _object_destructuring_empty({}); }(), function() { var ns = [], _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; try { - for(var _step, _iterator = ns[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)var _step_value = _step.value, _step_value = null !== _step_value ? _step_value : _throw(new TypeError("Cannot destructure undefined")); + for(var _step, _iterator = ns[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)_object_destructuring_empty(_step.value); } catch (err) { _didIteratorError = !0, _iteratorError = err; } finally{ @@ -32,7 +19,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; } var _iteratorNormalCompletion1 = !0, _didIteratorError1 = !1, _iteratorError1 = void 0; try { - for(var _step1, _iterator1 = ns[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0)var _step_value1 = _step1.value, _step_value1 = null !== _step_value1 ? _step_value1 : _throw(new TypeError("Cannot destructure undefined")); + for(var _step1, _iterator1 = ns[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0)_object_destructuring_empty(_step1.value); } catch (err) { _didIteratorError1 = !0, _iteratorError1 = err; } finally{ @@ -44,7 +31,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; } var _iteratorNormalCompletion2 = !0, _didIteratorError2 = !1, _iteratorError2 = void 0; try { - for(var _step2, _iterator2 = ns[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0)var _step_value2 = _step2.value, _step_value2 = null !== _step_value2 ? _step_value2 : _throw(new TypeError("Cannot destructure undefined")); + for(var _step2, _iterator2 = ns[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0)_object_destructuring_empty(_step2.value); } catch (err) { _didIteratorError2 = !0, _iteratorError2 = err; } finally{ diff --git a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.1.normal.js b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.1.normal.js index 44d3b55ea482..2f5a32208c4a 100644 --- a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.1.normal.js +++ b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.1.normal.js @@ -1,35 +1,35 @@ //// [emptyVariableDeclarationBindingPatterns01_ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; (function() { var f = function f() { - var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref2.p, _ref3 = tmp === void 0 ? a : tmp, _ref3 = _ref3 !== null ? _ref3 : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a), _ref = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref1 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref1.p, ref1 = _object_destructuring_empty(tmp === void 0 ? a : tmp); return function() { - var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref2.p, _ref3 = tmp === void 0 ? a : tmp, _ref3 = _ref3 !== null ? _ref3 : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : a), _ref = _sliced_to_array(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : a, 0), _ref1 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : a, tmp = _ref1.p, ref1 = _object_destructuring_empty(tmp === void 0 ? a : tmp); return a; }; }; var a; - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(a); + var ref1 = _object_destructuring_empty(a); + var ref2 = _object_destructuring_empty(a); var _a = _sliced_to_array(a, 0); var _a1 = _sliced_to_array(a, 0); var _a2 = _sliced_to_array(a, 0); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")), _a3 = _sliced_to_array(a, 0); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")), _a4 = _sliced_to_array(a, 0); - var a = a !== null ? a : _throw(new TypeError("Cannot destructure undefined")), _a5 = _sliced_to_array(a, 0); - var _a_p1 = a.p1, _a_p1 = _a_p1 !== null ? _a_p1 : _throw(new TypeError("Cannot destructure undefined")), _a_p2 = _sliced_to_array(a.p2, 0); - var _a_p11 = a.p1, _a_p11 = _a_p11 !== null ? _a_p11 : _throw(new TypeError("Cannot destructure undefined")), _a_p21 = _sliced_to_array(a.p2, 0); - var _a_p12 = a.p1, _a_p12 = _a_p12 !== null ? _a_p12 : _throw(new TypeError("Cannot destructure undefined")), _a_p22 = _sliced_to_array(a.p2, 0); - for(var _ref = {}, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = {}, _ref1 = _ref1 !== null ? _ref1 : _throw(new TypeError("Cannot destructure undefined")); false; void 0){} + var ref3 = _object_destructuring_empty(a), _a3 = _sliced_to_array(a, 0); + var ref4 = _object_destructuring_empty(a), _a4 = _sliced_to_array(a, 0); + var ref5 = _object_destructuring_empty(a), _a5 = _sliced_to_array(a, 0); + var ref6 = _object_destructuring_empty(a.p1), _a_p2 = _sliced_to_array(a.p2, 0); + var ref7 = _object_destructuring_empty(a.p1), _a_p21 = _sliced_to_array(a.p2, 0); + var ref8 = _object_destructuring_empty(a.p1), _a_p22 = _sliced_to_array(a.p2, 0); + for(var ref9 = _object_destructuring_empty({}), ref10 = _object_destructuring_empty({}); false; void 0){} })(); (function() { var ns = []; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { for(var _iterator = ns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ - var _step_value = _step.value, _step_value = _step_value !== null ? _step_value : _throw(new TypeError("Cannot destructure undefined")); + var ref = _object_destructuring_empty(_step.value); } } catch (err) { _didIteratorError = true; @@ -48,7 +48,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined; try { for(var _iterator1 = ns[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){ - var _step_value1 = _step1.value, _step_value1 = _step_value1 !== null ? _step_value1 : _throw(new TypeError("Cannot destructure undefined")); + var ref1 = _object_destructuring_empty(_step1.value); } } catch (err) { _didIteratorError1 = true; @@ -67,7 +67,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined; try { for(var _iterator2 = ns[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){ - var _step_value2 = _step2.value, _step_value2 = _step_value2 !== null ? _step_value2 : _throw(new TypeError("Cannot destructure undefined")); + var ref2 = _object_destructuring_empty(_step2.value); } } catch (err) { _didIteratorError2 = true; @@ -86,7 +86,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined; try { for(var _iterator3 = ns[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){ - var _step_value3 = _sliced_to_array(_step3.value, 0); + var _step_value = _sliced_to_array(_step3.value, 0); } } catch (err) { _didIteratorError3 = true; @@ -105,7 +105,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = undefined; try { for(var _iterator4 = ns[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true){ - var _step_value4 = _sliced_to_array(_step4.value, 0); + var _step_value1 = _sliced_to_array(_step4.value, 0); } } catch (err) { _didIteratorError4 = true; @@ -124,7 +124,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; var _iteratorNormalCompletion5 = true, _didIteratorError5 = false, _iteratorError5 = undefined; try { for(var _iterator5 = ns[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true){ - var _step_value5 = _sliced_to_array(_step5.value, 0); + var _step_value2 = _sliced_to_array(_step5.value, 0); } } catch (err) { _didIteratorError5 = true; diff --git a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.2.minified.js b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.2.minified.js index 6d9e3dcb8d1d..dc7a73af3699 100644 --- a/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.2.minified.js +++ b/crates/swc/tests/tsc-references/emptyVariableDeclarationBindingPatterns01_ES5iterable.2.minified.js @@ -1,26 +1,13 @@ //// [emptyVariableDeclarationBindingPatterns01_ES5iterable.ts] +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; -import _throw from "@swc/helpers/src/_throw.mjs"; !function() { - var a, a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")), a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")), a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0), _sliced_to_array(a, 0), _sliced_to_array(a, 0); - var a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0); - var a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0); - var a = null !== a ? a : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a, 0); - var _a_p1 = a.p1, _a_p1 = null !== _a_p1 ? _a_p1 : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a.p2, 0); - var _a_p11 = a.p1, _a_p11 = null !== _a_p11 ? _a_p11 : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a.p2, 0); - var _a_p12 = a.p1, _a_p12 = null !== _a_p12 ? _a_p12 : _throw(new TypeError("Cannot destructure undefined")); - _sliced_to_array(a.p2, 0); - var _ref = {}, _ref = null !== _ref ? _ref : _throw(new TypeError("Cannot destructure undefined")), _ref1 = {}, _ref1 = null !== _ref1 ? _ref1 : _throw(new TypeError("Cannot destructure undefined")); + var a; + _object_destructuring_empty(a), _object_destructuring_empty(a), _object_destructuring_empty(a), _sliced_to_array(a, 0), _sliced_to_array(a, 0), _sliced_to_array(a, 0), _object_destructuring_empty(a), _sliced_to_array(a, 0), _object_destructuring_empty(a), _sliced_to_array(a, 0), _object_destructuring_empty(a), _sliced_to_array(a, 0), _object_destructuring_empty(a.p1), _sliced_to_array(a.p2, 0), _object_destructuring_empty(a.p1), _sliced_to_array(a.p2, 0), _object_destructuring_empty(a.p1), _sliced_to_array(a.p2, 0), _object_destructuring_empty({}), _object_destructuring_empty({}); }(), function() { var ns = [], _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; try { - for(var _step, _iterator = ns[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)var _step_value = _step.value, _step_value = null !== _step_value ? _step_value : _throw(new TypeError("Cannot destructure undefined")); + for(var _step, _iterator = ns[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)_object_destructuring_empty(_step.value); } catch (err) { _didIteratorError = !0, _iteratorError = err; } finally{ @@ -32,7 +19,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; } var _iteratorNormalCompletion1 = !0, _didIteratorError1 = !1, _iteratorError1 = void 0; try { - for(var _step1, _iterator1 = ns[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0)var _step_value1 = _step1.value, _step_value1 = null !== _step_value1 ? _step_value1 : _throw(new TypeError("Cannot destructure undefined")); + for(var _step1, _iterator1 = ns[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0)_object_destructuring_empty(_step1.value); } catch (err) { _didIteratorError1 = !0, _iteratorError1 = err; } finally{ @@ -44,7 +31,7 @@ import _throw from "@swc/helpers/src/_throw.mjs"; } var _iteratorNormalCompletion2 = !0, _didIteratorError2 = !1, _iteratorError2 = void 0; try { - for(var _step2, _iterator2 = ns[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0)var _step_value2 = _step2.value, _step_value2 = null !== _step_value2 ? _step_value2 : _throw(new TypeError("Cannot destructure undefined")); + for(var _step2, _iterator2 = ns[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0)_object_destructuring_empty(_step2.value); } catch (err) { _didIteratorError2 = !0, _iteratorError2 = err; } finally{ diff --git a/crates/swc/tests/tsc-references/genericObjectRest.1.normal.js b/crates/swc/tests/tsc-references/genericObjectRest.1.normal.js index da0320afb74b..c71d03cfd792 100644 --- a/crates/swc/tests/tsc-references/genericObjectRest.1.normal.js +++ b/crates/swc/tests/tsc-references/genericObjectRest.1.normal.js @@ -1,10 +1,11 @@ //// [genericObjectRest.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; const a = 'a'; function f1(obj) { - let r0 = _extends({}, obj); + let r0 = _extends({}, _object_destructuring_empty(obj)); let { a: a1 } = obj, r1 = _object_without_properties(obj, [ "a" ]); diff --git a/crates/swc/tests/tsc-references/missingAndExcessProperties.1.normal.js b/crates/swc/tests/tsc-references/missingAndExcessProperties.1.normal.js index dd8a1df37a6b..c8ca61efa501 100644 --- a/crates/swc/tests/tsc-references/missingAndExcessProperties.1.normal.js +++ b/crates/swc/tests/tsc-references/missingAndExcessProperties.1.normal.js @@ -1,6 +1,6 @@ //// [missingAndExcessProperties.ts] // Missing properties -import _throw from "@swc/helpers/src/_throw.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; function f1() { var _ref = {}, x = _ref.x, y = _ref.y; var _ref1 = {}, _ref_x = _ref1.x, x = _ref_x === void 0 ? 1 : _ref_x, y = _ref1.y; @@ -21,10 +21,10 @@ function f2() { } // Excess properties function f3() { - var _ref = { + var ref = _object_destructuring_empty({ x: 0, y: 0 - }, _ref = _ref !== null ? _ref : _throw(new TypeError("Cannot destructure undefined")); + }); var x = { x: 0, y: 0 @@ -33,19 +33,18 @@ function f3() { x: 0, y: 0 }.y; - var _ref1 = { + var _ref = { x: 0, y: 0 - }, x = _ref1.x, y = _ref1.y; + }, x = _ref.x, y = _ref.y; } // Excess properties function f4() { var x, y; - var ref; - ref = { + _object_destructuring_empty({ x: 0, y: 0 - }, ref; + }); x = ({ x: 0, y: 0 @@ -54,9 +53,9 @@ function f4() { x: 0, y: 0 }).y; - var ref1; - ref1 = { + var ref; + ref = { x: 0, y: 0 - }, x = ref1.x, y = ref1.y, ref1; + }, x = ref.x, y = ref.y, ref; } diff --git a/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.1.normal.js b/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.1.normal.js index b2349d417338..c65f8aab33f5 100644 --- a/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.1.normal.js +++ b/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.1.normal.js @@ -1,5 +1,6 @@ //// [noUncheckedIndexedAccessDestructuring.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; import _to_array from "@swc/helpers/src/_to_array.mjs"; @@ -15,7 +16,7 @@ var _strArray2 = _to_array(strArray), s3 = _strArray2.slice(2); s3.push(undefined); // Should error, 'undefined' not part of s2's element type var t1 = strMap.t1; t1.toString(); // Should error, t1 possibly undefined -var t2 = _extends({}, strMap); +var t2 = _extends({}, _object_destructuring_empty(strMap)); t2.z.toString(); // Should error { var x = numMapPoint.x, y = numMapPoint.y, z = numMapPoint.z; diff --git a/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.2.minified.js b/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.2.minified.js index 06faa12d4a2f..7f5c1a0b249e 100644 --- a/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.2.minified.js +++ b/crates/swc/tests/tsc-references/noUncheckedIndexedAccessDestructuring.2.minified.js @@ -1,9 +1,10 @@ //// [noUncheckedIndexedAccessDestructuring.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs"; import _to_array from "@swc/helpers/src/_to_array.mjs"; -_sliced_to_array(strArray, 1)[0].toString(), _to_array(strArray).slice(0).push(void 0), _to_array(strArray).slice(2).push(void 0), strMap.t1.toString(), _extends({}, strMap).z.toString(); +_sliced_to_array(strArray, 1)[0].toString(), _to_array(strArray).slice(0).push(void 0), _to_array(strArray).slice(2).push(void 0), strMap.t1.toString(), _extends({}, _object_destructuring_empty(strMap)).z.toString(); var ref, x = numMapPoint.x, y = numMapPoint.y, z = numMapPoint.z; x.toFixed(), y.toFixed(), z.toFixed(); var x1 = numMapPoint.x, q = _object_without_properties(numMapPoint, [ diff --git a/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.1.normal.js b/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.1.normal.js index 320cd3c6b767..243906b3a994 100644 --- a/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.1.normal.js +++ b/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.1.normal.js @@ -1,7 +1,8 @@ //// [nonPrimitiveAccessProperty.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; var a; a.toString(); a.nonExist(); // error var destructuring = a.destructuring; // error -var rest = _extends({}, a); // ok +var rest = _extends({}, _object_destructuring_empty(a)); // ok diff --git a/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.2.minified.js b/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.2.minified.js index b2062e141ce5..a278d6bd80b5 100644 --- a/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.2.minified.js +++ b/crates/swc/tests/tsc-references/nonPrimitiveAccessProperty.2.minified.js @@ -1,4 +1,5 @@ //// [nonPrimitiveAccessProperty.ts] var a; import _extends from "@swc/helpers/src/_extends.mjs"; -a.toString(), a.nonExist(), a.destructuring, _extends({}, a); +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; +a.toString(), a.nonExist(), a.destructuring, _extends({}, _object_destructuring_empty(a)); diff --git a/crates/swc/tests/tsc-references/objectRest.1.normal.js b/crates/swc/tests/tsc-references/objectRest.1.normal.js index e090e4ff6baf..e0bc31bb141e 100644 --- a/crates/swc/tests/tsc-references/objectRest.1.normal.js +++ b/crates/swc/tests/tsc-references/objectRest.1.normal.js @@ -1,12 +1,13 @@ //// [objectRest.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; var o = { a: 1, b: 'no' }; -var clone = _extends({}, o); +var clone = _extends({}, _object_destructuring_empty(o)); var { a } = o, justB = _object_without_properties(o, [ "a" ]); @@ -31,7 +32,7 @@ var { d: renamed } = o2, d = _object_without_properties(o2, [ "d" ]); let nestedrest; -var { x , n1: { y , n2: { z } } } = nestedrest, nr = _extends({}, nestedrest.n1.n2.n3), restrest = _object_without_properties(nestedrest, [ +var { x , n1: { y , n2: { z } } } = nestedrest, nr = _extends({}, _object_destructuring_empty(nestedrest.n1.n2.n3)), restrest = _object_without_properties(nestedrest, [ "x", "n1" ]); diff --git a/crates/swc/tests/tsc-references/objectRest.2.minified.js b/crates/swc/tests/tsc-references/objectRest.2.minified.js index aaa082c83510..7f18fa47bcd8 100644 --- a/crates/swc/tests/tsc-references/objectRest.2.minified.js +++ b/crates/swc/tests/tsc-references/objectRest.2.minified.js @@ -1,13 +1,14 @@ //// [objectRest.ts] let nestedrest, complex; import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; import _to_property_key from "@swc/helpers/src/_to_property_key.mjs"; var _tmp, _o, o = { a: 1, b: 'no' }; -_extends({}, o); +_extends({}, _object_destructuring_empty(o)); var { a } = o; _object_without_properties(o, [ "a" @@ -33,7 +34,7 @@ _object_without_properties(o2, [ "d" ]); var { x , n1: { y , n2: { z } } } = nestedrest; -_extends({}, nestedrest.n1.n2.n3), _object_without_properties(nestedrest, [ +_extends({}, _object_destructuring_empty(nestedrest.n1.n2.n3)), _object_without_properties(nestedrest, [ "x", "n1" ]); diff --git a/crates/swc/tests/tsc-references/objectRestAssignment.1.normal.js b/crates/swc/tests/tsc-references/objectRestAssignment.1.normal.js index 575a08e0a655..3ce54873f8db 100644 --- a/crates/swc/tests/tsc-references/objectRestAssignment.1.normal.js +++ b/crates/swc/tests/tsc-references/objectRestAssignment.1.normal.js @@ -1,5 +1,6 @@ //// [objectRestAssignment.ts] import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; let ka; let nested; @@ -16,14 +17,14 @@ _complex = complex, nested = _object_without_properties(_complex.x, [ // should be: let overEmit; // var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); -var { a: [{}, ...y] , b: { z } } = overEmit, nested2 = _extends({}, overEmit.a[0]), c = _object_without_properties(overEmit.b, [ +var { a: [{}, ...y] , b: { z } } = overEmit, nested2 = _extends({}, _object_destructuring_empty(overEmit.a[0])), c = _object_without_properties(overEmit.b, [ "z" ]), rest2 = _object_without_properties(overEmit, [ "a", "b" ]); var _overEmit; -_overEmit = overEmit, nested2 = _extends({}, _overEmit.a[0]), c = _object_without_properties(_overEmit.b, [ +_overEmit = overEmit, nested2 = _extends({}, _object_destructuring_empty(_overEmit.a[0])), c = _object_without_properties(_overEmit.b, [ "z" ]), rest2 = _object_without_properties(_overEmit, [ "a", diff --git a/crates/swc/tests/tsc-references/objectRestAssignment.2.minified.js b/crates/swc/tests/tsc-references/objectRestAssignment.2.minified.js index 14fb77a837d9..08604c80a671 100644 --- a/crates/swc/tests/tsc-references/objectRestAssignment.2.minified.js +++ b/crates/swc/tests/tsc-references/objectRestAssignment.2.minified.js @@ -1,6 +1,7 @@ //// [objectRestAssignment.ts] let ka, other, complex, overEmit; import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs"; _object_without_properties(complex.x, [ "ka" @@ -9,12 +10,12 @@ _object_without_properties(complex.x, [ "y" ]), { x: { ka } , y: other } = complex; var { a: [{}, ...y] , b: { z } } = overEmit; -_extends({}, overEmit.a[0]), _object_without_properties(overEmit.b, [ +_extends({}, _object_destructuring_empty(overEmit.a[0])), _object_without_properties(overEmit.b, [ "z" ]), _object_without_properties(overEmit, [ "a", "b" -]), _extends({}, overEmit.a[0]), _object_without_properties(overEmit.b, [ +]), _extends({}, _object_destructuring_empty(overEmit.a[0])), _object_without_properties(overEmit.b, [ "z" ]), _object_without_properties(overEmit, [ "a", diff --git a/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js b/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js index caa99bbef9bc..a95b8ec3f968 100644 --- a/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameAndObjectRestSpread.1.normal.js @@ -3,17 +3,18 @@ import _class_private_field_get from "@swc/helpers/src/_class_private_field_get. import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; import _class_static_private_field_spec_get from "@swc/helpers/src/_class_static_private_field_spec_get.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_spread from "@swc/helpers/src/_object_spread.mjs"; var _prop = /*#__PURE__*/ new WeakMap(); class C { method(other) { const obj = _object_spread({}, other); _class_private_field_get(obj, _prop); - const rest = _extends({}, other); + const rest = _extends({}, _object_destructuring_empty(other)); _class_private_field_get(rest, _prop); const statics = _object_spread({}, C); _class_static_private_field_spec_get(statics, C, _propStatic); - const sRest = _extends({}, C); + const sRest = _extends({}, _object_destructuring_empty(C)); _class_static_private_field_spec_get(sRest, C, _propStatic); } constructor(){ diff --git a/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.1.normal.js b/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.1.normal.js index a4572599ed9a..f87567d1d0f5 100644 --- a/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.1.normal.js +++ b/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.1.normal.js @@ -2,6 +2,7 @@ import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _write_only_error from "@swc/helpers/src/_write_only_error.mjs"; import _class_private_field_destructure from "@swc/helpers/src/_class_private_field_destructure.mjs"; var _value = /*#__PURE__*/ new WeakMap(), _valueRest = /*#__PURE__*/ new WeakMap(), _valueOne = /*#__PURE__*/ new WeakMap(), _valueCompound = /*#__PURE__*/ new WeakMap(); @@ -26,14 +27,14 @@ class Test { var _tmp; _tmp = { foo - }, _class_private_field_destructure(this, _value).value = _extends({}, _tmp), _tmp; //ok + }, _class_private_field_destructure(this, _value).value = _extends({}, _object_destructuring_empty(_tmp)), _tmp; //ok ({ foo: (this, _write_only_error("#value")).foo } = { foo }); //error var _tmp1; _tmp1 = { foo - }, (this, _write_only_error("#value")).foo = _extends({}, _tmp1.foo), ({ foo: {} } = _tmp1), _tmp1; //error + }, (this, _write_only_error("#value")).foo = _extends({}, _object_destructuring_empty(_tmp1.foo)), ({ foo: {} } = _tmp1), _tmp1; //error let r = { o: (this, _write_only_error("#value")) }; //error diff --git a/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.2.minified.js b/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.2.minified.js index fff31b512d9a..62142f03dd77 100644 --- a/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.2.minified.js +++ b/crates/swc/tests/tsc-references/privateWriteOnlyAccessorRead.2.minified.js @@ -2,6 +2,7 @@ import _class_private_field_init from "@swc/helpers/src/_class_private_field_init.mjs"; import _class_private_field_set from "@swc/helpers/src/_class_private_field_set.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _write_only_error from "@swc/helpers/src/_write_only_error.mjs"; import _class_private_field_destructure from "@swc/helpers/src/_class_private_field_destructure.mjs"; var _value = new WeakMap(), _valueRest = new WeakMap(), _valueOne = new WeakMap(), _valueCompound = new WeakMap(); @@ -22,13 +23,13 @@ new class { o: { foo } - }), _class_private_field_destructure(this, _value).value = _extends({}, { + }), _class_private_field_destructure(this, _value).value = _extends({}, _object_destructuring_empty({ foo - }), ({ foo: _write_only_error("#value").foo } = { + })), ({ foo: _write_only_error("#value").foo } = { foo - }), _write_only_error("#value").foo = _extends({}, { + }), _write_only_error("#value").foo = _extends({}, _object_destructuring_empty({ foo - }.foo), _write_only_error("#value"), [_class_private_field_destructure(this, _valueOne).value, ..._class_private_field_destructure(this, _valueRest).value] = [ + }.foo)), _write_only_error("#value"), [_class_private_field_destructure(this, _valueOne).value, ..._class_private_field_destructure(this, _valueRest).value] = [ 1, 2, 3 diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js index 6a45eef0dd1f..b3df98e4d699 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).1.normal.js @@ -3,6 +3,7 @@ import _define_property from "@swc/helpers/src/_define_property.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _set from "@swc/helpers/src/_set.mjs"; import _update from "@swc/helpers/src/_update.mjs"; class C extends B { @@ -47,7 +48,7 @@ _define_property(C, "z12", { x: _update(_get_prototype_of(C), "a", C, true)._ = var _tmp; _define_property(C, "z13", (_tmp = { x: 0 -}, _update(_get_prototype_of(C), "a", C, true)._ = _extends({}, _tmp), _tmp)); +}, _update(_get_prototype_of(C), "a", C, true)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp)); _define_property(C, "z14", ++_update(_get_prototype_of(C), "a", C, true)._); _define_property(C, "z15", --_update(_get_prototype_of(C), "a", C, true)._); _define_property(C, "z16", ++_update(_get_prototype_of(C), "a", C, true)._); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).2.minified.js index e2fe8f9c5160..f6a5a06ccba2 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1(target=es2015).2.minified.js @@ -4,6 +4,7 @@ import _define_property from "@swc/helpers/src/_define_property.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _set from "@swc/helpers/src/_set.mjs"; import _update from "@swc/helpers/src/_update.mjs"; class C extends B { @@ -23,4 +24,4 @@ _define_property(C, "x", void 0), _define_property(C, "y1", C.x), _define_proper x: 0 }), _define_property(C, "z13", (_tmp = { x: 0 -}, _update(_get_prototype_of(C), "a", C, !0)._ = _extends({}, _tmp), _tmp)), _define_property(C, "z14", ++_update(_get_prototype_of(C), "a", C, !0)._), _define_property(C, "z15", --_update(_get_prototype_of(C), "a", C, !0)._), _define_property(C, "z16", ++_update(_get_prototype_of(C), "a", C, !0)._), _define_property(C, "z17", _update(_get_prototype_of(C), "a", C, !0)._++), _define_property(C, "z18", _get(_get_prototype_of(C), "a", C)``); +}, _update(_get_prototype_of(C), "a", C, !0)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp)), _define_property(C, "z14", ++_update(_get_prototype_of(C), "a", C, !0)._), _define_property(C, "z15", --_update(_get_prototype_of(C), "a", C, !0)._), _define_property(C, "z16", ++_update(_get_prototype_of(C), "a", C, !0)._), _define_property(C, "z17", _update(_get_prototype_of(C), "a", C, !0)._++), _define_property(C, "z18", _get(_get_prototype_of(C), "a", C)``); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js index 041a1b8383a9..fd4ca3f03588 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).1.normal.js @@ -2,6 +2,7 @@ import _extends from "@swc/helpers/src/_extends.mjs"; import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _set from "@swc/helpers/src/_set.mjs"; import _update from "@swc/helpers/src/_update.mjs"; class C extends B { @@ -46,7 +47,7 @@ C.z12 = { x: _update(_get_prototype_of(C), "a", C, true)._ = 0 } = { var _tmp; C.z13 = (_tmp = { x: 0 -}, _update(_get_prototype_of(C), "a", C, true)._ = _extends({}, _tmp), _tmp); +}, _update(_get_prototype_of(C), "a", C, true)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp); C.z14 = ++_update(_get_prototype_of(C), "a", C, true)._; C.z15 = --_update(_get_prototype_of(C), "a", C, true)._; C.z16 = ++_update(_get_prototype_of(C), "a", C, true)._; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js index 9cbef59e4df0..44088d244164 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2(target=es2015).2.minified.js @@ -3,6 +3,7 @@ var _tmp; import _extends from "@swc/helpers/src/_extends.mjs"; import _get from "@swc/helpers/src/_get.mjs"; import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _set from "@swc/helpers/src/_set.mjs"; import _update from "@swc/helpers/src/_update.mjs"; class C extends B { @@ -22,4 +23,4 @@ C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 x: 0 }, C.z13 = (_tmp = { x: 0 -}, _update(_get_prototype_of(C), "a", C, !0)._ = _extends({}, _tmp), _tmp), C.z14 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z15 = --_update(_get_prototype_of(C), "a", C, !0)._, C.z16 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z17 = _update(_get_prototype_of(C), "a", C, !0)._++, C.z18 = _get(_get_prototype_of(C), "a", C)``; +}, _update(_get_prototype_of(C), "a", C, !0)._ = _extends({}, _object_destructuring_empty(_tmp)), _tmp), C.z14 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z15 = --_update(_get_prototype_of(C), "a", C, !0)._, C.z16 = ++_update(_get_prototype_of(C), "a", C, !0)._, C.z17 = _update(_get_prototype_of(C), "a", C, !0)._++, C.z18 = _get(_get_prototype_of(C), "a", C)``; diff --git a/crates/swc/tests/tsc-references/unknownType1.1.normal.js b/crates/swc/tests/tsc-references/unknownType1.1.normal.js index d35748420f51..187d3cbdea1f 100644 --- a/crates/swc/tests/tsc-references/unknownType1.1.normal.js +++ b/crates/swc/tests/tsc-references/unknownType1.1.normal.js @@ -3,6 +3,7 @@ import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; import _extends from "@swc/helpers/src/_extends.mjs"; import _instanceof from "@swc/helpers/src/_instanceof.mjs"; +import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs"; import _object_spread from "@swc/helpers/src/_object_spread.mjs"; // Only equality operators are allowed with unknown function f10(x) { @@ -102,7 +103,7 @@ function f26(x, y, z) { function f27() {} // Rest type cannot be created from unknown function f28(x) { - var a = _extends({}, x); // Error + var a = _extends({}, _object_destructuring_empty(x)); // Error } // Class properties of type unknown don't need definite assignment var C1 = function C1() { diff --git a/crates/swc_ecma_transforms_base/src/helpers/_object_destructuring_empty.js b/crates/swc_ecma_transforms_base/src/helpers/_object_destructuring_empty.js new file mode 100644 index 000000000000..8d3d9c44f806 --- /dev/null +++ b/crates/swc_ecma_transforms_base/src/helpers/_object_destructuring_empty.js @@ -0,0 +1,4 @@ +function _objectDestructuringEmpty(o) { + if (o === null || o === void 0) throw new TypeError("Cannot destructure " + o); + return o; +} diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 4a31fe7bc449..2ef7ff3e0bcd 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -283,6 +283,7 @@ define_helpers!(Helpers { new_arrow_check: (), non_iterable_rest: (), non_iterable_spread: (), + object_destructuring_empty: (), object_spread: (define_property), object_spread_props: (), object_without_properties: (object_without_properties_loose), diff --git a/crates/swc_ecma_transforms_compat/src/es2015/destructuring.rs b/crates/swc_ecma_transforms_compat/src/es2015/destructuring.rs index 1a6b5feff40b..94ffea94ac69 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/destructuring.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/destructuring.rs @@ -4,7 +4,7 @@ use serde::Deserialize; use swc_atoms::js_word; use swc_common::{util::take::Take, Spanned, SyntaxContext, 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::{ alias_ident_for, alias_if_required, has_rest_pat, is_literal, member_expr, private_ident, @@ -275,16 +275,6 @@ impl AssignFolder { } } Pat::Object(ObjectPat { span, props, .. }) if props.is_empty() => { - let (ident, aliased) = alias_if_required(decl.init.as_ref().unwrap(), "ref"); - if aliased { - decls.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: decl.init, - definite: false, - }); - } - // We should convert // // var {} = null; @@ -294,39 +284,24 @@ impl AssignFolder { // var _ref = null; // _objectDestructuringEmpty(_ref); // - decls.push(VarDeclarator { - span, - name: ident.clone().into(), - init: Some(Box::new(Expr::Cond(CondExpr { - span: DUMMY_SP, - test: Box::new(Expr::Bin(BinExpr { - span: DUMMY_SP, - left: Box::new(Expr::Ident(ident.clone())), - op: op!("!=="), - right: Null { span: DUMMY_SP }.into(), - })), - cons: Box::new(Expr::Ident(ident)), - alt: Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: helper!(throw, "throw"), - args: vec![ - // new TypeError("Cannot destructure undefined") - NewExpr { - span: DUMMY_SP, - callee: Box::new(Expr::Ident(Ident::new( - "TypeError".into(), - DUMMY_SP, - ))), - args: Some(vec!["Cannot destructure undefined".as_arg()]), - type_args: Default::default(), - } - .as_arg(), - ], - type_args: Default::default(), - })), - }))), + + let expr = helper_expr!(object_destructuring_empty, "objectDestructuringEmpty") + .as_call( + DUMMY_SP, + vec![decl + .init + .expect("destructuring must be initialized") + .as_arg()], + ); + + let var_decl = VarDeclarator { + span: DUMMY_SP, + name: private_ident!(span, "ref").into(), + init: Some(Box::new(expr)), definite: false, - }) + }; + + decls.push(var_decl); } Pat::Object(ObjectPat { props, .. }) => { @@ -806,6 +781,13 @@ impl VisitMut for AssignFolder { exprs, }) } + Pat::Object(ObjectPat { props, .. }) if props.is_empty() => { + let mut right = right.take(); + right.visit_mut_with(self); + + *expr = helper_expr!(object_destructuring_empty, "objectDestructuringEmpty") + .as_call(DUMMY_SP, vec![right.as_arg()]); + } Pat::Object(ObjectPat { span, props, .. }) => { if props.len() == 1 { if let ObjectPatProp::Assign(p @ AssignPatProp { value: None, .. }) = diff --git a/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs b/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs index 112280dd9795..494c46acdaa0 100644 --- a/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/src/es2018/object_rest_spread.rs @@ -392,7 +392,12 @@ impl VisitMut for ObjectRest { props: vec![], } .as_arg(), - init.as_arg(), + helper_expr!( + object_destructuring_empty, + "objectDestructuringEmpty" + ) + .as_call(DUMMY_SP, vec![init.as_arg()]) + .as_arg(), ], type_args: Default::default(), }))), @@ -951,7 +956,9 @@ fn object_without_properties( props: vec![], } .as_arg(), - obj.as_arg(), + helper_expr!(object_destructuring_empty, "objectDestructuringEmpty") + .as_call(DUMMY_SP, vec![obj.as_arg()]) + .as_arg(), ], type_args: Default::default(), }); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs index 929cfa9a0e29..481e8d3b6e50 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs @@ -1114,7 +1114,7 @@ test_exec!( r#" expect(function () { var {} = null; -}).toThrow("Cannot destructure undefined"); +}).toThrow("Cannot destructure null"); "# ); @@ -1540,7 +1540,7 @@ var { [x]: x, ...y } = z; r#" var z = {}; var x = _extends({ -}, z); +}, _objectDestructuringEmpty(z)); var x = z.x, y = _objectWithoutProperties(z, ["x"]); var x = z[x], diff --git a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs index 55324ca2ae4a..4fcc9ae833dd 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs @@ -36,8 +36,7 @@ test!( }", "class Foo{ constructor(_param){ - var bar = _extends({ - }, _param); + var bar = _extends({}, _objectDestructuringEmpty(_param)); } }" ); @@ -102,7 +101,7 @@ function foo([{...bar}]) { "#, r#" function foo([_param]) { - var bar = _extends({}, _param); + var bar = _extends({}, _objectDestructuringEmpty(_param)); } "# @@ -193,7 +192,7 @@ try {} catch({ b }) {} try { } catch (_param) { var a34 = _extends({ - }, _param); + }, _objectDestructuringEmpty(_param)); } try { } catch (_param1) { @@ -500,13 +499,13 @@ var _tmp; const _ref = { }, _key = (_param)=>{ var rest = _extends({ - }, _param); + }, _objectDestructuringEmpty(_param)); let b = _extends({ - }, { - }); + }, _objectDestructuringEmpty({ + })); }, _key1 = (_tmp = { }, d = _extends({ -}, _tmp), _tmp), { [_key]: a , [_key1]: c } = _ref; +}, _objectDestructuringEmpty(_tmp)), _tmp), { [_key]: a , [_key1]: c } = _ref; "# ); @@ -523,7 +522,7 @@ const { }, c = ({ ...d } = {}), } = {}; -a() +a({}) expect(c).toEqual({}) expect(d).toEqual({}) "# @@ -546,13 +545,13 @@ var _tmp; const _ref = { }, { a =(_param)=>{ var rest = _extends({ - }, _param); + }, _objectDestructuringEmpty(_param)); let b = _extends({ - }, { - }); + }, _objectDestructuringEmpty({ + })); } , c =(_tmp = { }, d = _extends({ -}, _tmp), _tmp) } = _ref; +}, _objectDestructuringEmpty(_tmp)), _tmp) } = _ref; "# ); @@ -594,7 +593,7 @@ test!( const { a: { ...bar }, b: { ...baz }, ...foo } = obj; "#, r#" -const bar = _extends({}, obj.a), baz = _extends({}, obj.b), foo = +const bar = _extends({}, _objectDestructuringEmpty(obj.a)), baz = _extends({}, _objectDestructuringEmpty(obj.b)), foo = _objectWithoutProperties(obj, ["a", "b"]); "# ); @@ -835,7 +834,7 @@ function b3({ b }) {} "#, r#" function a(_param) { - var a34 = _extends({}, _param); + var a34 = _extends({}, _objectDestructuringEmpty(_param)); } function a2(_param) { @@ -887,7 +886,7 @@ function a7(_param = { function a8([_param]) { var a1 = _extends({ - }, _param); + }, _objectDestructuringEmpty(_param)); } function a9([_param]) { @@ -895,7 +894,7 @@ function a9([_param]) { } function a10([a1, _param]) { - var a2 = _extends({}, _param); + var a2 = _extends({}, _objectDestructuringEmpty(_param)); } // Unchanged @@ -996,15 +995,15 @@ const {w3, x3, y3, ...z4} = z; "#, r#" var z = {}; -var x = _extends({}, z); +var x = _extends({}, _objectDestructuringEmpty(z)); var a = _extends({ -}, { +}, _objectDestructuringEmpty({ a: 1 -}); +})); var x = _extends({ -}, a.b); +}, _objectDestructuringEmpty(a.b)); var x = _extends({ -}, a()); +}, _objectDestructuringEmpty(a())); var { x1 } = z, @@ -1051,7 +1050,7 @@ let { } } = complex, asdf = _objectWithoutProperties(complex.x, ["a", d].map(_toPropertyKey)), - d = _extends({}, complex.y), + d = _extends({}, _objectDestructuringEmpty(complex.y)), g = _objectWithoutProperties(complex, ["x", "y"]); "# ); @@ -1064,7 +1063,7 @@ test!( let { x4: { ...y4 } } = z; "#, r#" -let y4 = _extends({}, z.x4); +let y4 = _extends({}, _objectDestructuringEmpty(z.x4)); "# ); @@ -1656,7 +1655,7 @@ const { } = a, y = _objectWithoutProperties(a, ["x"]), z = foo(y); -const s = _extends({}, r), +const s = _extends({}, _objectDestructuringEmpty(r)), t = foo(s); // ordering is preserved var l = foo(), @@ -3046,7 +3045,7 @@ test!( var counter = 0; for (var _ref of [{ x: 1, y: 2 }]) { var _ref1; - _ref1 = _ref, src.y = _extends({}, _ref1), _ref1; + _ref1 = _ref, src.y = _extends({}, _objectDestructuringEmpty(_ref1)), _ref1; expect(src.y.x).toEqual(1); expect(src.y.y).toEqual(2); diff --git a/packages/swc-helpers/src/_object_destructuring_empty.mjs b/packages/swc-helpers/src/_object_destructuring_empty.mjs new file mode 100644 index 000000000000..1ae5cbb87f32 --- /dev/null +++ b/packages/swc-helpers/src/_object_destructuring_empty.mjs @@ -0,0 +1,4 @@ +export default function _objectDestructuringEmpty(o) { + if (o === null || o === void 0) throw new TypeError("Cannot destructure " + o); + return o; +}