Skip to content

Commit 6a8dd8c

Browse files
authored
fix(es/decorator): Skip TypeScript class method/prop declarations (#8555)
**Related issue:** - Closes #8552
1 parent 1890e66 commit 6a8dd8c

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"decorators": true
6+
},
7+
"transform": {
8+
"decoratorVersion": "2022-03"
9+
},
10+
"target": "es2022"
11+
},
12+
"isModule": true
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
abstract class C {
2+
abstract [Symbol.iterator]();
3+
declare [Symbol.toStringTag];
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class C {
2+
}

crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,14 +735,14 @@ impl Decorator202203 {
735735
fn process_decorators_of_class_members(&mut self, members: &mut [ClassMember]) {
736736
for mut m in members {
737737
match &mut m {
738-
ClassMember::Method(m) => {
738+
ClassMember::Method(m) if m.function.body.is_some() => {
739739
self.process_decorators(&mut m.function.decorators);
740740
self.process_prop_name(&mut m.key);
741741
}
742-
ClassMember::PrivateMethod(m) => {
742+
ClassMember::PrivateMethod(m) if m.function.body.is_some() => {
743743
self.process_decorators(&mut m.function.decorators);
744744
}
745-
ClassMember::ClassProp(m) => {
745+
ClassMember::ClassProp(m) if !m.declare => {
746746
self.process_decorators(&mut m.decorators);
747747
self.process_prop_name(&mut m.key);
748748
}
@@ -1333,6 +1333,11 @@ impl VisitMut for Decorator202203 {
13331333
}
13341334

13351335
fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
1336+
// method without body is TypeScript's method declaration.
1337+
if n.function.body.is_none() {
1338+
return;
1339+
}
1340+
13361341
n.visit_mut_children_with(self);
13371342

13381343
if n.function.decorators.is_empty() {
@@ -1383,6 +1388,10 @@ impl VisitMut for Decorator202203 {
13831388
}
13841389

13851390
fn visit_mut_class_prop(&mut self, p: &mut ClassProp) {
1391+
if p.declare {
1392+
return;
1393+
}
1394+
13861395
p.visit_mut_children_with(self);
13871396

13881397
if p.decorators.is_empty() {

0 commit comments

Comments
 (0)