Skip to content

Commit

Permalink
Fix import usage tracking for destructure defaulting (#9842)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles authored Jul 11, 2024
1 parent 9100a49 commit 28a80f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/transformers/js/core/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ impl Visit for Collect {
.or_default()
.push(node.key.span);
}

node.value.visit_with(self);
}

fn visit_member_expr(&mut self, node: &MemberExpr) {
Expand Down
19 changes: 19 additions & 0 deletions packages/transformers/js/core/src/hoist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,25 @@ mod tests {
assert!(collect.static_cjs_exports);
}

#[test]
fn collect_destructure_default() {
let (collect, _code, _hoist) = parse(
r#"
import {bar} from 'source';
export function thing(props) {
const {something = bar} = props;
return something;
}
"#,
);
assert_eq_imports!(
collect.imports,
map! { w!("bar") => (w!("source"), w!("bar"), false) }
);
assert_eq_set!(collect.used_imports, set! { w!("bar") });
}

#[test]
fn collect_cjs_reassign() {
let (collect, _code, _hoist) = parse(
Expand Down

0 comments on commit 28a80f9

Please sign in to comment.