mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(transformer): import oxc_allocator::Vec as ArenaVec (#6998)
Part of #6996.
This commit is contained in:
parent
63e8bfeeec
commit
fc1af2e9da
11 changed files with 68 additions and 40 deletions
|
|
@ -70,7 +70,7 @@ use std::{borrow::Cow, cell::RefCell};
|
|||
use rustc_hash::FxHashMap;
|
||||
use serde::Deserialize;
|
||||
|
||||
use oxc_allocator::{String as ArenaString, Vec};
|
||||
use oxc_allocator::{String as ArenaString, Vec as ArenaVec};
|
||||
use oxc_ast::ast::{Argument, CallExpression, Expression, TSTypeParameterInstantiation};
|
||||
use oxc_semantic::{ReferenceFlags, SymbolFlags};
|
||||
use oxc_span::{Atom, SPAN};
|
||||
|
|
@ -175,7 +175,7 @@ impl<'a> TransformCtx<'a> {
|
|||
pub fn helper_call(
|
||||
&self,
|
||||
helper: Helper,
|
||||
arguments: Vec<'a, Argument<'a>>,
|
||||
arguments: ArenaVec<'a, Argument<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> CallExpression<'a> {
|
||||
let callee = self.helper_load(helper, ctx);
|
||||
|
|
@ -192,7 +192,7 @@ impl<'a> TransformCtx<'a> {
|
|||
pub fn helper_call_expr(
|
||||
&self,
|
||||
helper: Helper,
|
||||
arguments: Vec<'a, Argument<'a>>,
|
||||
arguments: ArenaVec<'a, Argument<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> Expression<'a> {
|
||||
let callee = self.helper_load(helper, ctx);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Utility transforms which are in common between other transforms.
|
||||
|
||||
use oxc_allocator::Vec;
|
||||
use oxc_allocator::Vec as ArenaVec;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_traverse::{Traverse, TraverseCtx};
|
||||
|
||||
|
|
@ -42,11 +42,19 @@ impl<'a, 'ctx> Traverse<'a> for Common<'a, 'ctx> {
|
|||
self.top_level_statements.exit_program(program, ctx);
|
||||
}
|
||||
|
||||
fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn enter_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.var_declarations.enter_statements(stmts, ctx);
|
||||
}
|
||||
|
||||
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn exit_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.var_declarations.exit_statements(stmts, ctx);
|
||||
self.statement_injector.exit_statements(stmts, ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use oxc_allocator::{Address, GetAddress, Vec as AVec};
|
||||
use oxc_allocator::{Address, GetAddress, Vec as ArenaVec};
|
||||
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_traverse::{Traverse, TraverseCtx};
|
||||
|
|
@ -36,7 +36,7 @@ impl<'a, 'ctx> StatementInjector<'a, 'ctx> {
|
|||
impl<'a, 'ctx> Traverse<'a> for StatementInjector<'a, 'ctx> {
|
||||
fn exit_statements(
|
||||
&mut self,
|
||||
statements: &mut AVec<'a, Statement<'a>>,
|
||||
statements: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.ctx.statement_injector.insert_into_statements(statements, ctx);
|
||||
|
|
@ -150,7 +150,7 @@ impl<'a> StatementInjectorStore<'a> {
|
|||
/// Insert statements immediately before / after the target statement.
|
||||
fn insert_into_statements(
|
||||
&self,
|
||||
statements: &mut AVec<'a, Statement<'a>>,
|
||||
statements: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
let mut insertions = self.insertions.borrow_mut();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use oxc_allocator::Vec;
|
||||
use oxc_allocator::Vec as ArenaVec;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_data_structures::stack::SparseStack;
|
||||
use oxc_span::SPAN;
|
||||
|
|
@ -39,13 +39,17 @@ impl<'a, 'ctx> VarDeclarations<'a, 'ctx> {
|
|||
impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> {
|
||||
fn enter_statements(
|
||||
&mut self,
|
||||
_stmts: &mut Vec<'a, Statement<'a>>,
|
||||
_stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
_ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.ctx.var_declarations.record_entering_statements();
|
||||
}
|
||||
|
||||
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn exit_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.ctx.var_declarations.insert_into_statements(stmts, ctx);
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +60,7 @@ impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> {
|
|||
|
||||
/// Store for `VariableDeclarator`s to be added to enclosing statement block.
|
||||
pub struct VarDeclarationsStore<'a> {
|
||||
stack: RefCell<SparseStack<Vec<'a, VariableDeclarator<'a>>>>,
|
||||
stack: RefCell<SparseStack<ArenaVec<'a, VariableDeclarator<'a>>>>,
|
||||
}
|
||||
|
||||
// Public methods
|
||||
|
|
@ -107,7 +111,7 @@ impl<'a> VarDeclarationsStore<'a> {
|
|||
|
||||
fn insert_into_statements(
|
||||
&self,
|
||||
stmts: &mut Vec<'a, Statement<'a>>,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
if matches!(ctx.parent(), Ancestor::ProgramBody(_)) {
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@
|
|||
|
||||
use serde::Deserialize;
|
||||
|
||||
use oxc_allocator::Vec;
|
||||
use oxc_allocator::Vec as ArenaVec;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_data_structures::stack::SparseStack;
|
||||
use oxc_span::SPAN;
|
||||
|
|
@ -405,7 +405,7 @@ impl<'a> ArrowFunctions<'a> {
|
|||
#[expect(clippy::unused_self)]
|
||||
fn insert_this_var_statement_at_the_top_of_statements(
|
||||
&mut self,
|
||||
statements: &mut Vec<'a, Statement<'a>>,
|
||||
statements: &mut ArenaVec<'a, Statement<'a>>,
|
||||
this_var: &BoundIdentifier<'a>,
|
||||
ctx: &TraverseCtx<'a>,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
//! * Exponentiation operator TC39 proposal: <https://github.com/tc39/proposal-exponentiation-operator>
|
||||
//! * Exponentiation operator specification: <https://tc39.es/ecma262/#sec-exp-operator>
|
||||
|
||||
use oxc_allocator::{CloneIn, Vec};
|
||||
use oxc_allocator::{CloneIn, Vec as ArenaVec};
|
||||
use oxc_ast::{ast::*, NONE};
|
||||
use oxc_semantic::{ReferenceFlags, SymbolFlags};
|
||||
use oxc_span::SPAN;
|
||||
|
|
@ -149,7 +149,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
// Left side of `Math.pow(pow_left, ...)`
|
||||
Expression<'a>,
|
||||
// Temporary var initializations
|
||||
Vec<'a, Expression<'a>>,
|
||||
ArenaVec<'a, Expression<'a>>,
|
||||
) {
|
||||
let mut temp_var_inits = ctx.ast.vec();
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
// Left side of `Math.pow(pow_left, ...)`
|
||||
Expression<'a>,
|
||||
// Temporary var initializations
|
||||
Vec<'a, Expression<'a>>,
|
||||
ArenaVec<'a, Expression<'a>>,
|
||||
) {
|
||||
// Object part of 2nd member expression
|
||||
// ```
|
||||
|
|
@ -326,7 +326,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
// Left side of `Math.pow(pow_left, ...)`
|
||||
Expression<'a>,
|
||||
// Temporary var initializations
|
||||
Vec<'a, Expression<'a>>,
|
||||
ArenaVec<'a, Expression<'a>>,
|
||||
) {
|
||||
// Object part of 2nd member expression
|
||||
// ```
|
||||
|
|
@ -408,7 +408,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
// Left side of `Math.pow(pow_left, ...)`
|
||||
Expression<'a>,
|
||||
// Temporary var initializations
|
||||
Vec<'a, Expression<'a>>,
|
||||
ArenaVec<'a, Expression<'a>>,
|
||||
) {
|
||||
// Object part of 2nd member expression
|
||||
// ```
|
||||
|
|
@ -482,7 +482,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
fn get_second_member_expression_object(
|
||||
&mut self,
|
||||
obj: &mut Expression<'a>,
|
||||
temp_var_inits: &mut Vec<'a, Expression<'a>>,
|
||||
temp_var_inits: &mut ArenaVec<'a, Expression<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> Expression<'a> {
|
||||
// If the object reference that we need to save is locally declared, evaluating it multiple times
|
||||
|
|
@ -532,7 +532,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
/// If needs temp var initializers, replace expression `expr` with `(temp1, temp2, expr)`.
|
||||
fn revise_expression(
|
||||
expr: &mut Expression<'a>,
|
||||
mut temp_var_inits: Vec<'a, Expression<'a>>,
|
||||
mut temp_var_inits: ArenaVec<'a, Expression<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
if !temp_var_inits.is_empty() {
|
||||
|
|
@ -566,7 +566,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
|
|||
fn create_temp_var(
|
||||
&mut self,
|
||||
expr: Expression<'a>,
|
||||
temp_var_inits: &mut Vec<'a, Expression<'a>>,
|
||||
temp_var_inits: &mut ArenaVec<'a, Expression<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> BoundIdentifier<'a> {
|
||||
let binding = ctx.generate_uid_in_current_scope_based_on_node(
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@
|
|||
//!
|
||||
//! * Babel plugin implementation: <https://github.com/babel/babel/tree/main/packages/babel-helper-builder-react-jsx>
|
||||
|
||||
use oxc_allocator::Vec;
|
||||
use oxc_allocator::Vec as ArenaVec;
|
||||
use oxc_ast::{ast::*, AstBuilder, NONE};
|
||||
use oxc_ecmascript::PropName;
|
||||
use oxc_span::{Atom, GetSpan, Span, SPAN};
|
||||
|
|
@ -999,7 +999,7 @@ impl<'a, 'b> JSXElementOrFragment<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
fn children(&self) -> &'b Vec<'a, JSXChild<'a>> {
|
||||
fn children(&self) -> &'b ArenaVec<'a, JSXChild<'a>> {
|
||||
match self {
|
||||
Self::Element(e) => &e.children,
|
||||
Self::Fragment(e) => &e.children,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_allocator::{Allocator, Vec};
|
||||
use oxc_allocator::{Allocator, Vec as ArenaVec};
|
||||
use oxc_ast::{ast::*, AstBuilder};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_semantic::{ScopeTree, SymbolTable};
|
||||
|
|
@ -356,7 +356,11 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn enter_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.common.enter_statements(stmts, ctx);
|
||||
if let Some(typescript) = self.x0_typescript.as_mut() {
|
||||
typescript.enter_statements(stmts, ctx);
|
||||
|
|
@ -387,7 +391,11 @@ impl<'a, 'ctx> Traverse<'a> for TransformerImpl<'a, 'ctx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn exit_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
if let Some(typescript) = self.x0_typescript.as_mut() {
|
||||
typescript.exit_statements(stmts, ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_hash::FxHashMap;
|
||||
|
||||
use oxc_allocator::Vec;
|
||||
use oxc_allocator::Vec as ArenaVec;
|
||||
use oxc_ast::{ast::*, visit::walk_mut, VisitMut, NONE};
|
||||
use oxc_ecmascript::ToInt32;
|
||||
use oxc_span::{Atom, Span, SPAN};
|
||||
|
|
@ -181,10 +181,10 @@ impl<'a> TypeScriptEnum<'a> {
|
|||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn transform_ts_enum_members(
|
||||
&mut self,
|
||||
members: &mut Vec<'a, TSEnumMember<'a>>,
|
||||
members: &mut ArenaVec<'a, TSEnumMember<'a>>,
|
||||
param: &BindingIdentifier<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> Vec<'a, Statement<'a>> {
|
||||
) -> ArenaVec<'a, Statement<'a>> {
|
||||
let create_identifier_reference = |ctx: &mut TraverseCtx<'a>| {
|
||||
let ident = ctx.create_bound_reference_id(
|
||||
param.span,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use oxc_allocator::Vec;
|
||||
use oxc_allocator::Vec as ArenaVec;
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_traverse::{Traverse, TraverseCtx};
|
||||
|
||||
|
|
@ -197,11 +197,19 @@ impl<'a, 'ctx> Traverse<'a> for TypeScript<'a, 'ctx> {
|
|||
self.annotations.enter_accessor_property(def, ctx);
|
||||
}
|
||||
|
||||
fn enter_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn enter_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.annotations.enter_statements(stmts, ctx);
|
||||
}
|
||||
|
||||
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
fn exit_statements(
|
||||
&mut self,
|
||||
stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
self.annotations.exit_statements(stmts, ctx);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_hash::FxHashSet;
|
||||
|
||||
use oxc_allocator::{Box, Vec};
|
||||
use oxc_allocator::{Box, Vec as ArenaVec};
|
||||
use oxc_ast::{ast::*, NONE};
|
||||
use oxc_ecmascript::BoundNames;
|
||||
use oxc_span::{Atom, CompactStr, SPAN};
|
||||
|
|
@ -320,8 +320,8 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> {
|
|||
fn transform_namespace(
|
||||
arg_name: Atom<'a>,
|
||||
real_name: Atom<'a>,
|
||||
stmts: Vec<'a, Statement<'a>>,
|
||||
directives: Vec<'a, Directive<'a>>,
|
||||
stmts: ArenaVec<'a, Statement<'a>>,
|
||||
directives: ArenaVec<'a, Directive<'a>>,
|
||||
parent_export: Option<Expression<'a>>,
|
||||
scope_id: ScopeId,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
|
|
@ -414,7 +414,7 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> {
|
|||
decl: Declaration<'a>,
|
||||
name: Atom<'a>,
|
||||
names: &mut FxHashSet<Atom<'a>>,
|
||||
new_stmts: &mut Vec<'a, Statement<'a>>,
|
||||
new_stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
ctx: &TraverseCtx<'a>,
|
||||
) {
|
||||
// This function is only called with a function, class, or enum declaration,
|
||||
|
|
@ -449,7 +449,7 @@ impl<'a, 'ctx> TypeScriptNamespace<'a, 'ctx> {
|
|||
mut var_decl: Box<'a, VariableDeclaration<'a>>,
|
||||
name: Atom<'a>,
|
||||
ctx: &TraverseCtx<'a>,
|
||||
) -> Vec<'a, Statement<'a>> {
|
||||
) -> ArenaVec<'a, Statement<'a>> {
|
||||
let is_all_binding_identifier = var_decl
|
||||
.declarations
|
||||
.iter()
|
||||
|
|
|
|||
Loading…
Reference in a new issue