Skip to content

Commit 636585b

Browse files
authoredJul 30, 2024··
fix(es/codegen): Emit question token for class methods (#9342)
1 parent 1725858 commit 636585b

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed
 

‎.changeset/tall-cooks-speak.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_codegen: patch
3+
swc_ecma_transforms_typescript: patch
4+
---
5+
6+
fix(es/codegen): Emit question token for class methods

‎crates/swc_ecma_codegen/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,10 @@ where
15991599
}
16001600
}
16011601

1602+
if n.is_optional {
1603+
punct!("?");
1604+
}
1605+
16021606
if let Some(type_params) = &n.function.type_params {
16031607
emit!(type_params);
16041608
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class MyClass extends Base {
22
public override method(param: number): string {
33
}
4-
public abstract override log(msg: string): void;
4+
public abstract override log?<TValue>(msg: string): TValue;
55
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class MyClass extends Base {
22
public override method(param: number): string {}
3-
public abstract override log(msg: string): void;
3+
public abstract override log?<TValue>(msg: string): TValue;
44
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
class MyClass extends Base{public override method(param:number):string{}public abstract override log(msg:string):void}
1+
class MyClass extends Base{public override method(param:number):string{}public abstract override log?<TValue>(msg:string):TValue}

‎crates/swc_ecma_transforms_typescript/src/strip_type.rs

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl VisitMut for StripType {
8484
n.accessibility = None;
8585
n.is_override = false;
8686
n.is_abstract = false;
87+
n.is_optional = false;
8788
n.visit_mut_children_with(self);
8889
}
8990

0 commit comments

Comments
 (0)
Please sign in to comment.