Skip to content

Commit

Permalink
fix(es/decorators): Handle ref of decorated class (#8905)
Browse files Browse the repository at this point in the history
**Related issue:**

Follow up #8515 

 - Ts Decorator does not always return a class; we need to give it the correct reference.
  • Loading branch information
magic-akari committed May 1, 2024
1 parent 9db8cdb commit af96e39
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const foo = (_class = class _class {
}
}, _ts_decorate([
foo
], _class.prototype, "foo", null));
], _class.prototype, "foo", null), _class);
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const foo = (_class = class _class {
}
}, _ts_decorate([
foo
], _class.prototype, "foo", null));
], _class.prototype, "foo", null), _class);
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-8xxx/8095/es5/output/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ var foo = (_class = function() {
return _class;
}(), _ts_decorate([
foo
], _class.prototype, "foo", null));
], _class.prototype, "foo", null), _class);
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-8xxx/8515/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var C = (_class = class _class extends Component {
}, _class = _ts_decorate([
addX,
addY
], _class));
], _class), _class);
let OtherClass = class OtherClass extends Component {
};
OtherClass = _ts_decorate([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,12 @@ impl VisitMut for TscDecorator {
exprs: iter::once(AssignExpr {
span: DUMMY_SP,
op: op!("="),
left: var_name.into(),
left: var_name.clone().into(),
right: Box::new(e.take()),
})
.map(Into::into)
.chain(appended_exprs)
.chain(iter::once(var_name.into()))
.collect(),
});
}
Expand Down

0 comments on commit af96e39

Please sign in to comment.