Skip to content

Commit

Permalink
fix(es/compat): Add missing visit children for destructuring (#9658)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9647
  • Loading branch information
stormslowly authored Oct 18, 2024
1 parent 9c35520 commit 32116a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-hounds-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_compat_es2015: patch
swc_core: patch
---

fix: 🐛 add missing visit children in for stmt
22 changes: 22 additions & 0 deletions crates/swc_ecma_compat_es2015/src/destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct Config {
macro_rules! impl_for_for_stmt {
($name:ident, $T:tt) => {
fn $name(&mut self, for_stmt: &mut $T) {
for_stmt.visit_mut_children_with(self);

let (left, stmt) = match &mut for_stmt.left {
ForHead::VarDecl(var_decl) => {
let has_complex = var_decl.decls.iter().any(|d| match d.name {
Expand Down Expand Up @@ -1322,3 +1324,23 @@ impl Check for DestructuringVisitor {
self.found
}
}

#[cfg(test)]
mod tests {
use swc_ecma_transforms_testing::test;

use super::*;

test!(
::swc_ecma_parser::Syntax::default(),
|_| destructuring(Default::default()),
nested_for_of,
r#"
for (const [k1, v1] of Object.entries(o)){
for (const [k2, v2] of Object.entries(o)){
console.log(k1, v1, k2, v2);
}
}
"#
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
for (const ref of Object.entries(o)) {
let _ref = _sliced_to_array(ref, 2),
k1 = _ref[0],
v1 = _ref[1];
for (const ref of Object.entries(o)) {
let _ref = _sliced_to_array(ref, 2),
k2 = _ref[0],
v2 = _ref[1];
console.log(k1, v1, k2, v2);
}
}

0 comments on commit 32116a0

Please sign in to comment.