Skip to content

Commit

Permalink
fix(es/decorator): Skip TypeScript class method/prop declarations (#8555
Browse files Browse the repository at this point in the history
)

**Related issue:**

- Closes #8552
  • Loading branch information
magic-akari authored Jan 25, 2024
1 parent 1890e66 commit 6a8dd8c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8552/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"decoratorVersion": "2022-03"
},
"target": "es2022"
},
"isModule": true
}
4 changes: 4 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8552/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract class C {
abstract [Symbol.iterator]();
declare [Symbol.toStringTag];
}
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8552/output/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class C {
}
15 changes: 12 additions & 3 deletions crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,14 @@ impl Decorator202203 {
fn process_decorators_of_class_members(&mut self, members: &mut [ClassMember]) {
for mut m in members {
match &mut m {
ClassMember::Method(m) => {
ClassMember::Method(m) if m.function.body.is_some() => {
self.process_decorators(&mut m.function.decorators);
self.process_prop_name(&mut m.key);
}
ClassMember::PrivateMethod(m) => {
ClassMember::PrivateMethod(m) if m.function.body.is_some() => {
self.process_decorators(&mut m.function.decorators);
}
ClassMember::ClassProp(m) => {
ClassMember::ClassProp(m) if !m.declare => {
self.process_decorators(&mut m.decorators);
self.process_prop_name(&mut m.key);
}
Expand Down Expand Up @@ -1333,6 +1333,11 @@ impl VisitMut for Decorator202203 {
}

fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
// method without body is TypeScript's method declaration.
if n.function.body.is_none() {
return;
}

n.visit_mut_children_with(self);

if n.function.decorators.is_empty() {
Expand Down Expand Up @@ -1383,6 +1388,10 @@ impl VisitMut for Decorator202203 {
}

fn visit_mut_class_prop(&mut self, p: &mut ClassProp) {
if p.declare {
return;
}

p.visit_mut_children_with(self);

if p.decorators.is_empty() {
Expand Down

0 comments on commit 6a8dd8c

Please sign in to comment.