Skip to content
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
10 changes: 9 additions & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,13 +1541,21 @@ pub struct TSSatisfiesExpression<'a> {
pub type_annotation: TSType<'a>,
}

/// TypeScript Type Assertion
///
/// ## Example
/// ```ts
/// // ___ expression
/// let foo = <number>bar;
/// // ^^^^^^^^ type_annotation
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub struct TSTypeAssertion<'a> {
pub span: Span,
pub expression: Expression<'a>,
pub type_annotation: TSType<'a>,
pub expression: Expression<'a>,
}

#[ast(visit)]
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,8 @@ const _: () = {
assert!(size_of::<TSTypeAssertion>() == 40);
assert!(align_of::<TSTypeAssertion>() == 8);
assert!(offset_of!(TSTypeAssertion, span) == 0);
assert!(offset_of!(TSTypeAssertion, expression) == 8);
assert!(offset_of!(TSTypeAssertion, type_annotation) == 24);
assert!(offset_of!(TSTypeAssertion, type_annotation) == 8);
assert!(offset_of!(TSTypeAssertion, expression) == 24);

assert!(size_of::<TSImportEqualsDeclaration>() == 64);
assert!(align_of::<TSImportEqualsDeclaration>() == 8);
Expand Down Expand Up @@ -2714,8 +2714,8 @@ const _: () = {
assert!(size_of::<TSTypeAssertion>() == 24);
assert!(align_of::<TSTypeAssertion>() == 4);
assert!(offset_of!(TSTypeAssertion, span) == 0);
assert!(offset_of!(TSTypeAssertion, expression) == 8);
assert!(offset_of!(TSTypeAssertion, type_annotation) == 16);
assert!(offset_of!(TSTypeAssertion, type_annotation) == 8);
assert!(offset_of!(TSTypeAssertion, expression) == 16);

assert!(size_of::<TSImportEqualsDeclaration>() == 40);
assert!(align_of::<TSImportEqualsDeclaration>() == 4);
Expand Down
24 changes: 12 additions & 12 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,16 +1140,16 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `expression`
/// * `type_annotation`
/// * `expression`
#[inline]
pub fn expression_ts_type_assertion(
self,
span: Span,
expression: Expression<'a>,
type_annotation: TSType<'a>,
expression: Expression<'a>,
) -> Expression<'a> {
Expression::TSTypeAssertion(self.alloc_ts_type_assertion(span, expression, type_annotation))
Expression::TSTypeAssertion(self.alloc_ts_type_assertion(span, type_annotation, expression))
}

/// Build an [`Expression::TSNonNullExpression`].
Expand Down Expand Up @@ -2718,19 +2718,19 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `expression`
/// * `type_annotation`
/// * `expression`
#[inline]
pub fn simple_assignment_target_ts_type_assertion(
self,
span: Span,
expression: Expression<'a>,
type_annotation: TSType<'a>,
expression: Expression<'a>,
) -> SimpleAssignmentTarget<'a> {
SimpleAssignmentTarget::TSTypeAssertion(self.alloc_ts_type_assertion(
span,
expression,
type_annotation,
expression,
))
}

Expand Down Expand Up @@ -14142,16 +14142,16 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `expression`
/// * `type_annotation`
/// * `expression`
#[inline]
pub fn ts_type_assertion(
self,
span: Span,
expression: Expression<'a>,
type_annotation: TSType<'a>,
expression: Expression<'a>,
) -> TSTypeAssertion<'a> {
TSTypeAssertion { span, expression, type_annotation }
TSTypeAssertion { span, type_annotation, expression }
}

/// Build a [`TSTypeAssertion`], and store it in the memory arena.
Expand All @@ -14161,16 +14161,16 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `expression`
/// * `type_annotation`
/// * `expression`
#[inline]
pub fn alloc_ts_type_assertion(
self,
span: Span,
expression: Expression<'a>,
type_annotation: TSType<'a>,
expression: Expression<'a>,
) -> Box<'a, TSTypeAssertion<'a>> {
Box::new_in(self.ts_type_assertion(span, expression, type_annotation), self.allocator)
Box::new_in(self.ts_type_assertion(span, type_annotation, expression), self.allocator)
}

