Skip to content
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

feat(ast)!: remove invalid expressions from TSEnumMemberName #7219

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use oxc_estree::ESTree;
use oxc_span::{cmp::ContentEq, hash::ContentHash, Atom, GetSpan, GetSpanMut, Span};
use oxc_syntax::scope::ScopeId;

use super::{inherit_variants, js::*, jsx::*, literal::*};
use super::{inherit_variants, js::*, literal::*};

/// TypeScript `this` parameter
///
Expand Down Expand Up @@ -115,12 +115,6 @@ inherit_variants! {
pub enum TSEnumMemberName<'a> {
StaticIdentifier(Box<'a, IdentifierName<'a>>) = 64,
StaticStringLiteral(Box<'a, StringLiteral<'a>>) = 65,
StaticTemplateLiteral(Box<'a, TemplateLiteral<'a>>) = 66,
// Invalid Grammar `enum E { 1 }`
StaticNumericLiteral(Box<'a, NumericLiteral<'a>>) = 67,
// Invalid Grammar `enum E { [computed] }`
// `Expression` variants added here by `inherit_variants!` macro
@inherit Expression
}
}

Expand Down
11 changes: 4 additions & 7 deletions crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ use oxc_span::Atom;
use crate::ast::*;

impl<'a> TSEnumMemberName<'a> {
/// Get the name of this enum member if it can be determined statically.
pub fn static_name(&self) -> Option<&'a str> {
/// Get the name of this enum member.
pub fn static_name(&self) -> Atom<'a> {
match self {
Self::StaticIdentifier(ident) => Some(ident.name.as_str()),
Self::StaticStringLiteral(lit) => Some(lit.value.as_str()),
Self::NumericLiteral(lit) => Some(lit.raw),
Self::StaticTemplateLiteral(lit) => lit.quasi().map(Into::into),
_ => None,
Self::StaticIdentifier(ident) => ident.name.clone(),
Self::StaticStringLiteral(lit) => lit.value.clone(),
}
}
}
Expand Down
47 changes: 0 additions & 47 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7783,53 +7783,6 @@ impl<'a> AstBuilder<'a> {
TSEnumMemberName::StaticStringLiteral(self.alloc(self.string_literal(span, value)))
}

/// Build a [`TSEnumMemberName::StaticTemplateLiteral`]
///
/// This node contains a [`TemplateLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - quasis
/// - expressions
#[inline]
pub fn ts_enum_member_name_template_literal(
self,
span: Span,
quasis: Vec<'a, TemplateElement<'a>>,
expressions: Vec<'a, Expression<'a>>,
) -> TSEnumMemberName<'a> {
TSEnumMemberName::StaticTemplateLiteral(self.alloc(self.template_literal(
span,
quasis,
expressions,
)))
}

/// Build a [`TSEnumMemberName::StaticNumericLiteral`]
///
/// This node contains a [`NumericLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// - span: Node location in source code
/// - value: The value of the number, converted into base 10
/// - raw: The number as it appears in source code
/// - base: The base representation used by the literal in source code
#[inline]
pub fn ts_enum_member_name_numeric_literal<S>(
self,
span: Span,
value: f64,
raw: S,
base: NumberBase,
) -> TSEnumMemberName<'a>
where
S: IntoIn<'a, &'a str>,
{
TSEnumMemberName::StaticNumericLiteral(
self.alloc(self.numeric_literal(span, value, raw, base)),
)
}

/// Build a [`TSTypeAnnotation`].
///
/// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_type_annotation`] instead.
Expand Down
126 changes: 0 additions & 126 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2600,132 +2600,6 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for TSEnumMemberName<'old_alloc
Self::StaticStringLiteral(it) => {
TSEnumMemberName::StaticStringLiteral(CloneIn::clone_in(it, allocator))
}
Self::StaticTemplateLiteral(it) => {
TSEnumMemberName::StaticTemplateLiteral(CloneIn::clone_in(it, allocator))
}
Self::StaticNumericLiteral(it) => {
TSEnumMemberName::StaticNumericLiteral(CloneIn::clone_in(it, allocator))
}
Self::BooleanLiteral(it) => {
TSEnumMemberName::BooleanLiteral(CloneIn::clone_in(it, allocator))
}
Self::NullLiteral(it) => {
TSEnumMemberName::NullLiteral(CloneIn::clone_in(it, allocator))
}
Self::NumericLiteral(it) => {
TSEnumMemberName::NumericLiteral(CloneIn::clone_in(it, allocator))
}
Self::BigIntLiteral(it) => {
TSEnumMemberName::BigIntLiteral(CloneIn::clone_in(it, allocator))
}
Self::RegExpLiteral(it) => {
TSEnumMemberName::RegExpLiteral(CloneIn::clone_in(it, allocator))
}
Self::StringLiteral(it) => {
TSEnumMemberName::StringLiteral(CloneIn::clone_in(it, allocator))
}
Self::TemplateLiteral(it) => {
TSEnumMemberName::TemplateLiteral(CloneIn::clone_in(it, allocator))
}
Self::Identifier(it) => TSEnumMemberName::Identifier(CloneIn::clone_in(it, allocator)),
Self::MetaProperty(it) => {
TSEnumMemberName::MetaProperty(CloneIn::clone_in(it, allocator))
}
Self::Super(it) => TSEnumMemberName::Super(CloneIn::clone_in(it, allocator)),
Self::ArrayExpression(it) => {
TSEnumMemberName::ArrayExpression(CloneIn::clone_in(it, allocator))
}
Self::ArrowFunctionExpression(it) => {
TSEnumMemberName::ArrowFunctionExpression(CloneIn::clone_in(it, allocator))
}
Self::AssignmentExpression(it) => {
TSEnumMemberName::AssignmentExpression(CloneIn::clone_in(it, allocator))
}
Self::AwaitExpression(it) => {
TSEnumMemberName::AwaitExpression(CloneIn::clone_in(it, allocator))
}
Self::BinaryExpression(it) => {
TSEnumMemberName::BinaryExpression(CloneIn::clone_in(it, allocator))
}
Self::CallExpression(it) => {
TSEnumMemberName::CallExpression(CloneIn::clone_in(it, allocator))
}
Self::ChainExpression(it) => {
TSEnumMemberName::ChainExpression(CloneIn::clone_in(it, allocator))
}
Self::ClassExpression(it) => {
TSEnumMemberName::ClassExpression(CloneIn::clone_in(it, allocator))
}
Self::ConditionalExpression(it) => {
TSEnumMemberName::ConditionalExpression(CloneIn::clone_in(it, allocator))
}
Self::FunctionExpression(it) => {
TSEnumMemberName::FunctionExpression(CloneIn::clone_in(it, allocator))
}
Self::ImportExpression(it) => {
TSEnumMemberName::ImportExpression(CloneIn::clone_in(it, allocator))
}
Self::LogicalExpression(it) => {
TSEnumMemberName::LogicalExpression(CloneIn::clone_in(it, allocator))
}
Self::NewExpression(it) => {
TSEnumMemberName::NewExpression(CloneIn::clone_in(it, allocator))
}
Self::ObjectExpression(it) => {
TSEnumMemberName::ObjectExpression(CloneIn::clone_in(it, allocator))
}
Self::ParenthesizedExpression(it) => {
TSEnumMemberName::ParenthesizedExpression(CloneIn::clone_in(it, allocator))
}
Self::SequenceExpression(it) => {
TSEnumMemberName::SequenceExpression(CloneIn::clone_in(it, allocator))
}
Self::TaggedTemplateExpression(it) => {
TSEnumMemberName::TaggedTemplateExpression(CloneIn::clone_in(it, allocator))
}
Self::ThisExpression(it) => {
TSEnumMemberName::ThisExpression(CloneIn::clone_in(it, allocator))
}
Self::UnaryExpression(it) => {
TSEnumMemberName::UnaryExpression(CloneIn::clone_in(it, allocator))
}
Self::UpdateExpression(it) => {
TSEnumMemberName::UpdateExpression(CloneIn::clone_in(it, allocator))
}
Self::YieldExpression(it) => {
TSEnumMemberName::YieldExpression(CloneIn::clone_in(it, allocator))
}
Self::PrivateInExpression(it) => {
TSEnumMemberName::PrivateInExpression(CloneIn::clone_in(it, allocator))
}
Self::JSXElement(it) => TSEnumMemberName::JSXElement(CloneIn::clone_in(it, allocator)),
Self::JSXFragment(it) => {
TSEnumMemberName::JSXFragment(CloneIn::clone_in(it, allocator))
}
Self::TSAsExpression(it) => {
TSEnumMemberName::TSAsExpression(CloneIn::clone_in(it, allocator))
}
Self::TSSatisfiesExpression(it) => {
TSEnumMemberName::TSSatisfiesExpression(CloneIn::clone_in(it, allocator))
}
Self::TSTypeAssertion(it) => {
TSEnumMemberName::TSTypeAssertion(CloneIn::clone_in(it, allocator))
}
Self::TSNonNullExpression(it) => {
TSEnumMemberName::TSNonNullExpression(CloneIn::clone_in(it, allocator))
}
Self::TSInstantiationExpression(it) => {
TSEnumMemberName::TSInstantiationExpression(CloneIn::clone_in(it, allocator))
}
Self::ComputedMemberExpression(it) => {
TSEnumMemberName::ComputedMemberExpression(CloneIn::clone_in(it, allocator))
}
Self::StaticMemberExpression(it) => {
TSEnumMemberName::StaticMemberExpression(CloneIn::clone_in(it, allocator))
}
Self::PrivateFieldExpression(it) => {
TSEnumMemberName::PrivateFieldExpression(CloneIn::clone_in(it, allocator))
}
}
}
}
Expand Down
Loading
Loading