feat(ast): provide NONE type for AST builder calls (#5737)

Closes #5736.

Introduce a `NONE` type which can be used for any `AstBuilder` method call param which expects an `IntoIn<'a, Something<'a>>`, where otherwise you have to provide a verbose type annotation.

Before:

```rs
ast.arrow_function_expression(
    SPAN,
    is_expression,
    is_async,
    None::<TSTypeParameterDeclaration>,
    params,
    None::<TSTypeAnnotation>,
    body,
)
```

After:

```rs
ast.arrow_function_expression(SPAN, is_expression, is_async, NONE, params, NONE, body)
```
This commit is contained in:
overlookmotel 2024-09-13 02:42:01 +00:00
parent 71116a1cbd
commit 953fe17f0e
27 changed files with 111 additions and 219 deletions

View file

@ -7,7 +7,7 @@
use std::mem; use std::mem;
use oxc_allocator::{Allocator, Box, String, Vec}; use oxc_allocator::{Allocator, Box, FromIn, String, Vec};
use oxc_span::{Atom, GetSpan, Span}; use oxc_span::{Atom, GetSpan, Span};
use oxc_syntax::{number::NumberBase, operator::UnaryOperator}; use oxc_syntax::{number::NumberBase, operator::UnaryOperator};
@ -15,6 +15,17 @@ use oxc_syntax::{number::NumberBase, operator::UnaryOperator};
use crate::ast::*; use crate::ast::*;
use crate::AstBuilder; use crate::AstBuilder;
/// Type that can be used in any AST builder method call which requires an `IntoIn<'a, Anything<'a>>`.
/// Pass `NONE` instead of `None::<Anything<'a>>`.
#[allow(clippy::upper_case_acronyms)]
pub struct NONE;
impl<'a, T> FromIn<'a, NONE> for Option<Box<'a, T>> {
fn from_in(_: NONE, _: &'a Allocator) -> Self {
None
}
}
impl<'a> AstBuilder<'a> { impl<'a> AstBuilder<'a> {
#[inline] #[inline]
pub fn new(allocator: &'a Allocator) -> Self { pub fn new(allocator: &'a Allocator) -> Self {
@ -145,19 +156,9 @@ impl<'a> AstBuilder<'a> {
params: FormalParameters<'a>, params: FormalParameters<'a>,
body: Option<FunctionBody<'a>>, body: Option<FunctionBody<'a>>,
) -> Box<'a, Function<'a>> { ) -> Box<'a, Function<'a>> {
self.alloc(self.function( self.alloc(
r#type, self.function(r#type, span, id, false, false, false, NONE, NONE, params, NONE, body),
span, )
id,
false,
false,
false,
Option::<TSTypeParameterDeclaration>::None,
None::<Box<'a, TSThisParameter<'a>>>,
params,
Option::<TSTypeAnnotation>::None,
body,
))
} }
/* ---------- Modules ---------- */ /* ---------- Modules ---------- */
@ -174,7 +175,7 @@ impl<'a> AstBuilder<'a> {
self.vec(), self.vec(),
None, None,
ImportOrExportKind::Value, ImportOrExportKind::Value,
None::<WithClause>, NONE,
)) ))
} }
@ -191,7 +192,7 @@ impl<'a> AstBuilder<'a> {
specifiers, specifiers,
source, source,
ImportOrExportKind::Value, ImportOrExportKind::Value,
None::<WithClause>, NONE,
)) ))
} }

View file

@ -59,6 +59,7 @@ pub use num_bigint::BigUint;
pub use crate::{ pub use crate::{
ast_builder::AstBuilder, ast_builder::AstBuilder,
ast_builder_impl::NONE,
ast_kind::{AstKind, AstType}, ast_kind::{AstKind, AstType},
trivia::{Comment, CommentKind, SortedComments, Trivias}, trivia::{Comment, CommentKind, SortedComments, Trivias},
visit::{Visit, VisitMut}, visit::{Visit, VisitMut},

View file

@ -1,6 +1,6 @@
use oxc_allocator::Box; use oxc_allocator::Box;
#[allow(clippy::wildcard_imports)] #[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_span::{Atom, GetSpan, SPAN}; use oxc_span::{Atom, GetSpan, SPAN};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -130,7 +130,7 @@ impl<'a> IsolatedDeclarations<'a> {
unsafe { self.ast.copy(&function.this_param) }, unsafe { self.ast.copy(&function.this_param) },
params, params,
return_type, return_type,
Option::<FunctionBody>::None, NONE,
); );
self.ast.class_element_method_definition( self.ast.class_element_method_definition(
@ -170,7 +170,7 @@ impl<'a> IsolatedDeclarations<'a> {
false, false,
false, false,
false, false,
Option::<TSTypeAnnotation>::None, NONE,
accessibility, accessibility,
) )
} }
@ -228,7 +228,7 @@ impl<'a> IsolatedDeclarations<'a> {
SPAN, SPAN,
FormalParameterKind::Signature, FormalParameterKind::Signature,
self.ast.vec(), self.ast.vec(),
Option::<BindingRestElement>::None, NONE,
); );
self.transform_class_method_definition(method, params, None) self.transform_class_method_definition(method, params, None)
} }
@ -491,20 +491,8 @@ impl<'a> IsolatedDeclarations<'a> {
let r#type = PropertyDefinitionType::PropertyDefinition; let r#type = PropertyDefinitionType::PropertyDefinition;
let decorators = self.ast.vec(); let decorators = self.ast.vec();
let element = self.ast.class_element_property_definition( let element = self.ast.class_element_property_definition(
r#type, r#type, SPAN, decorators, ident, None, false, false, false, false, false, false,
SPAN, false, NONE, None,
decorators,
ident,
None,
false,
false,
false,
false,
false,
false,
false,
Option::<TSTypeAnnotation>::None,
None,
); );
elements.insert(0, element); elements.insert(0, element);
@ -562,11 +550,6 @@ impl<'a> IsolatedDeclarations<'a> {
let parameter = let parameter =
self.ast.formal_parameter(SPAN, self.ast.vec(), pattern, None, false, false); self.ast.formal_parameter(SPAN, self.ast.vec(), pattern, None, false, false);
let items = self.ast.vec1(parameter); let items = self.ast.vec1(parameter);
self.ast.alloc_formal_parameters( self.ast.alloc_formal_parameters(SPAN, FormalParameterKind::Signature, items, NONE)
SPAN,
FormalParameterKind::Signature,
items,
Option::<BindingRestElement>::None,
)
} }
} }

