Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 44 additions & 50 deletions crates/oxc_ast/src/serialize/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use super::{EmptyArray, Null};
#[ast_meta]
#[estree(raw_deser = "
const pattern = DESER[BindingPatternKind](POS_OFFSET.kind);
/* IF_TS */
pattern.optional = DESER[bool](POS_OFFSET.optional);
pattern.typeAnnotation = DESER[Option<Box<TSTypeAnnotation>>](POS_OFFSET.type_annotation);
/* END_IF_TS */
if (IS_TS) {
pattern.optional = DESER[bool](POS_OFFSET.optional);
pattern.typeAnnotation = DESER[Option<Box<TSTypeAnnotation>>](POS_OFFSET.type_annotation);
}
pattern
")]
pub struct BindingPatternConverter<'a, 'b>(pub &'b BindingPattern<'a>);
Expand Down Expand Up @@ -121,17 +121,15 @@ impl ESTree for CatchParameterConverter<'_, '_> {
pos = uint32[(POS_OFFSET.rest) >> 2];
params.push({
type: 'RestElement',
/* IF_TS */
decorators: [],
/* END_IF_TS */
...(IS_TS && { decorators: [] }),
argument: DESER[BindingPatternKind]( POS_OFFSET<BindingRestElement>.argument.kind ),
/* IF_TS */
optional: DESER[bool]( POS_OFFSET<BindingRestElement>.argument.optional ),
typeAnnotation: DESER[Option<Box<TSTypeAnnotation>>](
POS_OFFSET<BindingRestElement>.argument.type_annotation
),
value: null,
/* END_IF_TS */
...(IS_TS && {
optional: DESER[bool]( POS_OFFSET<BindingRestElement>.argument.optional ),
typeAnnotation: DESER[Option<Box<TSTypeAnnotation>>](
POS_OFFSET<BindingRestElement>.argument.type_annotation
),
value: null,
}),
start: DESER[u32]( POS_OFFSET<BindingRestElement>.span.start ),
end: DESER[u32]( POS_OFFSET<BindingRestElement>.span.end ),
});
Expand Down Expand Up @@ -183,35 +181,33 @@ impl ESTree for FormalParametersRest<'_, '_> {
#[estree(
ts_type = "FormalParameter | TSParameterProperty",
raw_deser = "
/* IF_JS */
DESER[BindingPatternKind](POS_OFFSET.pattern.kind)
/* END_IF_JS */

/* IF_TS */
const accessibility = DESER[Option<TSAccessibility>](POS_OFFSET.accessibility),
readonly = DESER[bool](POS_OFFSET.readonly),
override = DESER[bool](POS_OFFSET.override);
let param;
if (accessibility === null && !readonly && !override) {
param = DESER[BindingPatternKind](POS_OFFSET.pattern.kind);
param.decorators = DESER[Vec<Decorator>](POS_OFFSET.decorators);
param.optional = DESER[bool](POS_OFFSET.pattern.optional);
param.typeAnnotation = DESER[Option<Box<TSTypeAnnotation>>](POS_OFFSET.pattern.type_annotation);
if (IS_TS) {
const accessibility = DESER[Option<TSAccessibility>](POS_OFFSET.accessibility),
readonly = DESER[bool](POS_OFFSET.readonly),
override = DESER[bool](POS_OFFSET.override);
if (accessibility === null && !readonly && !override) {
param = DESER[BindingPatternKind](POS_OFFSET.pattern.kind);
param.decorators = DESER[Vec<Decorator>](POS_OFFSET.decorators);
param.optional = DESER[bool](POS_OFFSET.pattern.optional);
param.typeAnnotation = DESER[Option<Box<TSTypeAnnotation>>](POS_OFFSET.pattern.type_annotation);
} else {
param = {
type: 'TSParameterProperty',
accessibility,
decorators: DESER[Vec<Decorator>](POS_OFFSET.decorators),
override,
parameter: DESER[BindingPattern](POS_OFFSET.pattern),
readonly,
static: false,
start: DESER[u32]( POS_OFFSET<BindingRestElement>.span.start ),
end: DESER[u32]( POS_OFFSET<BindingRestElement>.span.end ),
};
}
} else {
param = {
type: 'TSParameterProperty',
accessibility,
decorators: DESER[Vec<Decorator>](POS_OFFSET.decorators),
override,
parameter: DESER[BindingPattern](POS_OFFSET.pattern),
readonly,
static: false,
start: DESER[u32]( POS_OFFSET<BindingRestElement>.span.start ),
end: DESER[u32]( POS_OFFSET<BindingRestElement>.span.end ),
};
param = DESER[BindingPatternKind](POS_OFFSET.pattern.kind);
}
param
/* END_IF_TS */
"
)]
pub struct FormalParameterConverter<'a, 'b>(pub &'b FormalParameter<'a>);
Expand Down Expand Up @@ -255,10 +251,10 @@ impl ESTree for FormalParameterConverter<'_, '_> {
ts_type = "ParamPattern[]",
raw_deser = "
const params = DESER[Box<FormalParameters>](POS_OFFSET.params);
/* IF_TS */
const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param);
if (thisParam !== null) params.unshift(thisParam);
/* END_IF_TS */
if (IS_TS) {
const thisParam = DESER[Option<Box<TSThisParameter>>](POS_OFFSET.this_param);
if (thisParam !== null) params.unshift(thisParam);
}
params
"
)]
Expand Down Expand Up @@ -411,15 +407,13 @@ impl ESTree for ArrowFunctionExpressionBody<'_> {
? keyCopy
: {
type: 'AssignmentPattern',
/* IF_TS */
decorators: [],
/* END_IF_TS */
...(IS_TS && { decorators: [] }),
left: keyCopy,
right: init,
/* IF_TS */
optional: false,
typeAnnotation: null,
/* END_IF_TS */
...(IS_TS && {
optional: false,
typeAnnotation: null,
}),
start: THIS.start,
end: THIS.end,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/serialize/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ impl ESTree for RegExpFlagsConverter<'_> {
#[ast_meta]
#[estree(raw_deser = r#"
const tail = DESER[bool](POS_OFFSET.tail),
start = DESER[u32](POS_OFFSET.span.start) /* IF_TS */ - 1 /* END_IF_TS */,
end = DESER[u32](POS_OFFSET.span.end) /* IF_TS */ + 2 - tail /* END_IF_TS */,
start = IS_TS ? DESER[u32](POS_OFFSET.span.start) - 1 : DESER[u32](POS_OFFSET.span.start),
end = IS_TS ? DESER[u32](POS_OFFSET.span.end) + 2 - tail : DESER[u32](POS_OFFSET.span.end),
value = DESER[TemplateElementValue](POS_OFFSET.value);
if (value.cooked !== null && DESER[bool](POS_OFFSET.lone_surrogates)) {
value.cooked = value.cooked
Expand Down
34 changes: 16 additions & 18 deletions crates/oxc_ast/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,29 @@ impl Program<'_> {
const body = DESER[Vec<Directive>](POS_OFFSET.directives);
body.push(...DESER[Vec<Statement>](POS_OFFSET.body));

/* IF_JS */
const start = DESER[u32](POS_OFFSET.span.start);
/* END_IF_JS */

const end = DESER[u32](POS_OFFSET.span.end);

/* IF_TS */
let start;
if (body.length > 0) {
const first = body[0];
start = first.start;
if (first.type === 'ExportNamedDeclaration' || first.type === 'ExportDefaultDeclaration') {
const { declaration } = first;
if (
declaration !== null && declaration.type === 'ClassDeclaration'
&& declaration.decorators.length > 0
) {
const decoratorStart = declaration.decorators[0].start;
if (decoratorStart < start) start = decoratorStart;
if (IS_TS) {
if (body.length > 0) {
const first = body[0];
start = first.start;
if (first.type === 'ExportNamedDeclaration' || first.type === 'ExportDefaultDeclaration') {
const { declaration } = first;
if (
declaration !== null && declaration.type === 'ClassDeclaration'
&& declaration.decorators.length > 0
) {
const decoratorStart = declaration.decorators[0].start;
if (decoratorStart < start) start = decoratorStart;
}
}
} else {
start = end;
}
} else {
start = end;
start = DESER[u32](POS_OFFSET.span.start);
}
/* END_IF_TS */

const program = {
type: 'Program',
Expand Down
7 changes: 5 additions & 2 deletions napi/parser/generated/deserialize/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function deserializeWith(buffer, sourceTextInput, sourceByteLenInput, preservePa
function deserializeProgram(pos) {
let body = deserializeVecDirective(pos + 72);
body.push(...deserializeVecStatement(pos + 96));
let start = deserializeU32(pos), end = deserializeU32(pos + 4);
let end = deserializeU32(pos + 4), start;
start = deserializeU32(pos);
return {
type: 'Program',
body,
Expand Down Expand Up @@ -778,7 +779,9 @@ function deserializeFormalParameters(pos) {
}

function deserializeFormalParameter(pos) {
return deserializeBindingPatternKind(pos + 32);
let param;
param = deserializeBindingPatternKind(pos + 32);
return param;
}

function deserializeFunctionBody(pos) {
Expand Down
49 changes: 27 additions & 22 deletions napi/parser/generated/deserialize/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,11 @@ function deserializeBindingRestElement(pos) {
}

function deserializeFunction(pos) {
let params = deserializeBoxFormalParameters(pos + 56), thisParam = deserializeOptionBoxTSThisParameter(pos + 48);
thisParam !== null && params.unshift(thisParam);
let params = deserializeBoxFormalParameters(pos + 56);
{
let thisParam = deserializeOptionBoxTSThisParameter(pos + 48);
thisParam !== null && params.unshift(thisParam);
}
return {
type: deserializeFunctionType(pos + 84),
id: deserializeOptionBindingIdentifier(pos + 8),
Expand Down Expand Up @@ -851,26 +854,28 @@ function deserializeFormalParameters(pos) {
}

function deserializeFormalParameter(pos) {
let accessibility = deserializeOptionTSAccessibility(pos + 64),
readonly = deserializeBool(pos + 65),
override = deserializeBool(pos + 66),
param;
if (accessibility === null && !readonly && !override) {
param = deserializeBindingPatternKind(pos + 32);
param.decorators = deserializeVecDecorator(pos + 8);
param.optional = deserializeBool(pos + 56);
param.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 48);
} else {param = {
type: 'TSParameterProperty',
accessibility,
decorators: deserializeVecDecorator(pos + 8),
override,
parameter: deserializeBindingPattern(pos + 32),
readonly,
static: false,
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
};}
let param;
{
let accessibility = deserializeOptionTSAccessibility(pos + 64),
readonly = deserializeBool(pos + 65),
override = deserializeBool(pos + 66);
if (accessibility === null && !readonly && !override) {
param = deserializeBindingPatternKind(pos + 32);
param.decorators = deserializeVecDecorator(pos + 8);
param.optional = deserializeBool(pos + 56);
param.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 48);
} else {param = {
type: 'TSParameterProperty',
accessibility,
decorators: deserializeVecDecorator(pos + 8),
override,
parameter: deserializeBindingPattern(pos + 32),
readonly,
static: false,
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
};}
}
return param;
}

Expand Down
Loading
Loading