mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(ast/estree): move start and end fields to last (#12012)
Related to #10307. Re-arrange fields in ESTree AST, so `start` and `end` are last, instead of first. Also bump `acorn-test262` submodule to include https://github.com/oxc-project/acorn-test262/pull/54, which rearranges the fields in test snapshots.
This commit is contained in:
1 parent
c71529fea0
commit
754f01d79a
18 files changed
+963
-945
No files matched your search
@@ -38,4 +38,4 @@ runs:
|
||||
show-progress: false
|
||||
repository: oxc-project/acorn-test262
|
||||
path: tasks/coverage/acorn-test262
|
||||
ref: 25df720d20c5299b016dcaa99ce0ca917e2df5b9 # Latest main at 16/6/25
|
||||
ref: d9ba02ddea22800a285c7ad24e3fbfbb00ccbb02 # Latest main at 1/7/25
|
||||
@@ -34,7 +34,7 @@ use super::{macros::inherit_variants, *};
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
#[estree(field_order(span, body, source_type, hashbang), via = ProgramConverter)]
|
||||
#[estree(field_order(body, source_type, hashbang, span), via = ProgramConverter)]
|
||||
pub struct Program<'a> {
|
||||
pub span: Span,
|
||||
pub source_type: SourceType,
|
||||
@@ -215,7 +215,7 @@ pub use match_expression;
|
||||
#[estree(
|
||||
rename = "Identifier",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, name, optional, typeAnnotation),
|
||||
field_order(decorators, name, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct IdentifierName<'a> {
|
||||
pub span: Span,
|
||||
@@ -234,7 +234,7 @@ pub struct IdentifierName<'a> {
|
||||
#[estree(
|
||||
rename = "Identifier",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, name, optional, typeAnnotation),
|
||||
field_order(decorators, name, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct IdentifierReference<'a> {
|
||||
pub span: Span,
|
||||
@@ -263,7 +263,7 @@ pub struct IdentifierReference<'a> {
|
||||
#[estree(
|
||||
rename = "Identifier",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, name, optional, typeAnnotation),
|
||||
field_order(decorators, name, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct BindingIdentifier<'a> {
|
||||
pub span: Span,
|
||||
@@ -290,7 +290,7 @@ pub struct BindingIdentifier<'a> {
|
||||
#[estree(
|
||||
rename = "Identifier",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, name, optional, typeAnnotation),
|
||||
field_order(decorators, name, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct LabelIdentifier<'a> {
|
||||
pub span: Span,
|
||||
@@ -708,7 +708,7 @@ pub struct BinaryExpression<'a> {
|
||||
#[ast(visit)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
#[estree(rename = "BinaryExpression", add_fields(operator = In), field_order(span, left, operator, right))]
|
||||
#[estree(rename = "BinaryExpression", add_fields(operator = In), field_order(left, operator, right, span))]
|
||||
pub struct PrivateInExpression<'a> {
|
||||
pub span: Span,
|
||||
pub left: PrivateIdentifier<'a>,
|
||||
@@ -855,7 +855,7 @@ pub use match_assignment_target_pattern;
|
||||
#[estree(
|
||||
rename = "ArrayPattern",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, elements, optional, typeAnnotation),
|
||||
field_order(decorators, elements, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct ArrayAssignmentTarget<'a> {
|
||||
pub span: Span,
|
||||
@@ -873,7 +873,7 @@ pub struct ArrayAssignmentTarget<'a> {
|
||||
#[estree(
|
||||
rename = "ObjectPattern",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, properties, optional, typeAnnotation),
|
||||
field_order(decorators, properties, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct ObjectAssignmentTarget<'a> {
|
||||
pub span: Span,
|
||||
@@ -891,7 +891,7 @@ pub struct ObjectAssignmentTarget<'a> {
|
||||
#[estree(
|
||||
rename = "RestElement",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull, value = TsNull),
|
||||
field_order(span, decorators, target, optional, typeAnnotation, value),
|
||||
field_order(decorators, target, optional, typeAnnotation, value, span),
|
||||
)]
|
||||
pub struct AssignmentTargetRest<'a> {
|
||||
pub span: Span,
|
||||
@@ -921,7 +921,7 @@ pub enum AssignmentTargetMaybeDefault<'a> {
|
||||
#[estree(
|
||||
rename = "AssignmentPattern",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, binding, init, optional, typeAnnotation),
|
||||
field_order(decorators, binding, init, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct AssignmentTargetWithDefault<'a> {
|
||||
pub span: Span,
|
||||
@@ -949,7 +949,7 @@ pub enum AssignmentTargetProperty<'a> {
|
||||
#[estree(
|
||||
rename = "Property",
|
||||
add_fields(kind = Init, method = False, shorthand = True, computed = False, optional = TsFalse),
|
||||
field_order(span, kind, binding, init, method, shorthand, computed, optional),
|
||||
field_order(kind, binding, init, method, shorthand, computed, optional, span),
|
||||
)]
|
||||
pub struct AssignmentTargetPropertyIdentifier<'a> {
|
||||
pub span: Span,
|
||||
@@ -968,7 +968,7 @@ pub struct AssignmentTargetPropertyIdentifier<'a> {
|
||||
#[estree(
|
||||
rename = "Property",
|
||||
add_fields(kind = Init, method = False, shorthand = False, optional = TsFalse),
|
||||
field_order(span, kind, name, binding, method, shorthand, computed, optional),
|
||||
field_order(kind, name, binding, method, shorthand, computed, optional, span),
|
||||
)]
|
||||
pub struct AssignmentTargetPropertyProperty<'a> {
|
||||
pub span: Span,
|
||||
@@ -1603,7 +1603,7 @@ pub enum BindingPatternKind<'a> {
|
||||
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
#[estree(
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, left, right, optional, typeAnnotation),
|
||||
field_order(decorators, left, right, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct AssignmentPattern<'a> {
|
||||
pub span: Span,
|
||||
@@ -1619,7 +1619,7 @@ pub struct AssignmentPattern<'a> {
|
||||
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
#[estree(
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, properties, optional, typeAnnotation),
|
||||
field_order(decorators, properties, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct ObjectPattern<'a> {
|
||||
pub span: Span,
|
||||
@@ -1634,7 +1634,7 @@ pub struct ObjectPattern<'a> {
|
||||
#[estree(
|
||||
rename = "Property",
|
||||
add_fields(kind = Init, method = False, optional = TsFalse),
|
||||
field_order(span, kind, key, value, method, shorthand, computed, optional),
|
||||
field_order(kind, key, value, method, shorthand, computed, optional, span),
|
||||
)]
|
||||
pub struct BindingProperty<'a> {
|
||||
pub span: Span,
|
||||
@@ -1652,7 +1652,7 @@ pub struct BindingProperty<'a> {
|
||||
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
#[estree(
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull),
|
||||
field_order(span, decorators, elements, optional, typeAnnotation),
|
||||
field_order(decorators, elements, optional, typeAnnotation, span),
|
||||
)]
|
||||
pub struct ArrayPattern<'a> {
|
||||
pub span: Span,
|
||||
@@ -1676,7 +1676,7 @@ pub struct ArrayPattern<'a> {
|
||||
#[estree(
|
||||
rename = "RestElement",
|
||||
add_fields(decorators = TsEmptyArray, optional = TsFalse, typeAnnotation = TsNull, value = TsNull),
|
||||
field_order(span, decorators, argument, optional, typeAnnotation, value),
|
||||
field_order(decorators, argument, optional, typeAnnotation, value, span),
|
||||
)]
|
||||
pub struct BindingRestElement<'a> {
|
||||
pub span: Span,
|
||||
|
||||
@@ -103,7 +103,7 @@ pub struct StringLiteral<'a> {
|
||||
#[estree(
|
||||
rename = "Literal",
|
||||
add_fields(bigint = BigIntLiteralBigint),
|
||||
field_order(span, value, raw, bigint),
|
||||
field_order(value, raw, bigint, span),
|
||||
)]
|
||||
pub struct BigIntLiteral<'a> {
|
||||
/// Node location in source code
|
||||
@@ -130,7 +130,7 @@ pub struct BigIntLiteral<'a> {
|
||||
#[estree(
|
||||
rename = "Literal",
|
||||
add_fields(value = RegExpLiteralValue),
|
||||
field_order(span, value, raw, regex),
|
||||
field_order(value, raw, regex, span),
|
||||
)]
|
||||
pub struct RegExpLiteral<'a> {
|
||||
/// Node location in source code
|
||||
|
||||
@@ -37,7 +37,7 @@ use super::{inherit_variants, js::*, literal::*};
|
||||
#[estree(
|
||||
rename = "Identifier",
|
||||
add_fields(name = This, decorators = EmptyArray, optional = False),
|
||||
field_order(span, decorators, name, optional, type_annotation),
|
||||
field_order(decorators, name, optional, type_annotation, span),
|
||||
)]
|
||||
pub struct TSThisParameter<'a> {
|
||||
pub span: Span,
|
||||
@@ -1084,7 +1084,7 @@ pub struct TSConstructSignatureDeclaration<'a> {
|
||||
#[estree(
|
||||
rename = "Identifier",
|
||||
add_fields(decorators = EmptyArray, optional = False),
|
||||
field_order(span, decorators, name, optional, type_annotation),
|
||||
field_order(decorators, name, optional, type_annotation, span),
|
||||
)]
|
||||
pub struct TSIndexSignatureName<'a> {
|
||||
pub span: Span,
|
||||
@@ -1438,7 +1438,7 @@ pub struct TSConstructorType<'a> {
|
||||
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
|
||||
#[estree(
|
||||
add_fields(key = TSMappedTypeKey, constraint = TSMappedTypeConstraint),
|
||||
field_order(span, key, constraint, name_type, type_annotation, optional, readonly),
|
||||
field_order(key, constraint, name_type, type_annotation, optional, readonly, span),
|
||||
)]
|
||||
pub struct TSMappedType<'a> {
|
||||
pub span: Span,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -59,32 +59,24 @@ impl ESTree for BindingPatternKindAndTsFields<'_, '_> {
|
||||
let span = match &self.kind {
|
||||
BindingPatternKind::BindingIdentifier(ident) => {
|
||||
state.serialize_field("type", &JsonSafeString("Identifier"));
|
||||
state.serialize_field("start", &ident.span.start);
|
||||
state.serialize_field("end", &ident.span.end);
|
||||
state.serialize_field("decorators", &self.decorators);
|
||||
state.serialize_field("name", &JsonSafeString(ident.name.as_str()));
|
||||
ident.span
|
||||
}
|
||||
BindingPatternKind::ObjectPattern(object) => {
|
||||
state.serialize_field("type", &JsonSafeString("ObjectPattern"));
|
||||
state.serialize_field("start", &object.span.start);
|
||||
state.serialize_field("end", &object.span.end);
|
||||
state.serialize_field("decorators", &self.decorators);
|
||||
state.serialize_field("properties", &Concat2(&object.properties, &object.rest));
|
||||
object.span
|
||||
}
|
||||
BindingPatternKind::ArrayPattern(array) => {
|
||||
state.serialize_field("type", &JsonSafeString("ArrayPattern"));
|
||||
state.serialize_field("start", &array.span.start);
|
||||
state.serialize_field("end", &array.span.end);
|
||||
state.serialize_field("decorators", &self.decorators);
|
||||
state.serialize_field("elements", &Concat2(&array.elements, &array.rest));
|
||||
array.span
|
||||
}
|
||||
BindingPatternKind::AssignmentPattern(assignment) => {
|
||||
state.serialize_field("type", &JsonSafeString("AssignmentPattern"));
|
||||
state.serialize_field("start", &assignment.span.start);
|
||||
state.serialize_field("end", &assignment.span.end);
|
||||
state.serialize_field("decorators", &self.decorators);
|
||||
state.serialize_field("left", &assignment.left);
|
||||
state.serialize_field("right", &assignment.right);
|
||||
@@ -95,6 +87,8 @@ impl ESTree for BindingPatternKindAndTsFields<'_, '_> {
|
||||
state.serialize_field("optional", &self.optional);
|
||||
state.serialize_field("typeAnnotation", &self.type_annotation);
|
||||
|
||||
state.serialize_field("start", &span.start);
|
||||
state.serialize_field("end", &span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[span.start, span.end]);
|
||||
}
|
||||
@@ -131,8 +125,6 @@ impl ESTree for CatchParameterConverter<'_, '_> {
|
||||
pos = uint32[(POS_OFFSET.rest) >> 2];
|
||||
params.push({
|
||||
type: 'RestElement',
|
||||
start: DESER[u32]( POS_OFFSET<BindingRestElement>.span.start ),
|
||||
end: DESER[u32]( POS_OFFSET<BindingRestElement>.span.end ),
|
||||
/* IF_TS */
|
||||
decorators: [],
|
||||
/* END_IF_TS */
|
||||
@@ -144,6 +136,8 @@ impl ESTree for CatchParameterConverter<'_, '_> {
|
||||
),
|
||||
value: null,
|
||||
/* END_IF_TS */
|
||||
start: DESER[u32]( POS_OFFSET<BindingRestElement>.span.start ),
|
||||
end: DESER[u32]( POS_OFFSET<BindingRestElement>.span.end ),
|
||||
});
|
||||
}
|
||||
params
|
||||
@@ -175,13 +169,13 @@ impl ESTree for FormalParametersRest<'_, '_> {
|
||||
let rest = self.0;
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("RestElement"));
|
||||
state.serialize_field("start", &rest.span.start);
|
||||
state.serialize_field("end", &rest.span.end);
|
||||
state.serialize_ts_field("decorators", &EmptyArray(()));
|
||||
state.serialize_field("argument", &rest.argument.kind);
|
||||
state.serialize_ts_field("optional", &rest.argument.optional);
|
||||
state.serialize_ts_field("typeAnnotation", &rest.argument.type_annotation);
|
||||
state.serialize_ts_field("value", &Null(()));
|
||||
state.serialize_field("start", &rest.span.start);
|
||||
state.serialize_field("end", &rest.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[rest.span.start, rest.span.end]);
|
||||
}
|
||||
@@ -214,14 +208,14 @@ impl ESTree for FormalParametersRest<'_, '_> {
|
||||
} else {
|
||||
param = {
|
||||
type: 'TSParameterProperty',
|
||||
start: DESER[u32](POS_OFFSET.span.start),
|
||||
end: DESER[u32](POS_OFFSET.span.end),
|
||||
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
|
||||
@@ -238,14 +232,14 @@ impl ESTree for FormalParameterConverter<'_, '_> {
|
||||
if param.has_modifier() {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("TSParameterProperty"));
|
||||
state.serialize_field("start", ¶m.span.start);
|
||||
state.serialize_field("end", ¶m.span.end);
|
||||
state.serialize_field("accessibility", ¶m.accessibility);
|
||||
state.serialize_field("decorators", ¶m.decorators);
|
||||
state.serialize_field("override", ¶m.r#override);
|
||||
state.serialize_field("parameter", ¶m.pattern);
|
||||
state.serialize_field("readonly", ¶m.readonly);
|
||||
state.serialize_field("static", &false);
|
||||
state.serialize_field("start", ¶m.span.start);
|
||||
state.serialize_field("end", ¶m.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[param.span.start, param.span.end]);
|
||||
}
|
||||
@@ -429,8 +423,6 @@ impl ESTree for ArrowFunctionExpressionBody<'_> {
|
||||
? keyCopy
|
||||
: {
|
||||
type: 'AssignmentPattern',
|
||||
start: THIS.start,
|
||||
end: THIS.end,
|
||||
/* IF_TS */
|
||||
decorators: [],
|
||||
/* END_IF_TS */
|
||||
@@ -440,6 +432,8 @@ impl ESTree for ArrowFunctionExpressionBody<'_> {
|
||||
optional: false,
|
||||
typeAnnotation: null,
|
||||
/* END_IF_TS */
|
||||
start: THIS.start,
|
||||
end: THIS.end,
|
||||
};
|
||||
value
|
||||
"
|
||||
@@ -453,13 +447,13 @@ impl ESTree for AssignmentTargetPropertyIdentifierInit<'_> {
|
||||
if let Some(init) = &self.0.init {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("AssignmentPattern"));
|
||||
state.serialize_field("start", &self.0.span.start);
|
||||
state.serialize_field("end", &self.0.span.end);
|
||||
state.serialize_ts_field("decorators", &EmptyArray(()));
|
||||
state.serialize_field("left", &self.0.binding);
|
||||
state.serialize_field("right", init);
|
||||
state.serialize_ts_field("optional", &false);
|
||||
state.serialize_ts_field("typeAnnotation", &Null(()));
|
||||
state.serialize_field("start", &self.0.span.start);
|
||||
state.serialize_field("end", &self.0.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[self.0.span.start, self.0.span.end]);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ impl ESTree for JSXElementOpeningElement<'_, '_> {
|
||||
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("JSXOpeningElement"));
|
||||
state.serialize_field("start", &opening_element.span.start);
|
||||
state.serialize_field("end", &opening_element.span.end);
|
||||
state.serialize_field("name", &opening_element.name);
|
||||
state.serialize_ts_field("typeArguments", &opening_element.type_arguments);
|
||||
state.serialize_field("attributes", &opening_element.attributes);
|
||||
state.serialize_field("selfClosing", &element.closing_element.is_none());
|
||||
state.serialize_field("start", &opening_element.span.start);
|
||||
state.serialize_field("end", &opening_element.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[opening_element.span.start, opening_element.span.end]);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl ESTree for JSXOpeningElementSelfClosing<'_, '_> {
|
||||
ts_type = "JSXIdentifier",
|
||||
raw_deser = "
|
||||
const ident = DESER[Box<IdentifierReference>](POS);
|
||||
{ type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name }
|
||||
{ type: 'JSXIdentifier', name: ident.name, start: ident.start, end: ident.end }
|
||||
"
|
||||
)]
|
||||
pub struct JSXElementIdentifierReference<'a, 'b>(pub &'b IdentifierReference<'a>);
|
||||
@@ -79,7 +79,7 @@ impl ESTree for JSXElementIdentifierReference<'_, '_> {
|
||||
ts_type = "JSXIdentifier",
|
||||
raw_deser = "
|
||||
const thisExpr = DESER[Box<ThisExpression>](POS);
|
||||
{ type: 'JSXIdentifier', start: thisExpr.start, end: thisExpr.end, name: 'this' }
|
||||
{ type: 'JSXIdentifier', name: 'this', start: thisExpr.start, end: thisExpr.end }
|
||||
"
|
||||
)]
|
||||
pub struct JSXElementThisExpression<'b>(pub &'b ThisExpression);
|
||||
|
||||
@@ -202,7 +202,7 @@ impl ESTree for RegExpFlagsConverter<'_> {
|
||||
value.cooked = value.cooked
|
||||
.replace(/\uFFFD(.{4})/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
|
||||
}
|
||||
{ type: 'TemplateElement', start, end, value, tail }
|
||||
{ type: 'TemplateElement', value, tail, start, end }
|
||||
"#)]
|
||||
pub struct TemplateElementConverter<'a, 'b>(pub &'b TemplateElement<'a>);
|
||||
|
||||
@@ -213,17 +213,17 @@ impl ESTree for TemplateElementConverter<'_, '_> {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("TemplateElement"));
|
||||
|
||||
state.serialize_field("value", &TemplateElementValue(element));
|
||||
state.serialize_field("tail", &element.tail);
|
||||
|
||||
let mut span = element.span;
|
||||
if S::INCLUDE_TS_FIELDS {
|
||||
span.start -= 1;
|
||||
span.end += if element.tail { 1 } else { 2 };
|
||||
}
|
||||
|
||||
state.serialize_field("start", &span.start);
|
||||
state.serialize_field("end", &span.end);
|
||||
|
||||
state.serialize_field("value", &TemplateElementValue(element));
|
||||
state.serialize_field("tail", &element.tail);
|
||||
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[span.start, span.end]);
|
||||
}
|
||||
|
||||
@@ -152,11 +152,11 @@ impl Program<'_> {
|
||||
|
||||
const program = {
|
||||
type: 'Program',
|
||||
start,
|
||||
end,
|
||||
body,
|
||||
sourceType: DESER[ModuleKind](POS_OFFSET.source_type.module_kind),
|
||||
hashbang: DESER[Option<Hashbang>](POS_OFFSET.hashbang),
|
||||
start,
|
||||
end,
|
||||
};
|
||||
program
|
||||
")]
|
||||
@@ -165,19 +165,21 @@ pub struct ProgramConverter<'a, 'b>(pub &'b Program<'a>);
|
||||
impl ESTree for ProgramConverter<'_, '_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let program = self.0;
|
||||
let span_start =
|
||||
if S::INCLUDE_TS_FIELDS { get_ts_start_span(program) } else { program.span.start };
|
||||
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("Program"));
|
||||
state.serialize_field("start", &span_start);
|
||||
state.serialize_field("end", &program.span.end);
|
||||
state.serialize_field("body", &Concat2(&program.directives, &program.body));
|
||||
state.serialize_field("sourceType", &program.source_type.module_kind());
|
||||
state.serialize_field("hashbang", &program.hashbang);
|
||||
|
||||
let span_start =
|
||||
if S::INCLUDE_TS_FIELDS { get_ts_start_span(program) } else { program.span.start };
|
||||
state.serialize_field("start", &span_start);
|
||||
state.serialize_field("end", &program.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[span_start, program.span.end]);
|
||||
}
|
||||
|
||||
state.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ impl ESTree for ExpressionStatementDirective<'_, '_> {
|
||||
if (innerId.type === 'Identifier') {
|
||||
id = {
|
||||
type: 'TSQualifiedName',
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
};
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
@@ -77,10 +77,10 @@ impl ESTree for ExpressionStatementDirective<'_, '_> {
|
||||
}
|
||||
innerId.left = {
|
||||
type: 'TSQualifiedName',
|
||||
start: id.start,
|
||||
end: innerId.left.end,
|
||||
left: id,
|
||||
right: innerId.left,
|
||||
start: id.start,
|
||||
end: innerId.left.end,
|
||||
};
|
||||
id = body.id;
|
||||
}
|
||||
@@ -89,8 +89,8 @@ impl ESTree for ExpressionStatementDirective<'_, '_> {
|
||||
|
||||
// Skip `body` field if `null`
|
||||
const node = body === null
|
||||
? { type: 'TSModuleDeclaration', start, end, id, kind, declare, global }
|
||||
: { type: 'TSModuleDeclaration', start, end, id, body, kind, declare, global };
|
||||
? { type: 'TSModuleDeclaration', id, kind, declare, global, start, end }
|
||||
: { type: 'TSModuleDeclaration', id, body, kind, declare, global, start, end };
|
||||
node
|
||||
")]
|
||||
pub struct TSModuleDeclarationConverter<'a, 'b>(pub &'b TSModuleDeclaration<'a>);
|
||||
@@ -101,8 +101,6 @@ impl ESTree for TSModuleDeclarationConverter<'_, '_> {
|
||||
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("TSModuleDeclaration"));
|
||||
state.serialize_field("start", &module.span.start);
|
||||
state.serialize_field("end", &module.span.end);
|
||||
|
||||
match &module.body {
|
||||
Some(TSModuleDeclarationBody::TSModuleDeclaration(inner_module)) => {
|
||||
@@ -158,6 +156,8 @@ impl ESTree for TSModuleDeclarationConverter<'_, '_> {
|
||||
state.serialize_field("declare", &module.declare);
|
||||
state.serialize_field("global", &TSModuleDeclarationGlobal(module));
|
||||
|
||||
state.serialize_field("start", &module.span.start);
|
||||
state.serialize_field("end", &module.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[module.span.start, module.span.end]);
|
||||
}
|
||||
@@ -173,13 +173,10 @@ impl ESTree for TSModuleDeclarationIdParts<'_, '_> {
|
||||
let parts = self.0;
|
||||
assert!(!parts.is_empty());
|
||||
|
||||
let span_start = parts[0].span.start;
|
||||
let (&last, rest) = parts.split_last().unwrap();
|
||||
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("TSQualifiedName"));
|
||||
state.serialize_field("start", &span_start);
|
||||
state.serialize_field("end", &last.span.end);
|
||||
|
||||
if rest.len() == 1 {
|
||||
// Only one part remaining (e.g. `X`). Serialize as `Identifier`.
|
||||
@@ -191,6 +188,9 @@ impl ESTree for TSModuleDeclarationIdParts<'_, '_> {
|
||||
|
||||
state.serialize_field("right", last);
|
||||
|
||||
let span_start = parts[0].span.start;
|
||||
state.serialize_field("start", &span_start);
|
||||
state.serialize_field("end", &last.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[span_start, last.span.end]);
|
||||
}
|
||||
@@ -307,24 +307,24 @@ impl ESTree for TSTypeNameIdentifierReference<'_, '_> {
|
||||
if (expression.type === 'TSQualifiedName') {
|
||||
let parent = expression = {
|
||||
type: 'MemberExpression',
|
||||
start: expression.start,
|
||||
end: expression.end,
|
||||
object: expression.left,
|
||||
property: expression.right,
|
||||
optional: false,
|
||||
computed: false,
|
||||
start: expression.start,
|
||||
end: expression.end,
|
||||
};
|
||||
|
||||
while (parent.object.type === 'TSQualifiedName') {
|
||||
const object = parent.object;
|
||||
parent = parent.object = {
|
||||
type: 'MemberExpression',
|
||||
start: object.start,
|
||||
end: object.end,
|
||||
object: object.left,
|
||||
property: object.right,
|
||||
optional: false,
|
||||
computed: false,
|
||||
start: object.start,
|
||||
end: object.end,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -353,12 +353,12 @@ impl ESTree for TSTypeNameAsMemberExpression<'_, '_> {
|
||||
// Recursively convert `left` to `MemberExpression` too if it's a `TSQualifiedName`.
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("MemberExpression"));
|
||||
state.serialize_field("start", &name.span.start);
|
||||
state.serialize_field("end", &name.span.end);
|
||||
state.serialize_field("object", &TSTypeNameAsMemberExpression(&name.left));
|
||||
state.serialize_field("property", &name.right);
|
||||
state.serialize_field("optional", &false);
|
||||
state.serialize_field("computed", &false);
|
||||
state.serialize_field("start", &name.span.start);
|
||||
state.serialize_field("end", &name.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[name.span.start, name.span.end]);
|
||||
}
|
||||
|
||||
@@ -50,13 +50,13 @@ impl ESTree for ImportImportName<'_> {
|
||||
impl ESTree for ExportEntry<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("start", &self.span.start);
|
||||
state.serialize_field("end", &self.span.end);
|
||||
state.serialize_field("moduleRequest", &self.module_request);
|
||||
state.serialize_field("importName", &self.import_name);
|
||||
state.serialize_field("exportName", &self.export_name);
|
||||
state.serialize_field("localName", &self.local_name);
|
||||
state.serialize_field("isType", &self.is_type);
|
||||
state.serialize_field("start", &self.span.start);
|
||||
state.serialize_field("end", &self.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[self.span.start, self.span.end]);
|
||||
}
|
||||
@@ -102,9 +102,9 @@ impl ESTree for ExportLocalName<'_> {
|
||||
impl ESTree for DynamicImport {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("moduleRequest", &self.module_request);
|
||||
state.serialize_field("start", &self.span.start);
|
||||
state.serialize_field("end", &self.span.end);
|
||||
state.serialize_field("moduleRequest", &self.module_request);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[self.span.start, self.span.end]);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ submodules:
|
||||
just clone-submodule tasks/coverage/babel https://github.com/babel/babel.git 1d4546bcb80009303aab386b59f4df1fd335c1d5
|
||||
just clone-submodule tasks/coverage/typescript https://github.com/microsoft/TypeScript.git 81c951894e93bdc37c6916f18adcd80de76679bc
|
||||
just clone-submodule tasks/prettier_conformance/prettier https://github.com/prettier/prettier.git 7584432401a47a26943dd7a9ca9a8e032ead7285
|
||||
just clone-submodule tasks/coverage/acorn-test262 https://github.com/oxc-project/acorn-test262 25df720d20c5299b016dcaa99ce0ca917e2df5b9
|
||||
just clone-submodule tasks/coverage/acorn-test262 https://github.com/oxc-project/acorn-test262 d9ba02ddea22800a285c7ad24e3fbfbb00ccbb02
|
||||
just update-transformer-fixtures
|
||||
|
||||
# Install git pre-commit to format files
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -70,10 +70,10 @@ impl ESTree for EcmaScriptModule<'_> {
|
||||
impl ESTree for StaticImport<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("start", &self.span.start);
|
||||
state.serialize_field("end", &self.span.end);
|
||||
state.serialize_field("moduleRequest", &self.module_request);
|
||||
state.serialize_field("entries", &self.entries);
|
||||
state.serialize_field("start", &self.span.start);
|
||||
state.serialize_field("end", &self.span.end);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[self.span.start, self.span.end]);
|
||||
}
|
||||
@@ -84,9 +84,9 @@ impl ESTree for StaticImport<'_> {
|
||||
impl ESTree for StaticExport<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("entries", &self.entries);
|
||||
state.serialize_field("start", &self.span.start);
|
||||
state.serialize_field("end", &self.span.end);
|
||||
state.serialize_field("entries", &self.entries);
|
||||
if state.ranges() {
|
||||
state.serialize_field("range", &[self.span.start, self.span.end]);
|
||||
}
|
||||
|
||||
@@ -203,6 +203,13 @@ function assertRawAndStandardMatch(filename, sourceText, pretty, expect) {
|
||||
const { program: programStandard, comments: commentsStandard, module: moduleStandard, errors: errorsStandard } =
|
||||
retStandard;
|
||||
|
||||
// Re-arrange fields to match raw transfer.
|
||||
// We don't want to change field order of the Rust structs, but want `start` and `end` last.
|
||||
// Field order doesn't matter much anyway for module record.
|
||||
moveStartAndEndToLast(moduleStandard.staticImports, true);
|
||||
moveStartAndEndToLast(moduleStandard.staticExports, true);
|
||||
moveStartAndEndToLast(moduleStandard.dynamicImports, false);
|
||||
|
||||
// @ts-ignore
|
||||
const retRaw = parseSync(filename, sourceText, { experimentalRawTransfer: true });
|
||||
const { program: programRaw, comments: commentsRaw } = retRaw;
|
||||
@@ -222,15 +229,29 @@ function assertRawAndStandardMatch(filename, sourceText, pretty, expect) {
|
||||
expect(jsonRaw).toEqual(jsonStandard);
|
||||
}
|
||||
|
||||
function moveStartAndEndToLast(arr, reorderEntries) {
|
||||
for (const obj of arr) {
|
||||
const { start, end } = obj;
|
||||
delete obj.start;
|
||||
delete obj.end;
|
||||
obj.start = start;
|
||||
obj.end = end;
|
||||
if (reorderEntries) moveStartAndEndToLast(obj.entries, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Acorn JSON files always end with:
|
||||
// ```
|
||||
// "sourceType": "script",
|
||||
// "hashbang": null
|
||||
// "hashbang": null,
|
||||
// "start": 0,
|
||||
// "end": <some integer>,
|
||||
// }
|
||||
// ```
|
||||
// For speed, extract `sourceType` with a slice, rather than parsing the JSON.
|
||||
function getSourceTypeFromJSON(json) {
|
||||
return json.slice(-29, -23);
|
||||
const index = json.lastIndexOf('"sourceType": "');
|
||||
return json.slice(index + 15, index + 21);
|
||||
}
|
||||
|
||||
// Stringify to JSON, replacing values which are invalid in JSON.
|
||||
|
||||
@@ -263,9 +263,9 @@ fn prepare_field_orders(schema: &mut Schema, estree_derive_id: DeriveId) {
|
||||
// No field order specified with `#[estree(field_order(...))]`.
|
||||
// Default field order is:
|
||||
// 1. `type` field (if present)
|
||||
// 2. `span` field (if present)
|
||||
// 3. Struct fields, in definition order.
|
||||
// 4. Extra fields (`#[estree(add_fields(...)]`), in order.
|
||||
// 2. Struct fields, in definition order.
|
||||
// 3. Extra fields (`#[estree(add_fields(...)]`), in order.
|
||||
// 4. `span` field (if present)
|
||||
let mut field_indices = vec![];
|
||||
let mut type_field_index = None;
|
||||
let mut span_field_index = None;
|
||||
@@ -280,9 +280,6 @@ fn prepare_field_orders(schema: &mut Schema, estree_derive_id: DeriveId) {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(span_field_index) = span_field_index {
|
||||
field_indices.insert(0, span_field_index);
|
||||
}
|
||||
if let Some(type_field_index) = type_field_index {
|
||||
field_indices.insert(0, type_field_index);
|
||||
}
|
||||
@@ -295,6 +292,10 @@ fn prepare_field_orders(schema: &mut Schema, estree_derive_id: DeriveId) {
|
||||
field_indices.extend(first_index..=last_index);
|
||||
}
|
||||
|
||||
if let Some(span_field_index) = span_field_index {
|
||||
field_indices.push(span_field_index);
|
||||
}
|
||||
|
||||
let struct_def = schema.struct_def_mut(type_id);
|
||||
struct_def.estree.field_indices = field_indices;
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
commit: 25df720d
|
||||
commit: d9ba02dd
|
||||
|
||||
estree_acorn_jsx Summary:
|
||||
AST Parsed : 39/39 (100.00%)
|
||||
|
||||
Reference in new issue
Block a user