View file

@ -1,7 +1,6 @@
use oxc_allocator::Box; use oxc_allocator::Box;
use oxc_ast::ast::Function;
#[allow(clippy::wildcard_imports)] #[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_span::{Span, SPAN}; use oxc_span::{Span, SPAN};
use crate::{ use crate::{
@ -41,7 +40,7 @@ impl<'a> IsolatedDeclarations<'a> {
unsafe { self.ast.copy(&func.this_param) }, unsafe { self.ast.copy(&func.this_param) },
params, params,
return_type, return_type,
Option::<FunctionBody>::None, NONE,
)) ))
} }
} }

View file

@ -24,7 +24,7 @@ use std::{cell::RefCell, collections::VecDeque, mem};
use diagnostics::function_with_assigning_properties; use diagnostics::function_with_assigning_properties;
use oxc_allocator::Allocator; use oxc_allocator::Allocator;
#[allow(clippy::wildcard_imports)] #[allow(clippy::wildcard_imports)]
use oxc_ast::{ast::*, AstBuilder, Visit}; use oxc_ast::{ast::*, AstBuilder, Visit, NONE};
use oxc_diagnostics::OxcDiagnostic; use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{Atom, SourceType, SPAN}; use oxc_span::{Atom, SourceType, SPAN};
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
@ -308,14 +308,8 @@ impl<'a> IsolatedDeclarations<'a> {
if need_empty_export_marker { if need_empty_export_marker {
let specifiers = self.ast.vec(); let specifiers = self.ast.vec();
let kind = ImportOrExportKind::Value; let kind = ImportOrExportKind::Value;
let empty_export = self.ast.alloc_export_named_declaration( let empty_export =
SPAN, self.ast.alloc_export_named_declaration(SPAN, None, specifiers, None, kind, NONE);
None,
specifiers,
None,
kind,
None::<WithClause>,
);
new_ast_stmts new_ast_stmts
.push(Statement::from(ModuleDeclaration::ExportNamedDeclaration(empty_export))); .push(Statement::from(ModuleDeclaration::ExportNamedDeclaration(empty_export)));
} }

View file

@ -1,8 +1,10 @@
use oxc_allocator::Box; use oxc_ast::{
use oxc_ast::ast::{ ast::{
ArrayExpression, ArrayExpressionElement, ArrowFunctionExpression, Expression, Function, ArrayExpression, ArrayExpressionElement, ArrowFunctionExpression, Expression, Function,
ObjectExpression, ObjectPropertyKind, TSLiteral, TSMethodSignatureKind, TSThisParameter, ObjectExpression, ObjectPropertyKind, TSLiteral, TSMethodSignatureKind, TSTupleElement,
TSTupleElement, TSType, TSTypeOperatorOperator, TSType, TSTypeOperatorOperator,
},
NONE,
}; };
use oxc_span::{GetSpan, Span, SPAN}; use oxc_span::{GetSpan, Span, SPAN};
@ -55,7 +57,7 @@ impl<'a> IsolatedDeclarations<'a> {
return_type.map(|return_type| { return_type.map(|return_type| {
self.ast.ts_type_function_type( self.ast.ts_type_function_type(
func.span, func.span,
None::<Box<'a, TSThisParameter<'a>>>, NONE,
params, params,
return_type, return_type,
// SAFETY: `ast.copy` is unsound! We need to fix. // SAFETY: `ast.copy` is unsound! We need to fix.

View file

@ -1,4 +1,4 @@
use oxc_ast::{ast::*, syntax_directed_operations::BoundNames, AstBuilder, Visit}; use oxc_ast::{ast::*, syntax_directed_operations::BoundNames, AstBuilder, Visit, NONE};
use oxc_span::{Atom, Span, SPAN}; use oxc_span::{Atom, Span, SPAN};
pub struct KeepVar<'a> { pub struct KeepVar<'a> {
@ -57,8 +57,7 @@ impl<'a> KeepVar<'a> {
let kind = VariableDeclarationKind::Var; let kind = VariableDeclarationKind::Var;
let decls = self.ast.vec_from_iter(self.vars.into_iter().map(|(name, span)| { let decls = self.ast.vec_from_iter(self.vars.into_iter().map(|(name, span)| {
let binding_kind = self.ast.binding_pattern_kind_binding_identifier(span, name); let binding_kind = self.ast.binding_pattern_kind_binding_identifier(span, name);
let id = let id = self.ast.binding_pattern(binding_kind, NONE, false);
self.ast.binding_pattern::<Option<TSTypeAnnotation>>(binding_kind, None, false);
self.ast.variable_declarator(span, kind, id, None, false) self.ast.variable_declarator(span, kind, id, None, false)
})); }));

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use cow_utils::CowUtils; use cow_utils::CowUtils;
use oxc_allocator::Allocator; use oxc_allocator::Allocator;
use oxc_ast::{ast::*, AstBuilder}; use oxc_ast::{ast::*, AstBuilder, NONE};
use oxc_semantic::{ScopeTree, SymbolTable}; use oxc_semantic::{ScopeTree, SymbolTable};
use oxc_span::{CompactStr, SPAN}; use oxc_span::{CompactStr, SPAN};
use oxc_traverse::{traverse_mut, Traverse, TraverseCtx}; use oxc_traverse::{traverse_mut, Traverse, TraverseCtx};
@ -197,13 +197,9 @@ impl<'a> InjectGlobalVariables<'a> {
let specifiers = Some(self.ast.vec1(self.inject_import_to_specifier(inject))); let specifiers = Some(self.ast.vec1(self.inject_import_to_specifier(inject)));
let source = self.ast.string_literal(SPAN, inject.source.as_str()); let source = self.ast.string_literal(SPAN, inject.source.as_str());
let kind = ImportOrExportKind::Value; let kind = ImportOrExportKind::Value;
let import_decl = self.ast.module_declaration_import_declaration( let import_decl = self
SPAN, .ast
specifiers, .module_declaration_import_declaration(SPAN, specifiers, source, NONE, kind);
source,
None::<WithClause>,
kind,
);
self.ast.statement_module_declaration(import_decl) self.ast.statement_module_declaration(import_decl)
}); });
program.body.splice(0..0, imports); program.body.splice(0..0, imports);

View file

@ -1,5 +1,5 @@
use oxc_allocator::Box; use oxc_allocator::Box;
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::Result; use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span}; use oxc_span::{GetSpan, Span};
use oxc_syntax::precedence::Precedence; use oxc_syntax::precedence::Precedence;
@ -218,13 +218,13 @@ impl<'a> ParserImpl<'a> {
}; };
let params_span = self.end_span(ident.span); let params_span = self.end_span(ident.span);
let ident = self.ast.binding_pattern_kind_from_binding_identifier(ident); let ident = self.ast.binding_pattern_kind_from_binding_identifier(ident);
let pattern = self.ast.binding_pattern(ident, Option::<TSTypeAnnotation>::None, false); let pattern = self.ast.binding_pattern(ident, NONE, false);
let formal_parameter = self.ast.plain_formal_parameter(params_span, pattern); let formal_parameter = self.ast.plain_formal_parameter(params_span, pattern);
self.ast.alloc_formal_parameters( self.ast.alloc_formal_parameters(
params_span, params_span,
FormalParameterKind::ArrowFormalParameters, FormalParameterKind::ArrowFormalParameters,
self.ast.vec1(formal_parameter), self.ast.vec1(formal_parameter),
Option::<BindingRestElement>::None, NONE,
) )
}; };

View file

@ -1,4 +1,4 @@
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::Result; use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span}; use oxc_span::{GetSpan, Span};
@ -145,8 +145,7 @@ impl<'a> ParserImpl<'a> {
shorthand = true; shorthand = true;
let identifier = let identifier =
self.ast.binding_pattern_kind_binding_identifier(ident.span, &ident.name); self.ast.binding_pattern_kind_binding_identifier(ident.span, &ident.name);
let left = let left = self.ast.binding_pattern(identifier, NONE, false);
self.ast.binding_pattern(identifier, Option::<TSTypeAnnotation>::None, false);
self.context(Context::In, Context::empty(), |p| p.parse_initializer(span, left))? self.context(Context::In, Context::empty(), |p| p.parse_initializer(span, left))?
} else { } else {
return Err(self.unexpected()); return Err(self.unexpected());
@ -172,7 +171,7 @@ impl<'a> ParserImpl<'a> {
let expr = self.parse_assignment_expression_or_higher()?; let expr = self.parse_assignment_expression_or_higher()?;
Ok(self.ast.binding_pattern( Ok(self.ast.binding_pattern(
self.ast.binding_pattern_kind_assignment_pattern(self.end_span(span), left, expr), self.ast.binding_pattern_kind_assignment_pattern(self.end_span(span), left, expr),
Option::<TSTypeAnnotation>::None, NONE,
false, false,
)) ))
} else { } else {

View file

@ -1,5 +1,5 @@
use oxc_allocator::Box; use oxc_allocator::Box;
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::Result; use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span}; use oxc_span::{GetSpan, Span};
@ -113,7 +113,7 @@ impl<'a> ParserImpl<'a> {
} }
(self.ast.binding_pattern(binding_kind, type_annotation, optional), definite) (self.ast.binding_pattern(binding_kind, type_annotation, optional), definite)
} else { } else {
(self.ast.binding_pattern(binding_kind, Option::<TSTypeAnnotation>::None, false), false) (self.ast.binding_pattern(binding_kind, NONE, false), false)
}; };
let init = let init =

