Skip to content

Commit

Permalink
feat(es/ast): Support abstract auto-accessors (#8736)
Browse files Browse the repository at this point in the history
**Description:**

Supports abstract auto-accessors:
https://github.com/microsoft/TypeScript/blob/3e91592b06096e1cfdc6eb05a95838831e547e22/tests/baselines/reference/autoAccessorAllowedModifiers.js#L9

**BREAKING CHANGE:**

Adds a new is_abstract property
  • Loading branch information
dsherret authored Apr 24, 2024
1 parent d925f8a commit 1155ac7
Show file tree
Hide file tree
Showing 37 changed files with 263 additions and 71 deletions.
4 changes: 4 additions & 0 deletions crates/swc_ecma_ast/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ pub struct AutoAccessor {
#[cfg_attr(feature = "serde-impl", serde(default))]
pub accessibility: Option<Accessibility>,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub is_abstract: bool,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub is_override: bool,

Expand All @@ -349,6 +352,7 @@ impl Take for AutoAccessor {
is_static: false,
decorators: Take::dummy(),
accessibility: None,
is_abstract: false,
is_override: false,
definite: false,
}
Expand Down
5 changes: 5 additions & 0 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,11 @@ where
space!();
}

if n.is_abstract {
keyword!("abstract");
space!();
}

if n.is_override {
keyword!("override");
space!();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class MyClass extends Base {
public prop13: string;
private static prop14: string;
protected override accessor prop15 = 5;
abstract accessor abstractAccessor: string;
[value]?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class MyClass extends Base {
public prop13: string;
private static prop14: string;
protected override accessor prop15 = 5;
abstract accessor abstractAccessor: string;
[value]?: string[];
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/swc_ecma_parser/src/parser/class_and_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ impl<I: Tokens> Parser<I> {
is_static,
decorators,
accessibility,
is_abstract,
is_override,
definite,
}));
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor1.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -98,6 +99,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -139,6 +141,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -173,6 +176,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
5 changes: 5 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor10.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -162,6 +163,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -302,6 +304,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -436,6 +439,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -497,6 +501,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor11.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor2.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -114,6 +115,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -163,6 +165,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -205,6 +208,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor3.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -98,6 +99,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -139,6 +141,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -173,6 +176,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor4.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -98,6 +99,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -139,6 +141,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -173,6 +176,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor6.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor7.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": true,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -125,6 +126,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor8.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -105,6 +106,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -173,6 +175,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -214,6 +217,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -310,6 +314,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -351,6 +356,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_ecma_parser/tests/tsc/autoAccessor9.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -156,6 +157,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -299,6 +301,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -551,6 +554,7 @@
"isStatic": false,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down Expand Up @@ -650,6 +654,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
}
Expand Down Expand Up @@ -749,6 +754,7 @@
"isStatic": true,
"decorators": [],
"accessibility": null,
"isAbstract": false,
"isOverride": false,
"definite": false
},
Expand Down
Loading

0 comments on commit 1155ac7

Please sign in to comment.