-
-
Notifications
You must be signed in to change notification settings - Fork 777
Closed
Labels
A-astArea - ASTArea - AST
Description
#10092 introduced a computed field on TSEnumMember, in order to align with TS-ESLint.
oxc/crates/oxc_ast/src/ast/ts.rs
Lines 122 to 127 in fa97b6c
| pub struct TSEnumMember<'a> { | |
| pub span: Span, | |
| pub id: TSEnumMemberName<'a>, | |
| pub computed: bool, | |
| pub initializer: Option<Expression<'a>>, | |
| } |
I suggest that we remove this field and instead have more variants on TSEnumMemberName:
pub enum TSEnumMemberName<'a> {
Identifier(Box<'a, IdentifierName<'a>>),
+ ComputedIdentifier(Box<'a, IdentifierName<'a>>),
String(Box<'a, StringLiteral<'a>>),
+ ComputedString(Box<'a, StringLiteral<'a>>),
- TemplateString(Box<'a, TemplateLiteral<'a>>),
+ ComputedTemplateString(Box<'a, TemplateLiteral<'a>>),
}There are 2 reasons I feel this is preferable:
- Shrink
TSEnumMemberby 8 bytes. - Make it impossible to represent an illegal syntax in AST:
enum Foo {
// Illegal syntax - template strings must be computed
`X` = 1,
}computed: false is not valid when member name is a TemplateLiteral.
Note: I had thought that computed Identifiers are also illegal ([A] = 1), but it appears that's a typechecking error, not a parse error.
Both TS and @typescript-eslint/parser accept this syntax when parsing only (type-checking disabled):
Metadata
Metadata
Assignees
Labels
A-astArea - ASTArea - AST