View file

@ -1,5 +1,5 @@
use oxc_allocator::{Box, Vec}; use oxc_allocator::{Box, Vec};
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::Result; use oxc_diagnostics::Result;
use oxc_span::{GetSpan, Span}; use oxc_span::{GetSpan, Span};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -347,7 +347,7 @@ impl<'a> ParserImpl<'a> {
self.ast.vec(), self.ast.vec(),
None, None,
ImportOrExportKind::Value, ImportOrExportKind::Value,
None::<WithClause>, NONE,
)) ))
} }

View file

@ -1,5 +1,5 @@
use oxc_allocator::{Box, Vec}; use oxc_allocator::{Box, Vec};
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::Result; use oxc_diagnostics::Result;
use oxc_span::GetSpan; use oxc_span::GetSpan;
use oxc_syntax::operator::UnaryOperator; use oxc_syntax::operator::UnaryOperator;
@ -1169,7 +1169,7 @@ impl<'a> ParserImpl<'a> {
this_param, this_param,
params, params,
return_type, return_type,
Option::<TSTypeParameterDeclaration>::None, NONE,
)) ))
} }
@ -1195,7 +1195,7 @@ impl<'a> ParserImpl<'a> {
this_param, this_param,
params, params,
return_type, return_type,
Option::<TSTypeParameterDeclaration>::None, NONE,
)) ))
} }

