mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(ast,parser): add definite flag to AccessorProperty node (#5182)
This commit is contained in:
parent
7dfd51a62b
commit
49cd5db54f
7 changed files with 41 additions and 1 deletions
|
|
@ -2281,6 +2281,8 @@ pub struct AccessorProperty<'a> {
|
|||
pub computed: bool,
|
||||
/// Property was declared with a `static` modifier
|
||||
pub r#static: bool,
|
||||
/// Property has a `!` after its key.
|
||||
pub definite: bool,
|
||||
/// Type annotation on the property.
|
||||
///
|
||||
/// Will only ever be [`Some`] for TypeScript files.
|
||||
|
|
|
|||
|
|
@ -696,6 +696,7 @@ const _: () = {
|
|||
assert!(offset_of!(AccessorProperty, value) == 64usize);
|
||||
assert!(offset_of!(AccessorProperty, computed) == 80usize);
|
||||
assert!(offset_of!(AccessorProperty, r#static) == 81usize);
|
||||
assert!(offset_of!(AccessorProperty, definite) == 82usize);
|
||||
assert!(offset_of!(AccessorProperty, type_annotation) == 88usize);
|
||||
|
||||
assert!(size_of::<ImportExpression>() == 56usize);
|
||||
|
|
@ -2101,6 +2102,7 @@ const _: () = {
|
|||
assert!(offset_of!(AccessorProperty, value) == 36usize);
|
||||
assert!(offset_of!(AccessorProperty, computed) == 44usize);
|
||||
assert!(offset_of!(AccessorProperty, r#static) == 45usize);
|
||||
assert!(offset_of!(AccessorProperty, definite) == 46usize);
|
||||
assert!(offset_of!(AccessorProperty, type_annotation) == 48usize);
|
||||
|
||||
assert!(size_of::<ImportExpression>() == 32usize);
|
||||
|
|
|
|||
|
|
@ -6496,6 +6496,7 @@ impl<'a> AstBuilder<'a> {
|
|||
/// - value: Initialized value in the declaration, if present.
|
||||
/// - computed: Property was declared with a computed key
|
||||
/// - r#static: Property was declared with a `static` modifier
|
||||
/// - definite: Property has a `!` after its key.
|
||||
/// - type_annotation: Type annotation on the property.
|
||||
#[inline]
|
||||
pub fn class_element_accessor_property<T1>(
|
||||
|
|
@ -6507,6 +6508,7 @@ impl<'a> AstBuilder<'a> {
|
|||
value: Option<Expression<'a>>,
|
||||
computed: bool,
|
||||
r#static: bool,
|
||||
definite: bool,
|
||||
type_annotation: T1,
|
||||
) -> ClassElement<'a>
|
||||
where
|
||||
|
|
@ -6520,6 +6522,7 @@ impl<'a> AstBuilder<'a> {
|
|||
value,
|
||||
computed,
|
||||
r#static,
|
||||
definite,
|
||||
type_annotation,
|
||||
)))
|
||||
}
|
||||
|
|
@ -7071,6 +7074,7 @@ impl<'a> AstBuilder<'a> {
|
|||
/// - value: Initialized value in the declaration, if present.
|
||||
/// - computed: Property was declared with a computed key
|
||||
/// - r#static: Property was declared with a `static` modifier
|
||||
/// - definite: Property has a `!` after its key.
|
||||
/// - type_annotation: Type annotation on the property.
|
||||
#[inline]
|
||||
pub fn accessor_property<T1>(
|
||||
|
|
@ -7082,6 +7086,7 @@ impl<'a> AstBuilder<'a> {
|
|||
value: Option<Expression<'a>>,
|
||||
computed: bool,
|
||||
r#static: bool,
|
||||
definite: bool,
|
||||
type_annotation: T1,
|
||||
) -> AccessorProperty<'a>
|
||||
where
|
||||
|
|
@ -7095,6 +7100,7 @@ impl<'a> AstBuilder<'a> {
|
|||
value,
|
||||
computed,
|
||||
r#static,
|
||||
definite,
|
||||
type_annotation: type_annotation.into_in(self.allocator),
|
||||
}
|
||||
}
|
||||
|
|
@ -7111,6 +7117,7 @@ impl<'a> AstBuilder<'a> {
|
|||
/// - value: Initialized value in the declaration, if present.
|
||||
/// - computed: Property was declared with a computed key
|
||||
/// - r#static: Property was declared with a `static` modifier
|
||||
/// - definite: Property has a `!` after its key.
|
||||
/// - type_annotation: Type annotation on the property.
|
||||
#[inline]
|
||||
pub fn alloc_accessor_property<T1>(
|
||||
|
|
@ -7122,6 +7129,7 @@ impl<'a> AstBuilder<'a> {
|
|||
value: Option<Expression<'a>>,
|
||||
computed: bool,
|
||||
r#static: bool,
|
||||
definite: bool,
|
||||
type_annotation: T1,
|
||||
) -> Box<'a, AccessorProperty<'a>>
|
||||
where
|
||||
|
|
@ -7136,6 +7144,7 @@ impl<'a> AstBuilder<'a> {
|
|||
value,
|
||||
computed,
|
||||
r#static,
|
||||
definite,
|
||||
type_annotation,
|
||||
),
|
||||
self.allocator,
|
||||
|
|
|
|||
|
|
@ -1954,6 +1954,7 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for AccessorProperty<'old_alloc
|
|||
value: self.value.clone_in(allocator),
|
||||
computed: self.computed.clone_in(allocator),
|
||||
r#static: self.r#static.clone_in(allocator),
|
||||
definite: self.definite.clone_in(allocator),
|
||||
type_annotation: self.type_annotation.clone_in(allocator),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -469,6 +469,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
None,
|
||||
property.computed,
|
||||
property.r#static,
|
||||
property.definite,
|
||||
// SAFETY: `ast.copy` is unsound! We need to fix.
|
||||
unsafe { self.ast.copy(&property.type_annotation) },
|
||||
);
|
||||
|
|
|
|||
|
|
@ -294,7 +294,8 @@ impl<'a> ParserImpl<'a> {
|
|||
if optional {
|
||||
self.error(diagnostics::optional_accessor_property(optional_span));
|
||||
}
|
||||
self.parse_class_accessor_property(span, key, computed, r#static, r#abstract).map(Some)
|
||||
self.parse_class_accessor_property(span, key, computed, r#static, r#abstract, definite)
|
||||
.map(Some)
|
||||
} else if self.at(Kind::LParen) || self.at(Kind::LAngle) || r#async || generator {
|
||||
// LAngle for start of type parameters `foo<T>`
|
||||
// ^
|
||||
|
|
@ -483,6 +484,7 @@ impl<'a> ParserImpl<'a> {
|
|||
}
|
||||
|
||||
/// <https://github.com/tc39/proposal-decorators>
|
||||
#[allow(clippy::fn_params_excessive_bools)]
|
||||
fn parse_class_accessor_property(
|
||||
&mut self,
|
||||
span: Span,
|
||||
|
|
@ -490,6 +492,7 @@ impl<'a> ParserImpl<'a> {
|
|||
computed: bool,
|
||||
r#static: bool,
|
||||
r#abstract: bool,
|
||||
definite: bool,
|
||||
) -> Result<ClassElement<'a>> {
|
||||
let type_annotation =
|
||||
if self.ts_enabled() { self.parse_ts_type_annotation()? } else { None };
|
||||
|
|
@ -510,6 +513,7 @@ impl<'a> ParserImpl<'a> {
|
|||
value,
|
||||
computed,
|
||||
r#static,
|
||||
definite,
|
||||
type_annotation,
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7319,6 +7319,7 @@ pub(crate) const OFFSET_ACCESSOR_PROPERTY_KEY: usize = offset_of!(AccessorProper
|
|||
pub(crate) const OFFSET_ACCESSOR_PROPERTY_VALUE: usize = offset_of!(AccessorProperty, value);
|
||||
pub(crate) const OFFSET_ACCESSOR_PROPERTY_COMPUTED: usize = offset_of!(AccessorProperty, computed);
|
||||
pub(crate) const OFFSET_ACCESSOR_PROPERTY_STATIC: usize = offset_of!(AccessorProperty, r#static);
|
||||
pub(crate) const OFFSET_ACCESSOR_PROPERTY_DEFINITE: usize = offset_of!(AccessorProperty, definite);
|
||||
pub(crate) const OFFSET_ACCESSOR_PROPERTY_TYPE_ANNOTATION: usize =
|
||||
offset_of!(AccessorProperty, type_annotation);
|
||||
|
||||
|
|
@ -7365,6 +7366,11 @@ impl<'a> AccessorPropertyWithoutDecorators<'a> {
|
|||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn definite(&self) -> &bool {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn type_annotation(&self) -> &Option<Box<'a, TSTypeAnnotation<'a>>> {
|
||||
unsafe {
|
||||
|
|
@ -7418,6 +7424,11 @@ impl<'a> AccessorPropertyWithoutKey<'a> {
|
|||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn definite(&self) -> &bool {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn type_annotation(&self) -> &Option<Box<'a, TSTypeAnnotation<'a>>> {
|
||||
unsafe {
|
||||
|
|
@ -7470,6 +7481,11 @@ impl<'a> AccessorPropertyWithoutValue<'a> {
|
|||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn definite(&self) -> &bool {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn type_annotation(&self) -> &Option<Box<'a, TSTypeAnnotation<'a>>> {
|
||||
unsafe {
|
||||
|
|
@ -7529,6 +7545,11 @@ impl<'a> AccessorPropertyWithoutTypeAnnotation<'a> {
|
|||
pub fn r#static(&self) -> &bool {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn definite(&self) -> &bool {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const OFFSET_IMPORT_EXPRESSION_SPAN: usize = offset_of!(ImportExpression, span);
|
||||
|
|
|
|||
Loading…
Reference in a new issue