Skip to content

Commit 1a9e904

Browse files
committed
fix: Handle identifier now being optional in swc when the parent class prop is optional.
1 parent 3931507 commit 1a9e904

File tree

2 files changed

+3
-1
lines changed

2 files changed

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

tests/specs/declarations/class/private_property/PrivateProperty_All.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Test {
44
#p1;
55
#p2 : string;
66
#p3 = 4;
7+
#p4 ? : string;
78

89
constructor() {
910
this.#p1 = "test";
@@ -15,6 +16,7 @@ class Test {
1516
#p1;
1617
#p2: string;
1718
#p3 = 4;
19+
#p4?: string;
1820

1921
constructor() {
2022
this.#p1 = "test";

0 commit comments

Comments
 (0)