diff --git a/crates/swc/tests/fixture/issues-2xxx/2531/2/output/index.js b/crates/swc/tests/fixture/issues-2xxx/2531/2/output/index.js index 05686a71b32..d01012946ef 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2531/2/output/index.js +++ b/crates/swc/tests/fixture/issues-2xxx/2531/2/output/index.js @@ -1,7 +1,7 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties"; const items = []; for (const _ref of items){ - var item = _ref; + let item = _ref; const { name } = item, rest = _object_without_properties(item, [ "name" ]); diff --git a/crates/swc/tests/tsc-references/objectRestForOf.1.normal.js b/crates/swc/tests/tsc-references/objectRestForOf.1.normal.js index 21de3918b53..3c972760f37 100644 --- a/crates/swc/tests/tsc-references/objectRestForOf.1.normal.js +++ b/crates/swc/tests/tsc-references/objectRestForOf.1.normal.js @@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props"; import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties"; let array; for (let _ref of array){ - var { x } = _ref, restOf = _object_without_properties(_ref, [ + let { x } = _ref, restOf = _object_without_properties(_ref, [ "x" ]); [ diff --git a/crates/swc/tests/tsc-references/objectRestForOf.2.minified.js b/crates/swc/tests/tsc-references/objectRestForOf.2.minified.js index 7fb67cf05bc..6c40e47c84f 100644 --- a/crates/swc/tests/tsc-references/objectRestForOf.2.minified.js +++ b/crates/swc/tests/tsc-references/objectRestForOf.2.minified.js @@ -4,14 +4,17 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread"; import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props"; import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties"; for (let _ref of array){ - var _ref1, { x } = _ref; + let { x } = _ref; _object_without_properties(_ref, [ "x" ]); } -for (var _ref of array)_object_without_properties(_ref1 = _ref, [ - "x" -]), { x: xx } = _ref1; +for (var _ref of array){ + var _ref1; + _object_without_properties(_ref1 = _ref, [ + "x" + ]), { x: xx } = _ref1; +} for (let norest of array.map((a)=>_object_spread_props(_object_spread({}, a), { x: 'a string' })))norest.x, norest.y; 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 9dab742cf8c..c7f1371233d 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 @@ -87,7 +87,7 @@ macro_rules! impl_for_for_stmt { stmt = Some(Stmt::Decl( VarDecl { span: DUMMY_SP, - kind: VarDeclKind::Var, + kind: VarDeclKind::Let, decls, declare: false, } 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 2b9b3ad77b6..6d275e73dfc 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 @@ -5,7 +5,7 @@ use swc_ecma_transforms_compat::{ es2015::{self, spread}, es2018::{object_rest_spread, object_rest_spread::Config}, }; -use swc_ecma_transforms_testing::{test, test_exec}; +use swc_ecma_transforms_testing::{compare_stdout, test, test_exec}; use swc_ecma_visit::Fold; fn syntax() -> Syntax { @@ -269,7 +269,7 @@ async function a() { r#" // ForXStatement for (var _ref of []) { - var { + let { a } = _ref, b = _object_without_properties(_ref, ["a"]); @@ -3134,3 +3134,23 @@ test_exec!( thing({ queryKey: [{ url: 'https://www.google.com', id: '1' }] }) "# ); + +compare_stdout!( + syntax(), + |_| { + // + let unresolved_mark = Mark::new(); + let top_level_mark = Mark::new(); + chain!( + resolver(unresolved_mark, top_level_mark, false), + tr(Default::default()), + ) + }, + issue_6988_1, + r###" + for (const a of [1,2,3]) { + const { ...rest } = {}; + setTimeout(() => { console.log(a) }); + } + "### +);