View file

@ -62,7 +62,7 @@
use std::cell::Cell; use std::cell::Cell;
use oxc_allocator::Vec; use oxc_allocator::Vec;
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_syntax::{scope::ScopeFlags, symbol::SymbolFlags}; use oxc_syntax::{scope::ScopeFlags, symbol::SymbolFlags};
use oxc_traverse::{Traverse, TraverseCtx}; use oxc_traverse::{Traverse, TraverseCtx};
@ -294,7 +294,7 @@ impl<'a> ArrowFunctions<'a> {
self.ctx self.ctx
.ast .ast
.binding_pattern_kind_from_binding_identifier(id.create_binding_identifier()), .binding_pattern_kind_from_binding_identifier(id.create_binding_identifier()),
Option::<TSTypeAnnotation>::None, NONE,
false, false,
); );

View file

@ -33,7 +33,7 @@
use std::cell::Cell; use std::cell::Cell;
use oxc_allocator::{CloneIn, Vec}; use oxc_allocator::{CloneIn, Vec};
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_semantic::{ReferenceFlags, SymbolFlags}; use oxc_semantic::{ReferenceFlags, SymbolFlags};
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator}; use oxc_syntax::operator::{AssignmentOperator, BinaryOperator};
@ -151,13 +151,7 @@ impl<'a> ExponentiationOperator<'a> {
let mut arguments = ctx.ast.vec_with_capacity(2); let mut arguments = ctx.ast.vec_with_capacity(2);
arguments.push(Argument::from(left)); arguments.push(Argument::from(left));
arguments.push(Argument::from(right)); arguments.push(Argument::from(right));
ctx.ast.expression_call( ctx.ast.expression_call(SPAN, callee, NONE, arguments, false)
SPAN,
callee,
None::<TSTypeParameterInstantiation<'_>>,
arguments,
false,
)
} }
/// Change `lhs **= 2` to `var temp; temp = lhs, lhs = Math.pow(temp, 2);`. /// Change `lhs **= 2` to `var temp; temp = lhs, lhs = Math.pow(temp, 2);`.
@ -327,7 +321,7 @@ impl<'a> ExponentiationOperator<'a> {
}; };
let kind = VariableDeclarationKind::Var; let kind = VariableDeclarationKind::Var;
let id = ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier); let id = ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier);
let id = ctx.ast.binding_pattern(id, None::<TSTypeAnnotation<'_>>, false); let id = ctx.ast.binding_pattern(id, NONE, false);
self.var_declarations self.var_declarations
.last_mut() .last_mut()
.unwrap() .unwrap()

View file

@ -26,7 +26,7 @@
//! * Babel plugin implementation: <https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-object-rest-spread> //! * Babel plugin implementation: <https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-object-rest-spread>
//! * Object rest/spread TC39 proposal: <https://github.com/tc39/proposal-object-rest-spread> //! * Object rest/spread TC39 proposal: <https://github.com/tc39/proposal-object-rest-spread>
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_semantic::{ReferenceFlags, SymbolId}; use oxc_semantic::{ReferenceFlags, SymbolId};
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_traverse::{Traverse, TraverseCtx}; use oxc_traverse::{Traverse, TraverseCtx};
@ -84,13 +84,7 @@ impl<'a> Traverse<'a> for ObjectSpread<'a> {
let callee = self.get_extend_object_callee(object_id, babel_helpers_id, ctx); let callee = self.get_extend_object_callee(object_id, babel_helpers_id, ctx);
// ({ ...x }) => _objectSpread({}, x) // ({ ...x }) => _objectSpread({}, x)
*expr = ctx.ast.expression_call( *expr = ctx.ast.expression_call(SPAN, callee, NONE, arguments, false);
SPAN,
callee,
None::<TSTypeParameterInstantiation>,
arguments,
false,
);
// ({ ...x, y, z }) => _objectSpread(_objectSpread({}, x), { y, z }); // ({ ...x, y, z }) => _objectSpread(_objectSpread({}, x), { y, z });
if !obj_prop_list.is_empty() { if !obj_prop_list.is_empty() {
@ -101,13 +95,7 @@ impl<'a> Traverse<'a> for ObjectSpread<'a> {
let callee = self.get_extend_object_callee(object_id, babel_helpers_id, ctx); let callee = self.get_extend_object_callee(object_id, babel_helpers_id, ctx);
*expr = ctx.ast.expression_call( *expr = ctx.ast.expression_call(SPAN, callee, NONE, arguments, false);
SPAN,
callee,
None::<TSTypeParameterInstantiation>,
arguments,
false,
);
} }
} }
} }

View file

@ -34,7 +34,7 @@
use std::cell::Cell; use std::cell::Cell;
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_semantic::SymbolFlags; use oxc_semantic::SymbolFlags;
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_traverse::{Traverse, TraverseCtx}; use oxc_traverse::{Traverse, TraverseCtx};
@ -70,8 +70,7 @@ impl<'a> Traverse<'a> for OptionalCatchBinding<'a> {
BindingIdentifier { span: SPAN, symbol_id: Cell::new(Some(symbol_id)), name }; BindingIdentifier { span: SPAN, symbol_id: Cell::new(Some(symbol_id)), name };
let binding_pattern_kind = let binding_pattern_kind =
ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier); ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier);
let binding_pattern = let binding_pattern = ctx.ast.binding_pattern(binding_pattern_kind, NONE, false);
ctx.ast.binding_pattern(binding_pattern_kind, None::<TSTypeAnnotation<'a>>, false);
let param = ctx.ast.catch_parameter(SPAN, binding_pattern); let param = ctx.ast.catch_parameter(SPAN, binding_pattern);
clause.param = Some(param); clause.param = Some(param);
} }

View file

@ -31,7 +31,7 @@
use std::cell::Cell; use std::cell::Cell;
use oxc_allocator::{CloneIn, Vec}; use oxc_allocator::{CloneIn, Vec};
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_semantic::{ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags}; use oxc_semantic::{ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags};
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator}; use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator};
@ -137,34 +137,19 @@ impl<'a> Traverse<'a> for NullishCoalescingOperator<'a> {
SPAN, SPAN,
FormalParameterKind::ArrowFormalParameters, FormalParameterKind::ArrowFormalParameters,
ctx.ast.vec1(param), ctx.ast.vec1(param),
None::<BindingRestElement>, NONE,
); );
let body = ctx.ast.function_body( let body = ctx.ast.function_body(
SPAN, SPAN,
ctx.ast.vec(), ctx.ast.vec(),
ctx.ast.vec1(ctx.ast.statement_expression(SPAN, new_expr)), ctx.ast.vec1(ctx.ast.statement_expression(SPAN, new_expr)),
); );
let type_parameters = None::<TSTypeParameterDeclaration>; let arrow_function =
let type_annotation = None::<TSTypeAnnotation>; ctx.ast.arrow_function_expression(SPAN, true, false, NONE, params, NONE, body);
let arrow_function = ctx.ast.arrow_function_expression(
SPAN,
true,
false,
type_parameters,
params,
type_annotation,
body,
);
arrow_function.scope_id.set(Some(current_scope_id)); arrow_function.scope_id.set(Some(current_scope_id));
let arrow_function = ctx.ast.expression_from_arrow_function(arrow_function); let arrow_function = ctx.ast.expression_from_arrow_function(arrow_function);
// `(x) => x;` -> `((x) => x)();` // `(x) => x;` -> `((x) => x)();`
new_expr = ctx.ast.expression_call( new_expr = ctx.ast.expression_call(SPAN, arrow_function, NONE, ctx.ast.vec(), false);
SPAN,
arrow_function,
None::<TSTypeParameterInstantiation>,
ctx.ast.vec(),
false,
);
} else { } else {
let kind = VariableDeclarationKind::Var; let kind = VariableDeclarationKind::Var;
self.var_declarations self.var_declarations
@ -207,7 +192,7 @@ impl<'a> NullishCoalescingOperator<'a> {
symbol_id: Cell::new(Some(symbol_id)), symbol_id: Cell::new(Some(symbol_id)),
}; };
let id = ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier); let id = ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier);
let id = ctx.ast.binding_pattern(id, None::<TSTypeAnnotation<'_>>, false); let id = ctx.ast.binding_pattern(id, NONE, false);
let reference = let reference =
ctx.create_reference_id(SPAN, symbol_name, Some(symbol_id), ReferenceFlags::Read); ctx.create_reference_id(SPAN, symbol_name, Some(symbol_id), ReferenceFlags::Read);

View file

@ -56,7 +56,7 @@
use std::cell::Cell; use std::cell::Cell;
use oxc_allocator::{CloneIn, Vec}; use oxc_allocator::{CloneIn, Vec};
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_semantic::{ReferenceFlags, SymbolFlags}; use oxc_semantic::{ReferenceFlags, SymbolFlags};
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_syntax::operator::{AssignmentOperator, LogicalOperator}; use oxc_syntax::operator::{AssignmentOperator, LogicalOperator};
@ -367,7 +367,7 @@ impl<'a> LogicalAssignmentOperators<'a> {
}; };
let kind = VariableDeclarationKind::Var; let kind = VariableDeclarationKind::Var;
let id = ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier); let id = ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier);
let id = ctx.ast.binding_pattern(id, None::<TSTypeAnnotation>, false); let id = ctx.ast.binding_pattern(id, NONE, false);
self.var_declarations self.var_declarations
.last_mut() .last_mut()
.unwrap() .unwrap()

View file

@ -2,7 +2,7 @@ use std::cell::{Cell, RefCell};
use indexmap::IndexMap; use indexmap::IndexMap;
use oxc_allocator::{Allocator, Vec}; use oxc_allocator::{Allocator, Vec};
use oxc_ast::{ast::*, AstBuilder}; use oxc_ast::{ast::*, AstBuilder, NONE};
use oxc_semantic::ReferenceFlags; use oxc_semantic::ReferenceFlags;
use oxc_span::{Atom, SPAN}; use oxc_span::{Atom, SPAN};
use oxc_syntax::symbol::SymbolId; use oxc_syntax::symbol::SymbolId;
@ -108,7 +108,7 @@ impl<'a> ModuleImports<'a> {
SPAN, SPAN,
Some(specifiers), Some(specifiers),
StringLiteral::new(SPAN, source), StringLiteral::new(SPAN, source),
None::<WithClause>, NONE,
ImportOrExportKind::Value, ImportOrExportKind::Value,
); );
self.ast.statement_module_declaration(import_stmt) self.ast.statement_module_declaration(import_stmt)
@ -139,18 +139,12 @@ impl<'a> ModuleImports<'a> {
}; };
self.ast.binding_pattern( self.ast.binding_pattern(
self.ast.binding_pattern_kind_from_binding_identifier(ident), self.ast.binding_pattern_kind_from_binding_identifier(ident),
Option::<TSTypeAnnotation>::None, NONE,
false, false,
) )
}; };
let decl = { let decl = {
let init = self.ast.expression_call( let init = self.ast.expression_call(SPAN, callee, NONE, args, false);
SPAN,
callee,
Option::<TSTypeParameterInstantiation>::None,
args,
false,
);
let decl = self.ast.variable_declarator(SPAN, var_kind, id, Some(init), false); let decl = self.ast.variable_declarator(SPAN, var_kind, id, Some(init), false);
self.ast.vec1(decl) self.ast.vec1(decl)
}; };

