-
-
Notifications
You must be signed in to change notification settings - Fork 569
feat(ast)!: Add computed
property to TSEnumMember
and TSEnumMemberName::TemplateString
#10092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Instrumentation Performance ReportMerging #10092 will not alter performanceComparing Summary
|
This comment was marked as resolved.
This comment was marked as resolved.
Thanks for this. Since we know for sure that the template string must have no expressions and only 1 quasi in this case, I wonder if we should add a specific type for it? pub enum TSEnumMemberName<'a> {
Identifier(Box<'a, IdentifierName<'a>>) = 0,
String(Box<'a, StringLiteral<'a>>) = 1,
Template(Box<'a, SimpleTemplateLiteral<'a>>) = 2,
}
/// A template literal with no expressions and only 1 quasi.
/// Basically a copy of `StringLiteral`, but with backtick quotes.
pub struct SimpleTemplateLiteral<'a> {
span: Span,
#[estree(via = StringLiteralValue)]
pub value: Atom<'a>,
#[content_eq(skip)]
pub raw: Option<Atom<'a>>,
#[builder(default)]
#[estree(skip)]
pub lone_surrogates: bool,
} Personally I think that'd be preferable as, generally speaking, I think it's ideal for the AST to statically be unable to represent syntax which is illegal. But @Boshen what do you think? Additionally, instead of a pub enum TSEnumMemberName<'a> {
Identifier(Box<'a, IdentifierName<'a>>) = 0,
String(Box<'a, StringLiteral<'a>>) = 1,
Template(Box<'a, SimpleTemplateLiteral<'a>>) = 2,
ComputedString(Box<'a, StringLiteral<'a>>) = 3,
ComputedTemplate(Box<'a, SimpleTemplateLiteral<'a>>) = 4,
} Again, the rationale is that this makes it impossible to represent an illegal syntax in AST: enum Foo {
// Illegal syntax - identifiers cannot be computed
[x] = 1,
} (there is no This also makes |
Thanks for the review~! I too prefer that idea because it is explicit. Let's wait for the Boshen's decision. 🙏🏻 |
One other thing: Doesn't codegen need to wrap in Otherwise this: export enum X {
[`A`] = 123,
} is printed as: export enum X {
`A` = 123,
} ...which is invalid syntax. |
@Boshen Could you please give your opinion on #10092 (comment)? Personally, I like the tighter constraint that a |
I think adding a |
…erName::TemplateString`
This reverts commit 302b856.
28bd941
to
fa97b6c
Compare
Rebased on main to fix merge conflicts. I'm going to merge this when CI passes. I realized my idea of a I do think my other suggestion of removing the pub enum TSEnumMemberName<'a> {
Identifier(Box<'a, IdentifierName<'a>>) = 0,
String(Box<'a, StringLiteral<'a>>) = 1,
Template(Box<'a, SimpleTemplateLiteral<'a>>) = 2,
ComputedString(Box<'a, StringLiteral<'a>>) = 3,
ComputedTemplate(Box<'a, SimpleTemplateLiteral<'a>>) = 4,
} I'll open an issue for making that change. But let's get this merged in meantime! |
Fixes #10088