mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
parent
e20c60d961
commit
c8e968f35d
7 changed files with 56 additions and 39 deletions
|
|
@ -1114,7 +1114,7 @@ pub struct BindingPattern<'a> {
|
|||
#[serde(flatten)]
|
||||
pub kind: BindingPatternKind<'a>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
pub optional: bool,
|
||||
}
|
||||
|
||||
|
|
@ -1198,7 +1198,7 @@ pub struct Function<'a> {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub return_type: Option<TSTypeAnnotation<'a>>,
|
||||
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
/// Valid modifiers: `export`, `default`, `async`
|
||||
#[serde(skip_serializing_if = "Modifiers::is_none")]
|
||||
pub modifiers: Modifiers<'a>,
|
||||
|
|
@ -1302,7 +1302,7 @@ pub struct ArrowExpression<'a> {
|
|||
pub body: Box<'a, FunctionBody<'a>>,
|
||||
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
pub return_type: Option<TSTypeAnnotation<'a>>,
|
||||
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
}
|
||||
|
||||
/// Section 15.5 Generator Function Definitions
|
||||
|
|
@ -1324,7 +1324,7 @@ pub struct Class<'a> {
|
|||
pub span: Span,
|
||||
pub id: Option<BindingIdentifier>,
|
||||
pub super_class: Option<Expression<'a>>,
|
||||
pub body: ClassBody<'a>,
|
||||
pub body: Box<'a, ClassBody<'a>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
@ -1479,7 +1479,7 @@ pub struct PropertyDefinition<'a> {
|
|||
pub definite: bool,
|
||||
pub readonly: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub accessibility: Option<TSAccessibility>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
|
|
|
|||
|
|
@ -524,7 +524,7 @@ pub struct TSPropertySignature<'a> {
|
|||
pub readonly: bool,
|
||||
pub key: PropertyKey<'a>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Hash)]
|
||||
|
|
@ -543,7 +543,7 @@ pub struct TSIndexSignature<'a> {
|
|||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub parameters: Vec<'a, Box<'a, TSIndexSignatureName<'a>>>,
|
||||
pub type_annotation: TSTypeAnnotation<'a>,
|
||||
pub type_annotation: Box<'a, TSTypeAnnotation<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Hash)]
|
||||
|
|
@ -553,7 +553,7 @@ pub struct TSCallSignatureDeclaration<'a> {
|
|||
pub span: Span,
|
||||
pub params: Box<'a, FormalParameters<'a>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub return_type: Option<TSTypeAnnotation<'a>>,
|
||||
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
}
|
||||
|
|
@ -578,7 +578,7 @@ pub struct TSMethodSignature<'a> {
|
|||
pub kind: TSMethodSignatureKind,
|
||||
pub params: Box<'a, FormalParameters<'a>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub return_type: Option<TSTypeAnnotation<'a>>,
|
||||
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
}
|
||||
|
|
@ -590,7 +590,7 @@ pub struct TSConstructSignatureDeclaration<'a> {
|
|||
pub span: Span,
|
||||
pub params: Box<'a, FormalParameters<'a>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub return_type: Option<TSTypeAnnotation<'a>>,
|
||||
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
}
|
||||
|
|
@ -601,7 +601,7 @@ pub struct TSIndexSignatureName<'a> {
|
|||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub name: Atom,
|
||||
pub type_annotation: TSTypeAnnotation<'a>,
|
||||
pub type_annotation: Box<'a, TSTypeAnnotation<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Hash)]
|
||||
|
|
@ -621,7 +621,7 @@ pub struct TSTypePredicate<'a> {
|
|||
pub span: Span,
|
||||
pub parameter_name: TSTypePredicateName,
|
||||
pub asserts: bool,
|
||||
pub type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Eq, Hash)]
|
||||
|
|
@ -718,7 +718,7 @@ pub struct TSFunctionType<'a> {
|
|||
#[serde(flatten)]
|
||||
pub span: Span,
|
||||
pub params: Box<'a, FormalParameters<'a>>,
|
||||
pub return_type: TSTypeAnnotation<'a>,
|
||||
pub return_type: Box<'a, TSTypeAnnotation<'a>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
}
|
||||
|
|
@ -730,7 +730,7 @@ pub struct TSConstructorType<'a> {
|
|||
pub span: Span,
|
||||
pub r#abstract: bool,
|
||||
pub params: Box<'a, FormalParameters<'a>>,
|
||||
pub return_type: TSTypeAnnotation<'a>,
|
||||
pub return_type: Box<'a, TSTypeAnnotation<'a>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
}
|
||||
|
|
@ -859,9 +859,14 @@ pub struct Modifier {
|
|||
|
||||
#[derive(Debug, Serialize, PartialEq, Eq, Hash, Default)]
|
||||
#[serde(transparent)]
|
||||
pub struct Modifiers<'a>(pub Option<Vec<'a, Modifier>>);
|
||||
pub struct Modifiers<'a>(Option<Vec<'a, Modifier>>);
|
||||
|
||||
impl<'a> Modifiers<'a> {
|
||||
#[must_use]
|
||||
pub const fn new(modifiers: Vec<'a, Modifier>) -> Self {
|
||||
Self(Some(modifiers))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn empty() -> Self {
|
||||
Self(None)
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ impl<'a> AstBuilder<'a> {
|
|||
params: Box<'a, FormalParameters<'a>>,
|
||||
body: Box<'a, FunctionBody<'a>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
return_type: Option<TSTypeAnnotation<'a>>,
|
||||
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
) -> Expression<'a> {
|
||||
Expression::ArrowFunctionExpression(self.alloc(ArrowExpression {
|
||||
span,
|
||||
|
|
@ -711,7 +711,7 @@ impl<'a> AstBuilder<'a> {
|
|||
params: Box<'a, FormalParameters<'a>>,
|
||||
body: Option<Box<'a, FunctionBody<'a>>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
return_type: Option<TSTypeAnnotation<'a>>,
|
||||
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
modifiers: Modifiers<'a>,
|
||||
) -> Box<'a, Function<'a>> {
|
||||
self.alloc(Function {
|
||||
|
|
@ -750,7 +750,7 @@ impl<'a> AstBuilder<'a> {
|
|||
span: Span,
|
||||
id: Option<BindingIdentifier>,
|
||||
super_class: Option<Expression<'a>>,
|
||||
body: ClassBody<'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, Box<'a, TSClassImplements<'a>>>>,
|
||||
|
|
@ -771,6 +771,16 @@ impl<'a> AstBuilder<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn class_body(
|
||||
&self,
|
||||
span: Span,
|
||||
body: Vec<'a, ClassElement<'a>>,
|
||||
) -> Box<'a, ClassBody<'a>> {
|
||||
self.alloc(ClassBody { span, body })
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn class_declaration(&self, class: Box<'a, Class<'a>>) -> Statement<'a> {
|
||||
|
|
@ -836,7 +846,7 @@ impl<'a> AstBuilder<'a> {
|
|||
pub fn binding_pattern(
|
||||
&self,
|
||||
kind: BindingPatternKind<'a>,
|
||||
type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
optional: bool,
|
||||
) -> BindingPattern<'a> {
|
||||
BindingPattern { kind, type_annotation, optional }
|
||||
|
|
@ -1139,8 +1149,8 @@ impl<'a> AstBuilder<'a> {
|
|||
&self,
|
||||
span: Span,
|
||||
type_annotation: TSType<'a>,
|
||||
) -> TSTypeAnnotation<'a> {
|
||||
TSTypeAnnotation { span, type_annotation }
|
||||
) -> Box<'a, TSTypeAnnotation<'a>> {
|
||||
self.alloc(TSTypeAnnotation { span, type_annotation })
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -1289,7 +1299,7 @@ impl<'a> AstBuilder<'a> {
|
|||
&self,
|
||||
span: Span,
|
||||
parameters: Vec<'a, Box<'a, TSIndexSignatureName<'a>>>,
|
||||
type_annotation: TSTypeAnnotation<'a>,
|
||||
type_annotation: Box<'a, TSTypeAnnotation<'a>>,
|
||||
) -> TSSignature<'a> {
|
||||
TSSignature::TSIndexSignature(self.alloc(TSIndexSignature {
|
||||
span,
|
||||
|
|
@ -1307,7 +1317,7 @@ impl<'a> AstBuilder<'a> {
|
|||
optional: bool,
|
||||
readonly: bool,
|
||||
key: PropertyKey<'a>,
|
||||
type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
) -> TSSignature<'a> {
|
||||
TSSignature::TSPropertySignature(self.alloc(TSPropertySignature {
|
||||
span,
|
||||
|
|
@ -1325,7 +1335,7 @@ impl<'a> AstBuilder<'a> {
|
|||
&self,
|
||||
span: Span,
|
||||
params: Box<'a, FormalParameters<'a>>,
|
||||
return_type: Option<TSTypeAnnotation<'a>>,
|
||||
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
) -> TSSignature<'a> {
|
||||
TSSignature::TSCallSignatureDeclaration(self.alloc(TSCallSignatureDeclaration {
|
||||
|
|
@ -1342,7 +1352,7 @@ impl<'a> AstBuilder<'a> {
|
|||
&self,
|
||||
span: Span,
|
||||
params: Box<'a, FormalParameters<'a>>,
|
||||
return_type: Option<TSTypeAnnotation<'a>>,
|
||||
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
) -> TSSignature<'a> {
|
||||
TSSignature::TSConstructSignatureDeclaration(self.alloc(TSConstructSignatureDeclaration {
|
||||
|
|
@ -1363,7 +1373,7 @@ impl<'a> AstBuilder<'a> {
|
|||
optional: bool,
|
||||
kind: TSMethodSignatureKind,
|
||||
params: Box<'a, FormalParameters<'a>>,
|
||||
return_type: Option<TSTypeAnnotation<'a>>,
|
||||
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
) -> TSSignature<'a> {
|
||||
TSSignature::TSMethodSignature(self.alloc(TSMethodSignature {
|
||||
|
|
@ -1667,7 +1677,7 @@ impl<'a> AstBuilder<'a> {
|
|||
span: Span,
|
||||
r#abstract: bool,
|
||||
params: Box<'a, FormalParameters<'a>>,
|
||||
return_type: TSTypeAnnotation<'a>,
|
||||
return_type: Box<'a, TSTypeAnnotation<'a>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
) -> TSType<'a> {
|
||||
TSType::TSConstructorType(self.alloc(TSConstructorType {
|
||||
|
|
@ -1685,7 +1695,7 @@ impl<'a> AstBuilder<'a> {
|
|||
&self,
|
||||
span: Span,
|
||||
params: Box<'a, FormalParameters<'a>>,
|
||||
return_type: TSTypeAnnotation<'a>,
|
||||
return_type: Box<'a, TSTypeAnnotation<'a>>,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
) -> TSType<'a> {
|
||||
TSType::TSFunctionType(self.alloc(TSFunctionType {
|
||||
|
|
@ -1713,7 +1723,7 @@ impl<'a> AstBuilder<'a> {
|
|||
span: Span,
|
||||
parameter_name: TSTypePredicateName,
|
||||
asserts: bool,
|
||||
type_annotation: Option<TSTypeAnnotation<'a>>,
|
||||
type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
) -> TSType<'a> {
|
||||
TSType::TSTypePredicate(self.alloc(TSTypePredicate {
|
||||
span,
|
||||
|
|
|
|||
|
|
@ -150,14 +150,12 @@ impl<'a> Parser<'a> {
|
|||
Ok(extends)
|
||||
}
|
||||
|
||||
fn parse_class_body(&mut self) -> Result<ClassBody<'a>> {
|
||||
fn parse_class_body(&mut self) -> Result<Box<'a, ClassBody<'a>>> {
|
||||
let span = self.start_span();
|
||||
|
||||
let mut class_elements = ClassElements::new(self);
|
||||
class_elements.parse(self)?;
|
||||
let body = class_elements.elements;
|
||||
|
||||
Ok(ClassBody { span: self.end_span(span), body })
|
||||
Ok(self.ast.class_body(self.end_span(span), body))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{diagnostics, lexer::Kind, list::SeparatedList, Parser};
|
|||
type ArrowFunctionHead<'a> = (
|
||||
Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
Box<'a, FormalParameters<'a>>,
|
||||
Option<TSTypeAnnotation<'a>>,
|
||||
Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
bool,
|
||||
Span,
|
||||
);
|
||||
|
|
@ -481,7 +481,7 @@ impl<'a> Parser<'a> {
|
|||
span: Span,
|
||||
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
params: Box<'a, FormalParameters<'a>>,
|
||||
return_type: Option<TSTypeAnnotation<'a>>,
|
||||
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
|
||||
r#async: bool,
|
||||
) -> Result<Expression<'a>> {
|
||||
let has_await = self.ctx.has_await();
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/** ------------------- Annotation ----------------- */
|
||||
|
||||
pub fn parse_ts_type_annotation(&mut self) -> Result<Option<TSTypeAnnotation<'a>>> {
|
||||
pub fn parse_ts_type_annotation(&mut self) -> Result<Option<Box<'a, TSTypeAnnotation<'a>>>> {
|
||||
if self.at(Kind::Colon) {
|
||||
let span = self.start_span();
|
||||
self.bump_any(); // bump ':'
|
||||
|
|
@ -72,7 +72,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_ts_variable_annotation(&mut self) -> Result<(Option<TSTypeAnnotation<'a>>, bool)> {
|
||||
pub fn parse_ts_variable_annotation(
|
||||
&mut self,
|
||||
) -> Result<(Option<Box<'a, TSTypeAnnotation<'a>>>, bool)> {
|
||||
if !self.at(Kind::Bang) {
|
||||
return Ok((self.parse_ts_type_annotation()?, false));
|
||||
}
|
||||
|
|
@ -515,7 +517,7 @@ impl<'a> Parser<'a> {
|
|||
modifiers.push(Self::modifier(kind, self.end_span(span)));
|
||||
}
|
||||
|
||||
(flags, Modifiers(Some(modifiers)))
|
||||
(flags, Modifiers::new(modifiers))
|
||||
}
|
||||
|
||||
fn at_modifier(&mut self) -> bool {
|
||||
|
|
|
|||
|
|
@ -828,7 +828,9 @@ impl<'a> Parser<'a> {
|
|||
self.unexpected()
|
||||
}
|
||||
|
||||
pub fn parse_ts_return_type_annotation(&mut self) -> Result<Option<TSTypeAnnotation<'a>>> {
|
||||
pub fn parse_ts_return_type_annotation(
|
||||
&mut self,
|
||||
) -> Result<Option<Box<'a, TSTypeAnnotation<'a>>>> {
|
||||
if !self.ts_enabled() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue