Skip to content

Commit

Permalink
refactor(ast): remove TSLiteral::NullLiteral (replaced by `TSNullKe…
Browse files Browse the repository at this point in the history
…yword`) (#9147)
  • Loading branch information
Boshen committed Feb 15, 2025
1 parent b36734c commit 97cc1c8
Show file tree
Hide file tree
Showing 16 changed files with 5 additions and 34 deletions.
11 changes: 5 additions & 6 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ pub struct TSLiteralType<'a> {
#[generate_derive(CloneIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum TSLiteral<'a> {
BooleanLiteral(Box<'a, BooleanLiteral>) = 0,
NullLiteral(Box<'a, NullLiteral>) = 1,
NumericLiteral(Box<'a, NumericLiteral<'a>>) = 2,
BigIntLiteral(Box<'a, BigIntLiteral<'a>>) = 3,
StringLiteral(Box<'a, StringLiteral<'a>>) = 5,
TemplateLiteral(Box<'a, TemplateLiteral<'a>>) = 6,
UnaryExpression(Box<'a, UnaryExpression<'a>>) = 7,
NumericLiteral(Box<'a, NumericLiteral<'a>>) = 1,
BigIntLiteral(Box<'a, BigIntLiteral<'a>>) = 2,
StringLiteral(Box<'a, StringLiteral<'a>>) = 3,
TemplateLiteral(Box<'a, TemplateLiteral<'a>>) = 4,
UnaryExpression(Box<'a, UnaryExpression<'a>>) = 5,
}

/// TypeScript Type
Expand Down
11 changes: 0 additions & 11 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8728,17 +8728,6 @@ impl<'a> AstBuilder<'a> {
TSLiteral::BooleanLiteral(self.alloc_boolean_literal(span, value))
}

/// Build a [`TSLiteral::NullLiteral`].
///
/// This node contains a [`NullLiteral`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: Node location in source code
#[inline]
pub fn ts_literal_null_literal(self, span: Span) -> TSLiteral<'a> {
TSLiteral::NullLiteral(self.alloc_null_literal(span))
}

/// Build a [`TSLiteral::NumericLiteral`].
///
/// This node contains a [`NumericLiteral`] that will be stored in the memory arena.
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3003,7 +3003,6 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSLiteral<'_> {
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
match self {
Self::BooleanLiteral(it) => TSLiteral::BooleanLiteral(CloneIn::clone_in(it, allocator)),
Self::NullLiteral(it) => TSLiteral::NullLiteral(CloneIn::clone_in(it, allocator)),
Self::NumericLiteral(it) => TSLiteral::NumericLiteral(CloneIn::clone_in(it, allocator)),
Self::BigIntLiteral(it) => TSLiteral::BigIntLiteral(CloneIn::clone_in(it, allocator)),
Self::StringLiteral(it) => TSLiteral::StringLiteral(CloneIn::clone_in(it, allocator)),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,6 @@ impl ContentEq for TSLiteral<'_> {
fn content_eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::BooleanLiteral(a), Self::BooleanLiteral(b)) => a.content_eq(b),
(Self::NullLiteral(a), Self::NullLiteral(b)) => a.content_eq(b),
(Self::NumericLiteral(a), Self::NumericLiteral(b)) => a.content_eq(b),
(Self::BigIntLiteral(a), Self::BigIntLiteral(b)) => a.content_eq(b),
(Self::StringLiteral(a), Self::StringLiteral(b)) => a.content_eq(b),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,6 @@ impl Serialize for TSLiteral<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
TSLiteral::BooleanLiteral(it) => it.serialize(serializer),
TSLiteral::NullLiteral(it) => it.serialize(serializer),
TSLiteral::NumericLiteral(it) => it.serialize(serializer),
TSLiteral::BigIntLiteral(it) => it.serialize(serializer),
TSLiteral::StringLiteral(it) => it.serialize(serializer),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_get_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ impl GetAddress for TSLiteral<'_> {
fn address(&self) -> Address {
match self {
Self::BooleanLiteral(it) => GetAddress::address(it),
Self::NullLiteral(it) => GetAddress::address(it),
Self::NumericLiteral(it) => GetAddress::address(it),
Self::BigIntLiteral(it) => GetAddress::address(it),
Self::StringLiteral(it) => GetAddress::address(it),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_get_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,6 @@ impl GetSpan for TSLiteral<'_> {
fn span(&self) -> Span {
match self {
Self::BooleanLiteral(it) => GetSpan::span(&**it),
Self::NullLiteral(it) => GetSpan::span(&**it),
Self::NumericLiteral(it) => GetSpan::span(&**it),
Self::BigIntLiteral(it) => GetSpan::span(&**it),
Self::StringLiteral(it) => GetSpan::span(&**it),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_get_span_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,6 @@ impl GetSpanMut for TSLiteral<'_> {
fn span_mut(&mut self) -> &mut Span {
match self {
Self::BooleanLiteral(it) => GetSpanMut::span_mut(&mut **it),
Self::NullLiteral(it) => GetSpanMut::span_mut(&mut **it),
Self::NumericLiteral(it) => GetSpanMut::span_mut(&mut **it),
Self::BigIntLiteral(it) => GetSpanMut::span_mut(&mut **it),
Self::StringLiteral(it) => GetSpanMut::span_mut(&mut **it),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3197,7 +3197,6 @@ pub mod walk {
// No `AstKind` for this type
match it {
TSLiteral::BooleanLiteral(it) => visitor.visit_boolean_literal(it),
TSLiteral::NullLiteral(it) => visitor.visit_null_literal(it),
TSLiteral::NumericLiteral(it) => visitor.visit_numeric_literal(it),
TSLiteral::BigIntLiteral(it) => visitor.visit_big_int_literal(it),
TSLiteral::StringLiteral(it) => visitor.visit_string_literal(it),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3352,7 +3352,6 @@ pub mod walk_mut {
// No `AstType` for this type
match it {
TSLiteral::BooleanLiteral(it) => visitor.visit_boolean_literal(it),
TSLiteral::NullLiteral(it) => visitor.visit_null_literal(it),
TSLiteral::NumericLiteral(it) => visitor.visit_numeric_literal(it),
TSLiteral::BigIntLiteral(it) => visitor.visit_big_int_literal(it),
TSLiteral::StringLiteral(it) => visitor.visit_string_literal(it),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3336,7 +3336,6 @@ impl Gen for TSLiteral<'_> {
fn gen(&self, p: &mut Codegen, ctx: Context) {
match self {
Self::BooleanLiteral(decl) => decl.print(p, ctx),
Self::NullLiteral(decl) => decl.print(p, ctx),
Self::NumericLiteral(decl) => decl.print_expr(p, Precedence::Lowest, ctx),
Self::BigIntLiteral(decl) => decl.print_expr(p, Precedence::Lowest, ctx),
Self::StringLiteral(decl) => decl.print(p, ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ fn is_inferrable_type(type_annotation: &TSTypeAnnotation, init: &Expression) ->
match &type_annotation.type_annotation {
TSType::TSLiteralType(ts_literal_type) => match &ts_literal_type.literal {
TSLiteral::BooleanLiteral(_) => is_init_boolean(init),
TSLiteral::NullLiteral(_) => is_init_null(init),
TSLiteral::NumericLiteral(_) => is_init_number(init),
TSLiteral::BigIntLiteral(_) => is_init_bigint(init),
TSLiteral::StringLiteral(_) => is_init_string(init),
Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_linter/src/rules/typescript/prefer_as_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ fn check_and_report(
}
_ => None,
},
TSLiteral::NullLiteral(null_literal) => match initial_value_expression {
Expression::NullLiteral(_) => Some(null_literal.span),
_ => None,
},
TSLiteral::NumericLiteral(number_literal) => match initial_value_expression {
Expression::NumericLiteral(initial_number) => {
if (number_literal.value - initial_number.value).abs() < f64::EPSILON {
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_prettier/src/format/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ impl<'a> Format<'a> for TSLiteralType<'a> {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
match &self.literal {
TSLiteral::BooleanLiteral(v) => v.format(p),
TSLiteral::NullLiteral(v) => v.format(p),
TSLiteral::NumericLiteral(v) => v.format(p),
TSLiteral::BigIntLiteral(v) => v.format(p),
TSLiteral::StringLiteral(v) => v.format(p),
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_traverse/src/generated/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3776,7 +3776,6 @@ unsafe fn walk_ts_literal<'a, Tr: Traverse<'a>>(
TSLiteral::BooleanLiteral(node) => {
walk_boolean_literal(traverser, (&mut **node) as *mut _, ctx)
}
TSLiteral::NullLiteral(node) => walk_null_literal(traverser, (&mut **node) as *mut _, ctx),
TSLiteral::NumericLiteral(node) => {
walk_numeric_literal(traverser, (&mut **node) as *mut _, ctx)
}
Expand Down
1 change: 0 additions & 1 deletion npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ export interface TSLiteralType extends Span {

export type TSLiteral =
| BooleanLiteral
| NullLiteral
| NumericLiteral
| BigIntLiteral
| StringLiteral
Expand Down

0 comments on commit 97cc1c8

Please sign in to comment.