View file

@ -1,7 +1,7 @@
use std::rc::Rc; use std::rc::Rc;
use oxc_allocator::Vec; use oxc_allocator::Vec;
use oxc_ast::{ast::*, AstBuilder}; use oxc_ast::{ast::*, AstBuilder, NONE};
use oxc_span::{Atom, GetSpan, Span, SPAN}; use oxc_span::{Atom, GetSpan, Span, SPAN};
use oxc_syntax::{ use oxc_syntax::{
identifier::{is_irregular_whitespace, is_line_terminator}, identifier::{is_irregular_whitespace, is_line_terminator},
@ -641,13 +641,7 @@ impl<'a> ReactJsx<'a> {
} }
let callee = self.get_create_element(has_key_after_props_spread, need_jsxs, ctx); let callee = self.get_create_element(has_key_after_props_spread, need_jsxs, ctx);
self.ast().expression_call( self.ast().expression_call(e.span(), callee, NONE, arguments, false)
e.span(),
callee,
Option::<TSTypeParameterInstantiation>::None,
arguments,
false,
)
} }
fn transform_element_name(&self, name: &JSXElementName<'a>) -> Expression<'a> { fn transform_element_name(&self, name: &JSXElementName<'a>) -> Expression<'a> {

View file

@ -1,4 +1,4 @@
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::OxcDiagnostic; use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{Span, SPAN}; use oxc_span::{Span, SPAN};
use oxc_syntax::{number::NumberBase, symbol::SymbolFlags}; use oxc_syntax::{number::NumberBase, symbol::SymbolFlags};
@ -164,7 +164,7 @@ impl<'a> ReactJsxSource<'a> {
let id = { let id = {
let ident = filename_var.create_binding_identifier(); let ident = filename_var.create_binding_identifier();
let ident = self.ctx.ast.binding_pattern_kind_from_binding_identifier(ident); let ident = self.ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
self.ctx.ast.binding_pattern(ident, Option::<TSTypeAnnotation>::None, false) self.ctx.ast.binding_pattern(ident, NONE, false)
}; };
let decl = { let decl = {
let init = self let init = self

View file

@ -2,7 +2,7 @@ use std::{cell::Cell, iter::once};
use base64::prelude::{Engine, BASE64_STANDARD}; use base64::prelude::{Engine, BASE64_STANDARD};
use oxc_allocator::CloneIn; use oxc_allocator::CloneIn;
use oxc_ast::{ast::*, match_expression, AstBuilder}; use oxc_ast::{ast::*, match_expression, AstBuilder, NONE};
use oxc_semantic::{Reference, ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags, SymbolId}; use oxc_semantic::{Reference, ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags, SymbolId};
use oxc_span::{Atom, GetSpan, SPAN}; use oxc_span::{Atom, GetSpan, SPAN};
use oxc_syntax::operator::AssignmentOperator; use oxc_syntax::operator::AssignmentOperator;
@ -164,7 +164,7 @@ impl<'a> Traverse<'a> for ReactRefresh<'a> {
ctx.ast.binding_pattern_kind_from_binding_identifier( ctx.ast.binding_pattern_kind_from_binding_identifier(
binding_identifier.clone(), binding_identifier.clone(),
), ),
None::<TSTypeAnnotation<'a>>, NONE,
false, false,
), ),
None, None,
@ -182,13 +182,7 @@ impl<'a> Traverse<'a> for ReactRefresh<'a> {
)); ));
new_statements.push(ctx.ast.statement_expression( new_statements.push(ctx.ast.statement_expression(
SPAN, SPAN,
ctx.ast.expression_call( ctx.ast.expression_call(SPAN, callee, NONE, arguments, false),
SPAN,
callee,
Option::<TSTypeParameterInstantiation>::None,
arguments,
false,
),
)); ));
} }
program.body.push(Statement::from(ctx.ast.declaration_variable( program.body.push(Statement::from(ctx.ast.declaration_variable(
@ -299,7 +293,7 @@ impl<'a> Traverse<'a> for ReactRefresh<'a> {
&binding_identifier, &binding_identifier,
ctx, ctx,
), ),
Option::<TSTypeParameterInstantiation>::None, NONE,
arguments, arguments,
false, false,
), ),
@ -329,7 +323,7 @@ impl<'a> Traverse<'a> for ReactRefresh<'a> {
*expr = self.ctx.ast.expression_call( *expr = self.ctx.ast.expression_call(
SPAN, SPAN,
Self::create_identifier_reference_from_binding_identifier(&binding_identifier, ctx), Self::create_identifier_reference_from_binding_identifier(&binding_identifier, ctx),
Option::<TSTypeParameterInstantiation>::None, NONE,
arguments, arguments,
false, false,
); );
@ -366,7 +360,7 @@ impl<'a> Traverse<'a> for ReactRefresh<'a> {
&binding_identifier, &binding_identifier,
ctx, ctx,
), ),
Option::<TSTypeParameterInstantiation>::None, NONE,
arguments, arguments,
false, false,
), ),
@ -656,7 +650,7 @@ impl<'a> ReactRefresh<'a> {
SPAN, SPAN,
FormalParameterKind::FormalParameter, FormalParameterKind::FormalParameter,
self.ctx.ast.vec(), self.ctx.ast.vec(),
Option::<BindingRestElement>::None, NONE,
); );
let function_body = self.ctx.ast.function_body( let function_body = self.ctx.ast.function_body(
SPAN, SPAN,
@ -673,10 +667,10 @@ impl<'a> ReactRefresh<'a> {
false, false,
false, false,
false, false,
Option::<TSTypeParameterDeclaration>::None, NONE,
Option::<TSThisParameter>::None, NONE,
formal_parameters, formal_parameters,
Option::<TSTypeAnnotation>::None, NONE,
Some(function_body), Some(function_body),
); );
let scope_id = ctx.create_child_scope_of_current(ScopeFlags::Function); let scope_id = ctx.create_child_scope_of_current(ScopeFlags::Function);
@ -708,7 +702,7 @@ impl<'a> ReactRefresh<'a> {
ctx.ast.expression_call( ctx.ast.expression_call(
SPAN, SPAN,
Self::create_identifier_reference_from_binding_identifier(&binding_identifier, ctx), Self::create_identifier_reference_from_binding_identifier(&binding_identifier, ctx),
Option::<TSTypeParameterInstantiation>::None, NONE,
ctx.ast.vec(), ctx.ast.vec(),
false, false,
), ),
@ -722,13 +716,13 @@ impl<'a> ReactRefresh<'a> {
VariableDeclarationKind::Var, VariableDeclarationKind::Var,
ctx.ast.binding_pattern( ctx.ast.binding_pattern(
ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier.clone()), ctx.ast.binding_pattern_kind_from_binding_identifier(binding_identifier.clone()),
Option::<TSTypeAnnotation>::None, NONE,
false, false,
), ),
Some(ctx.ast.expression_call( Some(ctx.ast.expression_call(
SPAN, SPAN,
self.refresh_sig.to_expression(ctx), self.refresh_sig.to_expression(ctx),
Option::<TSTypeParameterInstantiation>::None, NONE,
ctx.ast.vec(), ctx.ast.vec(),
false, false,
)), )),

View file

@ -46,7 +46,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::Result; use oxc_diagnostics::Result;
use oxc_regular_expression::ast::{ use oxc_regular_expression::ast::{
CharacterClass, CharacterClassContents, LookAroundAssertionKind, Pattern, Term, CharacterClass, CharacterClassContents, LookAroundAssertionKind, Pattern, Term,
@ -186,12 +186,7 @@ impl<'a> Traverse<'a> for RegExp<'a> {
ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, flags_str)); ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, flags_str));
arguments.push(flags_str); arguments.push(flags_str);
*expr = ctx.ast.expression_new( *expr = ctx.ast.expression_new(regexp.span, callee, arguments, NONE);
regexp.span,
callee,
arguments,
None::<TSTypeParameterInstantiation>,
);
} }
} }