/// Build a [`TSImportEqualsDeclaration`].
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7577,16 +7577,16 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeAssertion<'_> {
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
TSTypeAssertion {
span: CloneIn::clone_in(&self.span, allocator),
expression: CloneIn::clone_in(&self.expression, allocator),
type_annotation: CloneIn::clone_in(&self.type_annotation, allocator),
expression: CloneIn::clone_in(&self.expression, allocator),
}
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
TSTypeAssertion {
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
expression: CloneIn::clone_in_with_semantic_ids(&self.expression, allocator),
type_annotation: CloneIn::clone_in_with_semantic_ids(&self.type_annotation, allocator),
expression: CloneIn::clone_in_with_semantic_ids(&self.expression, allocator),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2377,8 +2377,8 @@ impl ContentEq for TSSatisfiesExpression<'_> {

impl ContentEq for TSTypeAssertion<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.expression, &other.expression)
&& ContentEq::content_eq(&self.type_annotation, &other.type_annotation)
ContentEq::content_eq(&self.type_annotation, &other.type_annotation)
&& ContentEq::content_eq(&self.expression, &other.expression)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2728,8 +2728,8 @@ impl<'a> Dummy<'a> for TSTypeAssertion<'a> {
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
expression: Dummy::dummy(allocator),
type_annotation: Dummy::dummy(allocator),
expression: Dummy::dummy(allocator),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3226,8 +3226,8 @@ impl ESTree for TSTypeAssertion<'_> {
state.serialize_field("type", &JsonSafeString("TSTypeAssertion"));
state.serialize_field("start", &self.span.start);
state.serialize_field("end", &self.span.end);
state.serialize_field("expression", &self.expression);
state.serialize_field("typeAnnotation", &self.type_annotation);
state.serialize_field("expression", &self.expression);
state.end();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3992,8 +3992,8 @@ pub mod walk {
let kind = AstKind::TSTypeAssertion(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_span(&it.span);
visitor.visit_expression(&it.expression);
visitor.visit_ts_type(&it.type_annotation);
visitor.visit_expression(&it.expression);
visitor.leave_node(kind);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4213,8 +4213,8 @@ pub mod walk_mut {
let kind = AstType::TSTypeAssertion;
visitor.enter_node(kind);
visitor.visit_span(&mut it.span);
visitor.visit_expression(&mut it.expression);
visitor.visit_ts_type(&mut it.type_annotation);
visitor.visit_expression(&mut it.expression);
visitor.leave_node(kind);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl<'a> ParserImpl<'a> {
self.expect(Kind::RAngle);
let lhs_span = self.start_span();
let expression = self.parse_simple_unary_expression(lhs_span);
self.ast.expression_ts_type_assertion(self.end_span(span), expression, type_annotation)
self.ast.expression_ts_type_assertion(self.end_span(span), type_annotation, expression)
}

pub(crate) fn parse_ts_import_equals_declaration(&mut self, span: u32) -> Declaration<'a> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/assignments/left-hand.ts
"flags": "ReferenceFlags(Write)",
"id": 1,
"name": "Foo",
"node_id": 19
"node_id": 20
},
{
"flags": "ReferenceFlags(Write)",
Expand All @@ -49,7 +49,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/assignments/left-hand.ts
"flags": "ReferenceFlags(Read)",
"id": 5,
"name": "Foo",
"node_id": 53
"node_id": 54
},
{
"flags": "ReferenceFlags(Read)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-assertion/
"references": [
{
"flags": "ReferenceFlags(Read)",
"id": 0,
"id": 1,
"name": "x",
"node_id": 11
"node_id": 14
}
]
},
Expand All @@ -39,9 +39,9 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-assertion/
"references": [
{
"flags": "ReferenceFlags(Type)",
"id": 1,
"id": 0,
"name": "T",
"node_id": 14
"node_id": 13
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-assertion/
"flags": "ReferenceFlags(Read | Write)",
"id": 0,
"name": "x",
"node_id": 14
"node_id": 15
}
]
}
Expand Down
40 changes: 20 additions & 20 deletions crates/oxc_traverse/src/generated/ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ pub(crate) enum AncestorType {
TSAsExpressionTypeAnnotation = 279,
TSSatisfiesExpressionExpression = 280,
TSSatisfiesExpressionTypeAnnotation = 281,
TSTypeAssertionExpression = 282,
TSTypeAssertionTypeAnnotation = 283,
TSTypeAssertionTypeAnnotation = 282,
TSTypeAssertionExpression = 283,
TSImportEqualsDeclarationId = 284,
TSImportEqualsDeclarationModuleReference = 285,
TSExternalModuleReferenceExpression = 286,
Expand Down Expand Up @@ -859,10 +859,10 @@ pub enum Ancestor<'a, 't> {
AncestorType::TSSatisfiesExpressionExpression as u16,
TSSatisfiesExpressionTypeAnnotation(TSSatisfiesExpressionWithoutTypeAnnotation<'a, 't>) =
AncestorType::TSSatisfiesExpressionTypeAnnotation as u16,
TSTypeAssertionExpression(TSTypeAssertionWithoutExpression<'a, 't>) =
AncestorType::TSTypeAssertionExpression as u16,
TSTypeAssertionTypeAnnotation(TSTypeAssertionWithoutTypeAnnotation<'a, 't>) =
AncestorType::TSTypeAssertionTypeAnnotation as u16,
TSTypeAssertionExpression(TSTypeAssertionWithoutExpression<'a, 't>) =
AncestorType::TSTypeAssertionExpression as u16,
TSImportEqualsDeclarationId(TSImportEqualsDeclarationWithoutId<'a, 't>) =
AncestorType::TSImportEqualsDeclarationId as u16,
TSImportEqualsDeclarationModuleReference(
Expand Down Expand Up @@ -1802,7 +1802,7 @@ impl<'a, 't> Ancestor<'a, 't> {

#[inline]
pub fn is_ts_type_assertion(self) -> bool {
matches!(self, Self::TSTypeAssertionExpression(_) | Self::TSTypeAssertionTypeAnnotation(_))
matches!(self, Self::TSTypeAssertionTypeAnnotation(_) | Self::TSTypeAssertionExpression(_))
}

#[inline]
Expand Down Expand Up @@ -2479,8 +2479,8 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> {
Self::TSAsExpressionTypeAnnotation(a) => a.address(),
Self::TSSatisfiesExpressionExpression(a) => a.address(),
Self::TSSatisfiesExpressionTypeAnnotation(a) => a.address(),
Self::TSTypeAssertionExpression(a) => a.address(),
Self::TSTypeAssertionTypeAnnotation(a) => a.address(),
Self::TSTypeAssertionExpression(a) => a.address(),
Self::TSImportEqualsDeclarationId(a) => a.address(),
Self::TSImportEqualsDeclarationModuleReference(a) => a.address(),
Self::TSExternalModuleReferenceExpression(a) => a.address(),
Expand Down Expand Up @@ -15132,34 +15132,34 @@ impl<'a, 't> GetAddress for TSSatisfiesExpressionWithoutTypeAnnotation<'a, 't> {
}

pub(crate) const OFFSET_TS_TYPE_ASSERTION_SPAN: usize = offset_of!(TSTypeAssertion, span);
pub(crate) const OFFSET_TS_TYPE_ASSERTION_EXPRESSION: usize =
offset_of!(TSTypeAssertion, expression);
pub(crate) const OFFSET_TS_TYPE_ASSERTION_TYPE_ANNOTATION: usize =
offset_of!(TSTypeAssertion, type_annotation);
pub(crate) const OFFSET_TS_TYPE_ASSERTION_EXPRESSION: usize =
offset_of!(TSTypeAssertion, expression);

#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct TSTypeAssertionWithoutExpression<'a, 't>(
pub struct TSTypeAssertionWithoutTypeAnnotation<'a, 't>(
pub(crate) *const TSTypeAssertion<'a>,
pub(crate) PhantomData<&'t ()>,
);

impl<'a, 't> TSTypeAssertionWithoutExpression<'a, 't> {
impl<'a, 't> TSTypeAssertionWithoutTypeAnnotation<'a, 't> {
#[inline]
pub fn span(self) -> &'t Span {
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ASSERTION_SPAN) as *const Span) }
}

#[inline]
pub fn type_annotation(self) -> &'t TSType<'a> {
pub fn expression(self) -> &'t Expression<'a> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_ASSERTION_TYPE_ANNOTATION)
as *const TSType<'a>)
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_ASSERTION_EXPRESSION)
as *const Expression<'a>)
}
}
}

