Skip to content

Commit 46748fe

Browse files
authored
fix: Don't add second ? to optional methods (#88)
1 parent fdabfd0 commit 46748fe

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/parsing/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ fn parse_identifier<'a>(node: &'a Ident, context: &mut Context<'a>) -> PrintItem
618618
let mut items = PrintItems::new();
619619
items.push_str(node.sym() as &str);
620620

621-
if node.optional() && !node.parent().unwrap().is::<ClassProp>() {
621+
if node.optional() && !node.parent().unwrap().is::<ClassProp>() && !node.parent().unwrap().is::<ClassMethod>() {
622622
items.push_str("?");
623623
}
624624
if let Node::VarDeclarator(node) = node.parent().unwrap() {

tests/specs/declarations/class/method/ClassMethod_All.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ abstract class Test {
3333
method8(): string | number | string | number | string {
3434
}
3535

36+
method9?() {
37+
}
38+
3639
get getSet(): string {
3740
}
3841

@@ -82,6 +85,9 @@ abstract class Test {
8285
{
8386
}
8487

88+
method9?() {
89+
}
90+
8591
get getSet(): string {
8692
}
8793

tests/specs/declarations/class/private_method/PrivateMethod_All.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ abstract class Test {
44
#method1( arg : string ) : test {
55
return 5 ;
66
}
7+
8+
#method2?() {
9+
}
710
}
811

912
[expect]
1013
abstract class Test {
1114
#method1(arg: string): test {
1215
return 5;
1316
}
17+
18+
#method2?() {
19+
}
1420
}

0 commit comments

Comments
 (0)