View file

@ -1,7 +1,7 @@
use std::cell::Cell; use std::cell::Cell;
use oxc_allocator::Vec; use oxc_allocator::Vec;
use oxc_ast::{ast::*, visit::walk_mut, VisitMut}; use oxc_ast::{ast::*, visit::walk_mut, VisitMut, NONE};
use oxc_span::{Atom, Span, SPAN}; use oxc_span::{Atom, Span, SPAN};
use oxc_syntax::{ use oxc_syntax::{
node::AstNodeId, node::AstNodeId,
@ -94,7 +94,7 @@ impl<'a> TypeScriptEnum<'a> {
symbol_id: Cell::new(Some(param_symbol_id)), symbol_id: Cell::new(Some(param_symbol_id)),
}; };
let kind = ast.binding_pattern_kind_from_binding_identifier(ident.clone()); let kind = ast.binding_pattern_kind_from_binding_identifier(ident.clone());
let id = ast.binding_pattern(kind, Option::<TSTypeAnnotation>::None, false); let id = ast.binding_pattern(kind, NONE, false);
// ((Foo) => { // ((Foo) => {
let params = ast.formal_parameter(SPAN, ast.vec(), id, None, false, false); let params = ast.formal_parameter(SPAN, ast.vec(), id, None, false, false);
@ -103,7 +103,7 @@ impl<'a> TypeScriptEnum<'a> {
SPAN, SPAN,
FormalParameterKind::ArrowFormalParameters, FormalParameterKind::ArrowFormalParameters,
params, params,
Option::<BindingRestElement>::None, NONE,
); );
// Foo[Foo["X"] = 0] = "X"; // Foo[Foo["X"] = 0] = "X";
@ -146,13 +146,7 @@ impl<'a> TypeScriptEnum<'a> {
ast.vec1(Argument::from(expression)) ast.vec1(Argument::from(expression))
}; };
let call_expression = ast.expression_call( let call_expression = ast.expression_call(SPAN, callee, NONE, arguments, false);
SPAN,
callee,
Option::<TSTypeParameterInstantiation>::None,
arguments,
false,
);
if is_already_declared { if is_already_declared {
let op = AssignmentOperator::Assign; let op = AssignmentOperator::Assign;
@ -176,8 +170,7 @@ impl<'a> TypeScriptEnum<'a> {
let binding_identifier = decl.id.clone(); let binding_identifier = decl.id.clone();
let binding_pattern_kind = let binding_pattern_kind =
ast.binding_pattern_kind_from_binding_identifier(binding_identifier); ast.binding_pattern_kind_from_binding_identifier(binding_identifier);
let binding = let binding = ast.binding_pattern(binding_pattern_kind, NONE, false);
ast.binding_pattern(binding_pattern_kind, Option::<TSTypeAnnotation>::None, false);
let decl = ast.variable_declarator(SPAN, kind, binding, Some(call_expression), false); let decl = ast.variable_declarator(SPAN, kind, binding, Some(call_expression), false);
ast.vec1(decl) ast.vec1(decl)
}; };

View file

@ -1,5 +1,5 @@
use oxc_allocator::Box; use oxc_allocator::Box;
use oxc_ast::ast::*; use oxc_ast::{ast::*, NONE};
use oxc_span::SPAN; use oxc_span::SPAN;
use oxc_syntax::reference::ReferenceFlags; use oxc_syntax::reference::ReferenceFlags;
use oxc_traverse::{Traverse, TraverseCtx}; use oxc_traverse::{Traverse, TraverseCtx};
@ -58,11 +58,7 @@ impl<'a> TypeScriptModule<'a> {
let decls = { let decls = {
let binding_pattern_kind = let binding_pattern_kind =
ctx.ast.binding_pattern_kind_binding_identifier(SPAN, &decl.id.name); ctx.ast.binding_pattern_kind_binding_identifier(SPAN, &decl.id.name);
let binding = ctx.ast.binding_pattern( let binding = ctx.ast.binding_pattern(binding_pattern_kind, NONE, false);
binding_pattern_kind,
Option::<TSTypeAnnotation>::None,
false,
);
let decl_span = decl.span; let decl_span = decl.span;
let init = match &mut decl.module_reference { let init = match &mut decl.module_reference {
@ -80,13 +76,7 @@ impl<'a> TypeScriptModule<'a> {
let arguments = ctx.ast.vec1(Argument::from( let arguments = ctx.ast.vec1(Argument::from(
ctx.ast.expression_from_string_literal(reference.expression.clone()), ctx.ast.expression_from_string_literal(reference.expression.clone()),
)); ));
ctx.ast.expression_call( ctx.ast.expression_call(SPAN, callee, NONE, arguments, false)
SPAN,
callee,
Option::<TSTypeParameterInstantiation>::None,
arguments,
false,
)
} }
}; };
ctx.ast.vec1(ctx.ast.variable_declarator(SPAN, kind, binding, Some(init), false)) ctx.ast.vec1(ctx.ast.variable_declarator(SPAN, kind, binding, Some(init), false))

View file

@ -1,7 +1,7 @@
use std::rc::Rc; use std::rc::Rc;
use oxc_allocator::{Box, Vec}; use oxc_allocator::{Box, Vec};
use oxc_ast::{ast::*, syntax_directed_operations::BoundNames}; use oxc_ast::{ast::*, syntax_directed_operations::BoundNames, NONE};
use oxc_span::{Atom, CompactStr, SPAN}; use oxc_span::{Atom, CompactStr, SPAN};
use oxc_syntax::{ use oxc_syntax::{
operator::{AssignmentOperator, LogicalOperator}, operator::{AssignmentOperator, LogicalOperator},
@ -298,8 +298,7 @@ impl<'a> TypeScriptNamespace<'a> {
let kind = VariableDeclarationKind::Let; let kind = VariableDeclarationKind::Let;
let declarations = { let declarations = {
let pattern_kind = self.ctx.ast.binding_pattern_kind_binding_identifier(SPAN, name); let pattern_kind = self.ctx.ast.binding_pattern_kind_binding_identifier(SPAN, name);
let binding = let binding = self.ctx.ast.binding_pattern(pattern_kind, NONE, false);
self.ctx.ast.binding_pattern(pattern_kind, Option::<TSTypeAnnotation>::None, false);
let decl = self.ctx.ast.variable_declarator(SPAN, kind, binding, None, false); let decl = self.ctx.ast.variable_declarator(SPAN, kind, binding, None, false);
self.ctx.ast.vec1(decl) self.ctx.ast.vec1(decl)
}; };
@ -325,14 +324,13 @@ impl<'a> TypeScriptNamespace<'a> {
let body = self.ctx.ast.function_body(SPAN, directives, stmts); let body = self.ctx.ast.function_body(SPAN, directives, stmts);
let params = { let params = {
let ident = self.ctx.ast.binding_pattern_kind_binding_identifier(SPAN, arg_name); let ident = self.ctx.ast.binding_pattern_kind_binding_identifier(SPAN, arg_name);
let pattern = let pattern = self.ctx.ast.binding_pattern(ident, NONE, false);
self.ctx.ast.binding_pattern(ident, Option::<TSTypeAnnotation>::None, false);
let items = self.ctx.ast.vec1(self.ctx.ast.plain_formal_parameter(SPAN, pattern)); let items = self.ctx.ast.vec1(self.ctx.ast.plain_formal_parameter(SPAN, pattern));
self.ctx.ast.formal_parameters( self.ctx.ast.formal_parameters(
SPAN, SPAN,
FormalParameterKind::FormalParameter, FormalParameterKind::FormalParameter,
items, items,
Option::<BindingRestElement>::None, NONE,
) )
}; };
let function = self.ctx.ast.plain_function( let function = self.ctx.ast.plain_function(
@ -410,13 +408,7 @@ impl<'a> TypeScriptNamespace<'a> {
self.ctx.ast.vec1(self.ctx.ast.argument_expression(expr)) self.ctx.ast.vec1(self.ctx.ast.argument_expression(expr))
}; };
let expr = self.ctx.ast.expression_call( let expr = self.ctx.ast.expression_call(SPAN, callee, NONE, arguments, false);
SPAN,
callee,
Option::<TSTypeParameterInstantiation>::None,
arguments,
false,
);
self.ctx.ast.statement_expression(SPAN, expr) self.ctx.ast.statement_expression(SPAN, expr)
} }