Skip to content

Commit

Permalink
refactor(transformer/class-properties): shorten code (#7913)
Browse files Browse the repository at this point in the history
Use `SymbolTable::symbol_is_mutated`, rather than repeating the same logic.
  • Loading branch information
overlookmotel committed Dec 15, 2024
1 parent f4cb5d3 commit 088dd48
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,15 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
| Expression::StringLiteral(_) => true,
Expression::Identifier(ident) => {
// Cannot have side effects if is bound.
// Additional check that the var is not mutated is required for cases like
// Check that the var is not mutated is required for cases like
// `let x = 1; class { [x] = 1; [++x] = 2; }`
// `++x` is hoisted to before class in output, so `x` in 1st key would get the wrong
// value unless it's hoisted out too.
// TODO: Add an exec test for this odd case.
// TODO(improve-on-babel): That case is rare.
// Test for it in first pass over class elements, and avoid temp vars where possible.
match ctx.symbols().get_reference(ident.reference_id()).symbol_id() {
Some(symbol_id) => {
// TODO: Use `SymbolTable::symbol_is_mutated`
ctx.symbols().get_flags(symbol_id).contains(SymbolFlags::ConstVariable)
|| ctx
.symbols()
.get_resolved_references(symbol_id)
.all(|reference| !reference.is_write())
}
Some(symbol_id) => !ctx.symbols().symbol_is_mutated(symbol_id),
None => false,
}
}
Expand Down

0 comments on commit 088dd48

Please sign in to comment.