Skip to content

Commit 24a72d7

Browse files
committed
fix(transformer/legacy-decorator): use write-only reference flag for computed key temp var assignment
1 parent f8fbd6e commit 24a72d7

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

  • crates/oxc_transformer/src/decorator/legacy
  • tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/computed-key-property-decorator-with-initializer

crates/oxc_transformer/src/decorator/legacy/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ impl<'a> LegacyDecorator<'a> {
11121112
// Create a unique binding for the computed property key, and insert it outside of the class
11131113
let binding = VarDeclarationsStore::create_uid_var_based_on_node(key, ctx);
11141114
let operator = AssignmentOperator::Assign;
1115-
let left = binding.create_read_write_target(ctx);
1115+
let left = binding.create_write_target(ctx);
11161116
let right = key.to_expression_mut().take_in(ctx.ast);
11171117
let key_expr = ctx.ast.expression_assignment(SPAN, operator, left, right);
11181118
*key = PropertyKey::from(key_expr);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const FIELD_NAME = "myField";
2+
3+
function dec(target: any, key: string) {}
4+
5+
class MyModel {
6+
@dec
7+
[FIELD_NAME] = "value";
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var _FIELD_NAME;
2+
const FIELD_NAME = "myField";
3+
function dec(target, key) {}
4+
class MyModel {
5+
[_FIELD_NAME = FIELD_NAME] = "value";
6+
}
7+
babelHelpers.decorate([dec], MyModel.prototype, _FIELD_NAME, void 0);

0 commit comments

Comments
 (0)