impl<'a, 't> GetAddress for TSTypeAssertionWithoutExpression<'a, 't> {
impl<'a, 't> GetAddress for TSTypeAssertionWithoutTypeAnnotation<'a, 't> {
#[inline]
fn address(&self) -> Address {
Address::from_ptr(self.0)
Expand All @@ -15168,27 +15168,27 @@ impl<'a, 't> GetAddress for TSTypeAssertionWithoutExpression<'a, 't> {

#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct TSTypeAssertionWithoutTypeAnnotation<'a, 't>(
pub struct TSTypeAssertionWithoutExpression<'a, 't>(
pub(crate) *const TSTypeAssertion<'a>,
pub(crate) PhantomData<&'t ()>,
);

impl<'a, 't> TSTypeAssertionWithoutTypeAnnotation<'a, 't> {
impl<'a, 't> TSTypeAssertionWithoutExpression<'a, 't> {
#[inline]
pub fn span(self) -> &'t Span {
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ASSERTION_SPAN) as *const Span) }
}

#[inline]
pub fn expression(self) -> &'t Expression<'a> {
pub fn type_annotation(self) -> &'t TSType<'a> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_ASSERTION_EXPRESSION)
as *const Expression<'a>)
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_ASSERTION_TYPE_ANNOTATION)
as *const TSType<'a>)
}
}
}

impl<'a, 't> GetAddress for TSTypeAssertionWithoutTypeAnnotation<'a, 't> {
impl<'a, 't> GetAddress for TSTypeAssertionWithoutExpression<'a, 't> {
#[inline]
fn address(&self) -> Address {
Address::from_ptr(self.0)
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_traverse/src/generated/scopes_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,8 +1943,8 @@ impl<'a> Visit<'a> for ChildScopeCollector {

#[inline]
fn visit_ts_type_assertion(&mut self, it: &TSTypeAssertion<'a>) {
self.visit_expression(&it.expression);
self.visit_ts_type(&it.type_annotation);
self.visit_expression(&it.expression);
}

#[inline(always)]
Expand Down
Loading
Loading