From 088dd481df6b9db0d2aee9f569a036d152476352 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sun, 15 Dec 2024 16:54:58 +0000 Subject: [PATCH] refactor(transformer/class-properties): shorten code (#7913) Use `SymbolTable::symbol_is_mutated`, rather than repeating the same logic. --- .../src/es2022/class_properties/computed_key.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties/computed_key.rs b/crates/oxc_transformer/src/es2022/class_properties/computed_key.rs index 4a82170557185..958ad310ea142 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/computed_key.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/computed_key.rs @@ -72,7 +72,7 @@ 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. @@ -80,14 +80,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // 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, } }