refactor(ast): store ScopeId in AST nodes (#3302)

Add `scope_id` field to all AST nodes which can constitute a scope (`Program`, `Function`, `BlockStatement` etc).
This commit is contained in:
overlookmotel 2024-05-16 16:21:17 +00:00
parent c8f1f79d27
commit 723a46fcc0
5 changed files with 727 additions and 44 deletions

View file

@ -14,7 +14,7 @@ use oxc_syntax::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
},
reference::{ReferenceFlag, ReferenceId},
scope::ScopeFlags,
scope::{ScopeFlags, ScopeId},
symbol::SymbolId,
};
#[cfg(feature = "serialize")]
@ -46,7 +46,7 @@ export interface FormalParameterRest extends Span {
scope(ScopeFlags::Top),
strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict))
)]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
pub struct Program<'a> {
@ -56,6 +56,29 @@ pub struct Program<'a> {
pub directives: Vec<'a, Directive<'a>>,
pub hashbang: Option<Hashbang<'a>>,
pub body: Vec<'a, Statement<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> Program<'a> {
pub fn new(
span: Span,
source_type: SourceType,
directives: Vec<'a, Directive<'a>>,
hashbang: Option<Hashbang<'a>>,
body: Vec<'a, Statement<'a>>,
) -> Self {
Self { span, source_type, directives, hashbang, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for Program<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.source_type.hash(state);
self.directives.hash(state);
self.hashbang.hash(state);
self.body.hash(state);
}
}
impl<'a> Program<'a> {
@ -1513,13 +1536,27 @@ pub struct Hashbang<'a> {
/// Block Statement
#[visited_node(scope(ScopeFlags::empty()))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct BlockStatement<'a> {
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> BlockStatement<'a> {
pub fn new(span: Span, body: Vec<'a, Statement<'a>>) -> Self {
Self { span, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for BlockStatement<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.body.hash(state);
}
}
/// Declarations and the Variable Statement
@ -1743,7 +1780,7 @@ pub struct WhileStatement<'a> {
scope(ScopeFlags::empty()),
scope_if(self.init.as_ref().is_some_and(ForStatementInit::is_lexical_declaration))
)]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct ForStatement<'a> {
@ -1753,6 +1790,29 @@ pub struct ForStatement<'a> {
pub test: Option<Expression<'a>>,
pub update: Option<Expression<'a>>,
pub body: Statement<'a>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> ForStatement<'a> {
pub fn new(
span: Span,
init: Option<ForStatementInit<'a>>,
test: Option<Expression<'a>>,
update: Option<Expression<'a>>,
body: Statement<'a>,
) -> Self {
Self { span, init, test, update, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for ForStatement<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.init.hash(state);
self.test.hash(state);
self.update.hash(state);
self.body.hash(state);
}
}
inherit_variants! {
@ -1784,7 +1844,7 @@ impl<'a> ForStatementInit<'a> {
/// For-In Statement
#[visited_node(scope(ScopeFlags::empty()), scope_if(self.left.is_lexical_declaration()))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct ForInStatement<'a> {
@ -1793,11 +1853,32 @@ pub struct ForInStatement<'a> {
pub left: ForStatementLeft<'a>,
pub right: Expression<'a>,
pub body: Statement<'a>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> ForInStatement<'a> {
pub fn new(
span: Span,
left: ForStatementLeft<'a>,
right: Expression<'a>,
body: Statement<'a>,
) -> Self {
Self { span, left, right, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for ForInStatement<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.left.hash(state);
self.right.hash(state);
self.body.hash(state);
}
}
/// For-Of Statement
#[visited_node(scope(ScopeFlags::empty()), scope_if(self.left.is_lexical_declaration()))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct ForOfStatement<'a> {
@ -1807,6 +1888,29 @@ pub struct ForOfStatement<'a> {
pub left: ForStatementLeft<'a>,
pub right: Expression<'a>,
pub body: Statement<'a>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> ForOfStatement<'a> {
pub fn new(
span: Span,
r#await: bool,
left: ForStatementLeft<'a>,
right: Expression<'a>,
body: Statement<'a>,
) -> Self {
Self { span, r#await, left, right, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for ForOfStatement<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.r#await.hash(state);
self.left.hash(state);
self.right.hash(state);
self.body.hash(state);
}
}
inherit_variants! {
@ -1883,7 +1987,7 @@ pub struct WithStatement<'a> {
/// Switch Statement
#[visited_node(scope(ScopeFlags::empty()), enter_scope_before(cases))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct SwitchStatement<'a> {
@ -1891,6 +1995,21 @@ pub struct SwitchStatement<'a> {
pub span: Span,
pub discriminant: Expression<'a>,
pub cases: Vec<'a, SwitchCase<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> SwitchStatement<'a> {
pub fn new(span: Span, discriminant: Expression<'a>, cases: Vec<'a, SwitchCase<'a>>) -> Self {
Self { span, discriminant, cases, scope_id: Cell::default() }
}
}
impl<'a> Hash for SwitchStatement<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.discriminant.hash(state);
self.cases.hash(state);
}
}
#[visited_node]
@ -1947,7 +2066,7 @@ pub struct TryStatement<'a> {
}
#[visited_node(scope(ScopeFlags::empty()), scope_if(self.param.is_some()))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct CatchClause<'a> {
@ -1955,6 +2074,25 @@ pub struct CatchClause<'a> {
pub span: Span,
pub param: Option<CatchParameter<'a>>,
pub body: Box<'a, BlockStatement<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> CatchClause<'a> {
pub fn new(
span: Span,
param: Option<CatchParameter<'a>>,
body: Box<'a, BlockStatement<'a>>,
) -> Self {
Self { span, param, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for CatchClause<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.param.hash(state);
self.body.hash(state);
}
}
#[visited_node]
@ -2139,7 +2277,7 @@ pub struct BindingRestElement<'a> {
scope_if(!matches!(ctx.ancestor(2).unwrap(), Ancestor::MethodDefinitionValue(_))),
strict_if(self.body.as_ref().is_some_and(|body| body.has_use_strict_directive()))
)]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub struct Function<'a> {
@ -2171,9 +2309,40 @@ pub struct Function<'a> {
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
/// Valid modifiers: `export`, `default`, `async`
pub modifiers: Modifiers<'a>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> Function<'a> {
#![allow(clippy::too_many_arguments)]
pub fn new(
r#type: FunctionType,
span: Span,
id: Option<BindingIdentifier<'a>>,
generator: bool,
r#async: bool,
this_param: Option<TSThisParameter<'a>>,
params: Box<'a, FormalParameters<'a>>,
body: Option<Box<'a, FunctionBody<'a>>>,
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
modifiers: Modifiers<'a>,
) -> Self {
Self {
r#type,
span,
id,
generator,
r#async,
this_param,
params,
body,
type_parameters,
return_type,
modifiers,
scope_id: Cell::default(),
}
}
pub fn is_typescript_syntax(&self) -> bool {
matches!(
self.r#type,
@ -2203,6 +2372,22 @@ impl<'a> Function<'a> {
}
}
impl<'a> Hash for Function<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.r#type.hash(state);
self.span.hash(state);
self.id.hash(state);
self.generator.hash(state);
self.r#async.hash(state);
self.this_param.hash(state);
self.params.hash(state);
self.body.hash(state);
self.type_parameters.hash(state);
self.return_type.hash(state);
self.modifiers.hash(state);
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub enum FunctionType {
@ -2307,7 +2492,7 @@ impl<'a> FunctionBody<'a> {
/// Arrow Function Definitions
#[visited_node(scope(ScopeFlags::Function | ScopeFlags::Arrow))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
pub struct ArrowFunctionExpression<'a> {
@ -2322,9 +2507,31 @@ pub struct ArrowFunctionExpression<'a> {
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> ArrowFunctionExpression<'a> {
pub fn new(
span: Span,
expression: bool,
r#async: bool,
params: Box<'a, FormalParameters<'a>>,
body: Box<'a, FunctionBody<'a>>,
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
) -> Self {
Self {
span,
expression,
r#async,
params,
body,
type_parameters,
return_type,
scope_id: Cell::default(),
}
}
/// Get expression part of `ArrowFunctionExpression`: `() => expression_part`.
pub fn get_expression(&self) -> Option<&Expression<'a>> {
if self.expression {
@ -2336,6 +2543,18 @@ impl<'a> ArrowFunctionExpression<'a> {
}
}
impl<'a> Hash for ArrowFunctionExpression<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.expression.hash(state);
self.r#async.hash(state);
self.params.hash(state);
self.body.hash(state);
self.type_parameters.hash(state);
self.return_type.hash(state);
}
}
/// Generator Function Definitions
#[visited_node]
#[derive(Debug, Hash)]
@ -2350,7 +2569,7 @@ pub struct YieldExpression<'a> {
/// Class Definitions
#[visited_node(scope(ScopeFlags::StrictMode), enter_scope_before(id))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub struct Class<'a> {
@ -2366,9 +2585,38 @@ pub struct Class<'a> {
pub implements: Option<Vec<'a, TSClassImplements<'a>>>,
/// Valid Modifiers: `export`, `abstract`
pub modifiers: Modifiers<'a>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> Class<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
r#type: ClassType,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
id: Option<BindingIdentifier<'a>>,
super_class: Option<Expression<'a>>,
body: Box<'a, ClassBody<'a>>,
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
super_type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
modifiers: Modifiers<'a>,
) -> Self {
Self {
r#type,
span,
decorators,
id,
super_class,
body,
type_parameters,
super_type_parameters,
implements,
modifiers,
scope_id: Cell::default(),
}
}
pub fn is_expression(&self) -> bool {
self.r#type == ClassType::ClassExpression
}
@ -2386,6 +2634,21 @@ impl<'a> Class<'a> {
}
}
impl<'a> Hash for Class<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.r#type.hash(state);
self.span.hash(state);
self.decorators.hash(state);
self.id.hash(state);
self.super_class.hash(state);
self.body.hash(state);
self.type_parameters.hash(state);
self.super_type_parameters.hash(state);
self.implements.hash(state);
self.modifiers.hash(state);
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub enum ClassType {
@ -2613,13 +2876,27 @@ impl<'a> PrivateIdentifier<'a> {
}
#[visited_node(scope(ScopeFlags::ClassStaticBlock))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct StaticBlock<'a> {
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> StaticBlock<'a> {
pub fn new(span: Span, body: Vec<'a, Statement<'a>>) -> Self {
Self { span, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for StaticBlock<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.body.hash(state);
}
}
#[visited_node]

View file

@ -9,9 +9,12 @@
// Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]`
#![allow(non_snake_case)]
use std::{cell::Cell, hash::Hash};
use oxc_allocator::{Box, Vec};
use oxc_ast_macros::visited_node;
use oxc_span::{Atom, GetSpan, Span};
use oxc_syntax::scope::ScopeId;
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
@ -44,7 +47,7 @@ pub struct TSThisParameter<'a> {
///
/// `const_opt`enum`BindingIdentifier`{`EnumBody_opt`}
#[visited_node(scope(ScopeFlags::empty()), enter_scope_before(members))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub struct TSEnumDeclaration<'a> {
@ -54,6 +57,27 @@ pub struct TSEnumDeclaration<'a> {
pub members: Vec<'a, TSEnumMember<'a>>,
/// Valid Modifiers: `const`, `export`, `declare`
pub modifiers: Modifiers<'a>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> TSEnumDeclaration<'a> {
pub fn new(
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
modifiers: Modifiers<'a>,
) -> Self {
Self { span, id, members, modifiers, scope_id: Cell::default() }
}
}
impl<'a> Hash for TSEnumDeclaration<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.id.hash(state);
self.members.hash(state);
self.modifiers.hash(state);
}
}
#[visited_node]
@ -598,7 +622,7 @@ pub struct TSTypeParameterInstantiation<'a> {
}
#[visited_node(scope(ScopeFlags::empty()))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
pub struct TSTypeParameter<'a> {
@ -610,6 +634,33 @@ pub struct TSTypeParameter<'a> {
pub r#in: bool,
pub out: bool,
pub r#const: bool,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> TSTypeParameter<'a> {
pub fn new(
span: Span,
name: BindingIdentifier<'a>,
constraint: Option<TSType<'a>>,
default: Option<TSType<'a>>,
r#in: bool,
out: bool,
r#const: bool,
) -> Self {
Self { span, name, constraint, default, r#in, out, r#const, scope_id: Cell::default() }
}
}
impl<'a> Hash for TSTypeParameter<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.name.hash(state);
self.constraint.hash(state);
self.default.hash(state);
self.r#in.hash(state);
self.out.hash(state);
self.r#const.hash(state);
}
}
#[visited_node]
@ -883,13 +934,27 @@ pub enum TSModuleDeclarationBody<'a> {
}
#[visited_node(scope(ScopeFlags::TsModuleBlock))]
#[derive(Debug, Hash)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))]
pub struct TSModuleBlock<'a> {
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
impl<'a> TSModuleBlock<'a> {
pub fn new(span: Span, body: Vec<'a, Statement<'a>>) -> Self {
Self { span, body, scope_id: Cell::default() }
}
}
impl<'a> Hash for TSModuleBlock<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.span.hash(state);
self.body.hash(state);
}
}
#[visited_node]

