Skip to content

Commit 32116a0

Browse files
authored
fix(es/compat): Add missing visit children for destructuring (#9658)
**Related issue:** - Closes #9647
1 parent 9c35520 commit 32116a0

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

.changeset/nervous-hounds-kiss.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_compat_es2015: patch
3+
swc_core: patch
4+
---
5+
6+
fix: 🐛 add missing visit children in for stmt

crates/swc_ecma_compat_es2015/src/destructuring.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub struct Config {
5353
macro_rules! impl_for_for_stmt {
5454
($name:ident, $T:tt) => {
5555
fn $name(&mut self, for_stmt: &mut $T) {
56+
for_stmt.visit_mut_children_with(self);
57+
5658
let (left, stmt) = match &mut for_stmt.left {
5759
ForHead::VarDecl(var_decl) => {
5860
let has_complex = var_decl.decls.iter().any(|d| match d.name {
@@ -1322,3 +1324,23 @@ impl Check for DestructuringVisitor {
13221324
self.found
13231325
}
13241326
}
1327+
1328+
#[cfg(test)]
1329+
mod tests {
1330+
use swc_ecma_transforms_testing::test;
1331+
1332+
use super::*;
1333+
1334+
test!(
1335+
::swc_ecma_parser::Syntax::default(),
1336+
|_| destructuring(Default::default()),
1337+
nested_for_of,
1338+
r#"
1339+
for (const [k1, v1] of Object.entries(o)){
1340+
for (const [k2, v2] of Object.entries(o)){
1341+
console.log(k1, v1, k2, v2);
1342+
}
1343+
}
1344+
"#
1345+
);
1346+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
for (const ref of Object.entries(o)) {
2+
let _ref = _sliced_to_array(ref, 2),
3+
k1 = _ref[0],
4+
v1 = _ref[1];
5+
for (const ref of Object.entries(o)) {
6+
let _ref = _sliced_to_array(ref, 2),
7+
k2 = _ref[0],
8+
v2 = _ref[1];
9+
console.log(k1, v1, k2, v2);
10+
}
11+
}

0 commit comments

Comments
 (0)