mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 10:12:42 +03:00
fix(es/compat): Fix variable scoping of object rest pass. (#7437)
**Related issue:** - Closes #6988.
This commit is contained in:
parent
c14306c914
commit
f3d660f972
@ -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"
|
||||
]);
|
||||
|
@ -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"
|
||||
]);
|
||||
[
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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) });
|
||||
}
|
||||
"###
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user