View file

@ -128,7 +128,7 @@ impl<'a> AstBuilder<'a> {
hashbang: Option<Hashbang<'a>>,
body: Vec<'a, Statement<'a>>,
) -> Program<'a> {
Program { span, source_type, directives, hashbang, body }
Program::new(span, source_type, directives, hashbang, body)
}
/* ---------- Constructors ---------- */
@ -280,14 +280,12 @@ impl<'a> AstBuilder<'a> {
#[inline]
pub fn block(&self, span: Span, body: Vec<'a, Statement<'a>>) -> Box<'a, BlockStatement<'a>> {
self.alloc(BlockStatement { span, body })
self.alloc(BlockStatement::new(span, body))
}
#[inline]
pub fn block_statement(&self, block: Box<'a, BlockStatement<'a>>) -> Statement<'a> {
Statement::BlockStatement(
self.alloc(BlockStatement { span: block.span, body: block.unbox().body }),
)
Statement::BlockStatement(self.block(block.span, block.unbox().body))
}
#[inline]
@ -347,7 +345,7 @@ impl<'a> AstBuilder<'a> {
right: Expression<'a>,
body: Statement<'a>,
) -> Statement<'a> {
Statement::ForInStatement(self.alloc(ForInStatement { span, left, right, body }))
Statement::ForInStatement(self.alloc(ForInStatement::new(span, left, right, body)))
}
#[inline]
@ -359,7 +357,7 @@ impl<'a> AstBuilder<'a> {
right: Expression<'a>,
body: Statement<'a>,
) -> Statement<'a> {
Statement::ForOfStatement(self.alloc(ForOfStatement { span, r#await, left, right, body }))
Statement::ForOfStatement(self.alloc(ForOfStatement::new(span, r#await, left, right, body)))
}
#[inline]
@ -371,7 +369,7 @@ impl<'a> AstBuilder<'a> {
update: Option<Expression<'a>>,
body: Statement<'a>,
) -> Statement<'a> {
Statement::ForStatement(self.alloc(ForStatement { span, init, test, update, body }))
Statement::ForStatement(self.alloc(ForStatement::new(span, init, test, update, body)))
}
#[inline]
@ -407,7 +405,7 @@ impl<'a> AstBuilder<'a> {
discriminant: Expression<'a>,
cases: Vec<'a, SwitchCase<'a>>,
) -> Statement<'a> {
Statement::SwitchStatement(self.alloc(SwitchStatement { span, discriminant, cases }))
Statement::SwitchStatement(self.alloc(SwitchStatement::new(span, discriminant, cases)))
}
#[inline]
@ -443,7 +441,7 @@ impl<'a> AstBuilder<'a> {
param: Option<CatchParameter<'a>>,
body: Box<'a, BlockStatement<'a>>,
) -> Box<'a, CatchClause<'a>> {
self.alloc(CatchClause { span, param, body })
self.alloc(CatchClause::new(span, param, body))
}
#[inline]
@ -509,7 +507,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
) -> Expression<'a> {
Expression::ArrowFunctionExpression(self.alloc(ArrowFunctionExpression {
Expression::ArrowFunctionExpression(self.alloc(ArrowFunctionExpression::new(
span,
expression,
r#async,
@ -517,7 +515,7 @@ impl<'a> AstBuilder<'a> {
body,
type_parameters,
return_type,
}))
)))
}
#[inline]
@ -993,7 +991,7 @@ impl<'a> AstBuilder<'a> {
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
modifiers: Modifiers<'a>,
) -> Box<'a, Function<'a>> {
self.alloc(Function {
self.alloc(Function::new(
r#type,
span,
id,
@ -1005,7 +1003,7 @@ impl<'a> AstBuilder<'a> {
type_parameters,
return_type,
modifiers,
})
))
}
#[inline]
@ -1034,7 +1032,7 @@ impl<'a> AstBuilder<'a> {
decorators: Vec<'a, Decorator<'a>>,
modifiers: Modifiers<'a>,
) -> Box<'a, Class<'a>> {
self.alloc(Class {
self.alloc(Class::new(
r#type,
span,
decorators,
@ -1045,7 +1043,7 @@ impl<'a> AstBuilder<'a> {
super_type_parameters,
implements,
modifiers,
})
))
}
#[inline]
@ -1064,7 +1062,7 @@ impl<'a> AstBuilder<'a> {
#[inline]
pub fn static_block(&self, span: Span, body: Vec<'a, Statement<'a>>) -> ClassElement<'a> {
ClassElement::StaticBlock(self.alloc(StaticBlock { span, body }))
ClassElement::StaticBlock(self.alloc(StaticBlock::new(span, body)))
}
#[inline]
@ -1598,7 +1596,7 @@ impl<'a> AstBuilder<'a> {
out: bool,
r#const: bool,
) -> TSTypeParameter<'a> {
TSTypeParameter { span, name, constraint, default, r#in, out, r#const }
TSTypeParameter::new(span, name, constraint, default, r#in, out, r#const)
}
#[inline]
@ -1736,7 +1734,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
body: Vec<'a, Statement<'a>>,
) -> Box<'a, TSModuleBlock<'a>> {
self.alloc(TSModuleBlock { span, body })
self.alloc(TSModuleBlock::new(span, body))
}
#[inline]
@ -1853,12 +1851,9 @@ impl<'a> AstBuilder<'a> {
members: Vec<'a, TSEnumMember<'a>>,
modifiers: Modifiers<'a>,
) -> Declaration<'a> {
Declaration::TSEnumDeclaration(self.alloc(TSEnumDeclaration {
span,
id,
members,
modifiers,
}))
Declaration::TSEnumDeclaration(
self.alloc(TSEnumDeclaration::new(span, id, members, modifiers)),
)
}
#[inline]

View file

@ -106,14 +106,19 @@ export default function generateAncestorsCode(types) {
clippy::cast_ptr_alignment
)]
use std::cell::Cell;
use memoffset::offset_of;
use oxc_allocator::{Box, Vec};
#[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*;
use oxc_span::{Atom, SourceType, Span};
use oxc_syntax::operator::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
use oxc_syntax::{
operator::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
},
scope::ScopeId,
};
/// Type of [\`Ancestor\`].

View file

@ -8,14 +8,19 @@
clippy::cast_ptr_alignment
)]
use std::cell::Cell;
use memoffset::offset_of;
use oxc_allocator::{Box, Vec};
#[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*;
use oxc_span::{Atom, SourceType, Span};
use oxc_syntax::operator::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
use oxc_syntax::{
operator::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
},
scope::ScopeId,
};
/// Type of [`Ancestor`].
@ -2156,6 +2161,7 @@ pub(crate) const OFFSET_PROGRAM_SOURCE_TYPE: usize = offset_of!(Program, source_
pub(crate) const OFFSET_PROGRAM_DIRECTIVES: usize = offset_of!(Program, directives);
pub(crate) const OFFSET_PROGRAM_HASHBANG: usize = offset_of!(Program, hashbang);
pub(crate) const OFFSET_PROGRAM_BODY: usize = offset_of!(Program, body);
pub(crate) const OFFSET_PROGRAM_SCOPE_ID: usize = offset_of!(Program, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -2185,6 +2191,13 @@ impl<'a> ProgramWithoutDirectives<'a> {
&*((self.0 as *const u8).add(OFFSET_PROGRAM_BODY) as *const Vec<'a, Statement<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_PROGRAM_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -2216,6 +2229,13 @@ impl<'a> ProgramWithoutHashbang<'a> {
&*((self.0 as *const u8).add(OFFSET_PROGRAM_BODY) as *const Vec<'a, Statement<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_PROGRAM_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -2247,6 +2267,13 @@ impl<'a> ProgramWithoutBody<'a> {
&*((self.0 as *const u8).add(OFFSET_PROGRAM_HASHBANG) as *const Option<Hashbang<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_PROGRAM_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_ARRAY_EXPRESSION_SPAN: usize = offset_of!(ArrayExpression, span);
@ -3780,6 +3807,7 @@ impl<'a> DirectiveWithoutExpression<'a> {
pub(crate) const OFFSET_BLOCK_STATEMENT_SPAN: usize = offset_of!(BlockStatement, span);
pub(crate) const OFFSET_BLOCK_STATEMENT_BODY: usize = offset_of!(BlockStatement, body);
pub(crate) const OFFSET_BLOCK_STATEMENT_SCOPE_ID: usize = offset_of!(BlockStatement, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -3790,6 +3818,14 @@ impl<'a> BlockStatementWithoutBody<'a> {
pub fn span(&self) -> &Span {
unsafe { &*((self.0 as *const u8).add(OFFSET_BLOCK_STATEMENT_SPAN) as *const Span) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_BLOCK_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_VARIABLE_DECLARATION_SPAN: usize = offset_of!(VariableDeclaration, span);
@ -4096,6 +4132,7 @@ pub(crate) const OFFSET_FOR_STATEMENT_INIT: usize = offset_of!(ForStatement, ini
pub(crate) const OFFSET_FOR_STATEMENT_TEST: usize = offset_of!(ForStatement, test);
pub(crate) const OFFSET_FOR_STATEMENT_UPDATE: usize = offset_of!(ForStatement, update);
pub(crate) const OFFSET_FOR_STATEMENT_BODY: usize = offset_of!(ForStatement, body);
pub(crate) const OFFSET_FOR_STATEMENT_SCOPE_ID: usize = offset_of!(ForStatement, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -4127,6 +4164,14 @@ impl<'a> ForStatementWithoutInit<'a> {
pub fn body(&self) -> &Statement<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_BODY) as *const Statement<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4159,6 +4204,14 @@ impl<'a> ForStatementWithoutTest<'a> {
pub fn body(&self) -> &Statement<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_BODY) as *const Statement<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4191,6 +4244,14 @@ impl<'a> ForStatementWithoutUpdate<'a> {
pub fn body(&self) -> &Statement<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_BODY) as *const Statement<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4226,12 +4287,21 @@ impl<'a> ForStatementWithoutBody<'a> {
as *const Option<Expression<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_FOR_IN_STATEMENT_SPAN: usize = offset_of!(ForInStatement, span);
pub(crate) const OFFSET_FOR_IN_STATEMENT_LEFT: usize = offset_of!(ForInStatement, left);
pub(crate) const OFFSET_FOR_IN_STATEMENT_RIGHT: usize = offset_of!(ForInStatement, right);
pub(crate) const OFFSET_FOR_IN_STATEMENT_BODY: usize = offset_of!(ForInStatement, body);
pub(crate) const OFFSET_FOR_IN_STATEMENT_SCOPE_ID: usize = offset_of!(ForInStatement, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -4256,6 +4326,14 @@ impl<'a> ForInStatementWithoutLeft<'a> {
&*((self.0 as *const u8).add(OFFSET_FOR_IN_STATEMENT_BODY) as *const Statement<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_IN_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4282,6 +4360,14 @@ impl<'a> ForInStatementWithoutRight<'a> {
&*((self.0 as *const u8).add(OFFSET_FOR_IN_STATEMENT_BODY) as *const Statement<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_IN_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4308,6 +4394,14 @@ impl<'a> ForInStatementWithoutBody<'a> {
&*((self.0 as *const u8).add(OFFSET_FOR_IN_STATEMENT_RIGHT) as *const Expression<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_IN_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_FOR_OF_STATEMENT_SPAN: usize = offset_of!(ForOfStatement, span);
@ -4315,6 +4409,7 @@ pub(crate) const OFFSET_FOR_OF_STATEMENT_AWAIT: usize = offset_of!(ForOfStatemen
pub(crate) const OFFSET_FOR_OF_STATEMENT_LEFT: usize = offset_of!(ForOfStatement, left);
pub(crate) const OFFSET_FOR_OF_STATEMENT_RIGHT: usize = offset_of!(ForOfStatement, right);
pub(crate) const OFFSET_FOR_OF_STATEMENT_BODY: usize = offset_of!(ForOfStatement, body);
pub(crate) const OFFSET_FOR_OF_STATEMENT_SCOPE_ID: usize = offset_of!(ForOfStatement, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -4344,6 +4439,14 @@ impl<'a> ForOfStatementWithoutLeft<'a> {
&*((self.0 as *const u8).add(OFFSET_FOR_OF_STATEMENT_BODY) as *const Statement<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_OF_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4375,6 +4478,14 @@ impl<'a> ForOfStatementWithoutRight<'a> {
&*((self.0 as *const u8).add(OFFSET_FOR_OF_STATEMENT_BODY) as *const Statement<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_OF_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4406,6 +4517,14 @@ impl<'a> ForOfStatementWithoutBody<'a> {
&*((self.0 as *const u8).add(OFFSET_FOR_OF_STATEMENT_RIGHT) as *const Expression<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FOR_OF_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_CONTINUE_STATEMENT_SPAN: usize = offset_of!(ContinueStatement, span);
@ -4492,6 +4611,7 @@ pub(crate) const OFFSET_SWITCH_STATEMENT_SPAN: usize = offset_of!(SwitchStatemen
pub(crate) const OFFSET_SWITCH_STATEMENT_DISCRIMINANT: usize =
offset_of!(SwitchStatement, discriminant);
pub(crate) const OFFSET_SWITCH_STATEMENT_CASES: usize = offset_of!(SwitchStatement, cases);
pub(crate) const OFFSET_SWITCH_STATEMENT_SCOPE_ID: usize = offset_of!(SwitchStatement, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -4510,6 +4630,14 @@ impl<'a> SwitchStatementWithoutDiscriminant<'a> {
as *const Vec<'a, SwitchCase<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_SWITCH_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4529,6 +4657,14 @@ impl<'a> SwitchStatementWithoutCases<'a> {
as *const Expression<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_SWITCH_STATEMENT_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_SWITCH_CASE_SPAN: usize = offset_of!(SwitchCase, span);
@ -4716,6 +4852,7 @@ impl<'a> TryStatementWithoutFinalizer<'a> {
pub(crate) const OFFSET_CATCH_CLAUSE_SPAN: usize = offset_of!(CatchClause, span);
pub(crate) const OFFSET_CATCH_CLAUSE_PARAM: usize = offset_of!(CatchClause, param);
pub(crate) const OFFSET_CATCH_CLAUSE_BODY: usize = offset_of!(CatchClause, body);
pub(crate) const OFFSET_CATCH_CLAUSE_SCOPE_ID: usize = offset_of!(CatchClause, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -4734,6 +4871,14 @@ impl<'a> CatchClauseWithoutParam<'a> {
as *const Box<'a, BlockStatement<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CATCH_CLAUSE_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -4753,6 +4898,14 @@ impl<'a> CatchClauseWithoutBody<'a> {
as *const Option<CatchParameter<'a>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CATCH_CLAUSE_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_CATCH_PARAMETER_SPAN: usize = offset_of!(CatchParameter, span);
@ -5026,6 +5179,7 @@ pub(crate) const OFFSET_FUNCTION_BODY: usize = offset_of!(Function, body);
pub(crate) const OFFSET_FUNCTION_TYPE_PARAMETERS: usize = offset_of!(Function, type_parameters);
pub(crate) const OFFSET_FUNCTION_RETURN_TYPE: usize = offset_of!(Function, return_type);
pub(crate) const OFFSET_FUNCTION_MODIFIERS: usize = offset_of!(Function, modifiers);
pub(crate) const OFFSET_FUNCTION_SCOPE_ID: usize = offset_of!(Function, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -5096,6 +5250,13 @@ impl<'a> FunctionWithoutId<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FUNCTION_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FUNCTION_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5167,6 +5328,13 @@ impl<'a> FunctionWithoutThisParam<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FUNCTION_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FUNCTION_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5238,6 +5406,13 @@ impl<'a> FunctionWithoutParams<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FUNCTION_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FUNCTION_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5309,6 +5484,13 @@ impl<'a> FunctionWithoutBody<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FUNCTION_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FUNCTION_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5380,6 +5562,13 @@ impl<'a> FunctionWithoutTypeParameters<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FUNCTION_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FUNCTION_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5451,6 +5640,13 @@ impl<'a> FunctionWithoutReturnType<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_FUNCTION_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_FUNCTION_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_FORMAL_PARAMETERS_SPAN: usize = offset_of!(FormalParameters, span);
@ -5651,6 +5847,8 @@ pub(crate) const OFFSET_ARROW_FUNCTION_EXPRESSION_TYPE_PARAMETERS: usize =
offset_of!(ArrowFunctionExpression, type_parameters);
pub(crate) const OFFSET_ARROW_FUNCTION_EXPRESSION_RETURN_TYPE: usize =
offset_of!(ArrowFunctionExpression, return_type);
pub(crate) const OFFSET_ARROW_FUNCTION_EXPRESSION_SCOPE_ID: usize =
offset_of!(ArrowFunctionExpression, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -5702,6 +5900,14 @@ impl<'a> ArrowFunctionExpressionWithoutParams<'a> {
as *const Option<Box<'a, TSTypeAnnotation<'a>>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_ARROW_FUNCTION_EXPRESSION_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5754,6 +5960,14 @@ impl<'a> ArrowFunctionExpressionWithoutBody<'a> {
as *const Option<Box<'a, TSTypeAnnotation<'a>>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_ARROW_FUNCTION_EXPRESSION_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5808,6 +6022,14 @@ impl<'a> ArrowFunctionExpressionWithoutTypeParameters<'a> {
as *const Option<Box<'a, TSTypeAnnotation<'a>>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_ARROW_FUNCTION_EXPRESSION_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -5862,6 +6084,14 @@ impl<'a> ArrowFunctionExpressionWithoutReturnType<'a> {
as *const Option<Box<'a, TSTypeParameterDeclaration<'a>>>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_ARROW_FUNCTION_EXPRESSION_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_YIELD_EXPRESSION_SPAN: usize = offset_of!(YieldExpression, span);
@ -5895,6 +6125,7 @@ pub(crate) const OFFSET_CLASS_SUPER_TYPE_PARAMETERS: usize =
offset_of!(Class, super_type_parameters);
pub(crate) const OFFSET_CLASS_IMPLEMENTS: usize = offset_of!(Class, implements);
pub(crate) const OFFSET_CLASS_MODIFIERS: usize = offset_of!(Class, modifiers);
pub(crate) const OFFSET_CLASS_SCOPE_ID: usize = offset_of!(Class, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -5958,6 +6189,13 @@ impl<'a> ClassWithoutDecorators<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -6022,6 +6260,13 @@ impl<'a> ClassWithoutId<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -6086,6 +6331,13 @@ impl<'a> ClassWithoutSuperClass<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -6152,6 +6404,13 @@ impl<'a> ClassWithoutBody<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -6215,6 +6474,13 @@ impl<'a> ClassWithoutTypeParameters<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -6278,6 +6544,13 @@ impl<'a> ClassWithoutSuperTypeParameters<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -6341,6 +6614,13 @@ impl<'a> ClassWithoutImplements<'a> {
pub fn modifiers(&self) -> &Modifiers<'a> {
unsafe { &*((self.0 as *const u8).add(OFFSET_CLASS_MODIFIERS) as *const Modifiers<'a>) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_SCOPE_ID) as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_CLASS_BODY_SPAN: usize = offset_of!(ClassBody, span);
@ -6951,6 +7231,7 @@ impl<'a> PropertyDefinitionWithoutDecorators<'a> {
pub(crate) const OFFSET_STATIC_BLOCK_SPAN: usize = offset_of!(StaticBlock, span);
pub(crate) const OFFSET_STATIC_BLOCK_BODY: usize = offset_of!(StaticBlock, body);
pub(crate) const OFFSET_STATIC_BLOCK_SCOPE_ID: usize = offset_of!(StaticBlock, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -6961,6 +7242,14 @@ impl<'a> StaticBlockWithoutBody<'a> {
pub fn span(&self) -> &Span {
unsafe { &*((self.0 as *const u8).add(OFFSET_STATIC_BLOCK_SPAN) as *const Span) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_STATIC_BLOCK_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_ACCESSOR_PROPERTY_TYPE: usize = offset_of!(AccessorProperty, r#type);
@ -8341,6 +8630,8 @@ pub(crate) const OFFSET_TS_ENUM_DECLARATION_ID: usize = offset_of!(TSEnumDeclara
pub(crate) const OFFSET_TS_ENUM_DECLARATION_MEMBERS: usize = offset_of!(TSEnumDeclaration, members);
pub(crate) const OFFSET_TS_ENUM_DECLARATION_MODIFIERS: usize =
offset_of!(TSEnumDeclaration, modifiers);
pub(crate) const OFFSET_TS_ENUM_DECLARATION_SCOPE_ID: usize =
offset_of!(TSEnumDeclaration, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -8367,6 +8658,14 @@ impl<'a> TSEnumDeclarationWithoutId<'a> {
as *const Modifiers<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_ENUM_DECLARATION_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -8394,6 +8693,14 @@ impl<'a> TSEnumDeclarationWithoutMembers<'a> {
as *const Modifiers<'a>)
}
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_ENUM_DECLARATION_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_TS_ENUM_MEMBER_SPAN: usize = offset_of!(TSEnumMember, span);
@ -8939,6 +9246,7 @@ pub(crate) const OFFSET_TS_TYPE_PARAMETER_DEFAULT: usize = offset_of!(TSTypePara
pub(crate) const OFFSET_TS_TYPE_PARAMETER_IN: usize = offset_of!(TSTypeParameter, r#in);
pub(crate) const OFFSET_TS_TYPE_PARAMETER_OUT: usize = offset_of!(TSTypeParameter, out);
pub(crate) const OFFSET_TS_TYPE_PARAMETER_CONST: usize = offset_of!(TSTypeParameter, r#const);
pub(crate) const OFFSET_TS_TYPE_PARAMETER_SCOPE_ID: usize = offset_of!(TSTypeParameter, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -8980,6 +9288,14 @@ impl<'a> TSTypeParameterWithoutName<'a> {
pub fn r#const(&self) -> &bool {
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_CONST) as *const bool) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -9022,6 +9338,14 @@ impl<'a> TSTypeParameterWithoutConstraint<'a> {
pub fn r#const(&self) -> &bool {
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_CONST) as *const bool) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
#[repr(transparent)]
@ -9064,6 +9388,14 @@ impl<'a> TSTypeParameterWithoutDefault<'a> {
pub fn r#const(&self) -> &bool {
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_CONST) as *const bool) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_TYPE_PARAMETER_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_TS_TYPE_PARAMETER_DECLARATION_SPAN: usize =
@ -10403,6 +10735,7 @@ impl<'a> TSModuleDeclarationWithoutBody<'a> {
pub(crate) const OFFSET_TS_MODULE_BLOCK_SPAN: usize = offset_of!(TSModuleBlock, span);
pub(crate) const OFFSET_TS_MODULE_BLOCK_BODY: usize = offset_of!(TSModuleBlock, body);
pub(crate) const OFFSET_TS_MODULE_BLOCK_SCOPE_ID: usize = offset_of!(TSModuleBlock, scope_id);
#[repr(transparent)]
#[derive(Debug)]
@ -10413,6 +10746,14 @@ impl<'a> TSModuleBlockWithoutBody<'a> {
pub fn span(&self) -> &Span {
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_MODULE_BLOCK_SPAN) as *const Span) }
}
#[inline]
pub fn scope_id(&self) -> &Cell<Option<ScopeId>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_BLOCK_SCOPE_ID)
as *const Cell<Option<ScopeId>>)
}
}
}
pub(crate) const OFFSET_TS_TYPE_LITERAL_SPAN: usize = offset_of!(TSTypeLiteral, span);