Skip to content

Commit 6feab7e

Browse files
committed
fix(ast/estree): remove custom serializer for MethodDefinition key field (#11763)
Remove the custom ESTree serializer for `MethodDefinition`'s `key` field. This serializer was required to replicate a bug in TS-ESLint, which they've now fixed. This fixes the test case which was broken by #11762.
1 parent ea30fff commit 6feab7e

File tree

5 files changed

+4
-67
lines changed

5 files changed

+4
-67
lines changed

crates/oxc_ast/src/ast/js.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,6 @@ pub struct MethodDefinition<'a> {
20972097
/// This will always be true when an `abstract` modifier is used on the method.
20982098
pub r#type: MethodDefinitionType,
20992099
pub decorators: Vec<'a, Decorator<'a>>,
2100-
#[estree(via = MethodDefinitionKey)]
21012100
pub key: PropertyKey<'a>,
21022101
#[visit(args(flags = match self.kind {
21032102
MethodDefinitionKind::Get => ScopeFlags::Function | ScopeFlags::GetAccessor,

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ impl ESTree for MethodDefinition<'_> {
14991499
state.serialize_field("start", &self.span.start);
15001500
state.serialize_field("end", &self.span.end);
15011501
state.serialize_field("decorators", &self.decorators);
1502-
state.serialize_field("key", &crate::serialize::js::MethodDefinitionKey(self));
1502+
state.serialize_field("key", &self.key);
15031503
state.serialize_field("value", &self.value);
15041504
state.serialize_field("kind", &self.kind);
15051505
state.serialize_field("computed", &self.computed);

crates/oxc_ast/src/serialize/js.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use oxc_estree::{
33
Concat2, ConcatElement, ESTree, JsonSafeString, SequenceSerializer, Serializer,
44
StructSerializer,
55
};
6-
use oxc_span::GetSpan;
76

87
use crate::ast::*;
98

@@ -380,52 +379,6 @@ impl ESTree for ExportAllDeclarationWithClause<'_, '_> {
380379
// Misc
381380
// ----------------------------------------
382381

383-
/// Serializer for `key` field of `MethodDefinition`.
384-
///
385-
/// In TS-ESTree `"constructor"` in `class C { "constructor"() {} }`
386-
/// is represented as an `Identifier`.
387-
/// In Acorn and Espree, it's a `Literal`.
388-
/// <https://github.com/typescript-eslint/typescript-eslint/issues/11084>
389-
#[ast_meta]
390-
#[estree(
391-
ts_type = "PropertyKey",
392-
raw_deser = "
393-
/* IF_JS */
394-
DESER[PropertyKey](POS_OFFSET.key)
395-
/* END_IF_JS */
396-
397-
/* IF_TS */
398-
let key = DESER[PropertyKey](POS_OFFSET.key);
399-
if (THIS.kind === 'constructor') {
400-
key = {
401-
type: 'Identifier',
402-
start: key.start,
403-
end: key.end,
404-
decorators: [],
405-
name: 'constructor',
406-
optional: false,
407-
typeAnnotation: null,
408-
};
409-
}
410-
key
411-
/* END_IF_TS */
412-
"
413-
)]
414-
pub struct MethodDefinitionKey<'a, 'b>(pub &'b MethodDefinition<'a>);
415-
416-
impl ESTree for MethodDefinitionKey<'_, '_> {
417-
fn serialize<S: Serializer>(&self, serializer: S) {
418-
let method = self.0;
419-
if S::INCLUDE_TS_FIELDS && method.kind == MethodDefinitionKind::Constructor {
420-
// `key` can only be either an identifier `constructor`, or string `"constructor"`
421-
let span = method.key.span();
422-
IdentifierName { span, name: Atom::from("constructor") }.serialize(serializer);
423-
} else {
424-
method.key.serialize(serializer);
425-
}
426-
}
427-
}
428-
429382
/// Serializer for `body` field of `ArrowFunctionExpression`.
430383
///
431384
/// Serialize as either an expression (if `expression` property is set),

napi/parser/generated/deserialize/ts.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -956,27 +956,14 @@ function deserializeClassBody(pos) {
956956
}
957957

958958
function deserializeMethodDefinition(pos) {
959-
const kind = deserializeMethodDefinitionKind(pos + 57);
960-
let key = deserializePropertyKey(pos + 32);
961-
if (kind === 'constructor') {
962-
key = {
963-
type: 'Identifier',
964-
start: key.start,
965-
end: key.end,
966-
decorators: [],
967-
name: 'constructor',
968-
optional: false,
969-
typeAnnotation: null,
970-
};
971-
}
972959
return {
973960
type: deserializeMethodDefinitionType(pos + 56),
974961
start: deserializeU32(pos),
975962
end: deserializeU32(pos + 4),
976963
decorators: deserializeVecDecorator(pos + 8),
977-
key,
964+
key: deserializePropertyKey(pos + 32),
978965
value: deserializeBoxFunction(pos + 48),
979-
kind,
966+
kind: deserializeMethodDefinitionKind(pos + 57),
980967
computed: deserializeBool(pos + 58),
981968
static: deserializeBool(pos + 59),
982969
override: deserializeBool(pos + 60),

tasks/coverage/snapshots/estree_typescript.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ commit: 81c95189
22

33
estree_typescript Summary:
44
AST Parsed : 6489/6489 (100.00%)
5-
Positive Passed: 6485/6489 (99.94%)
6-
Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts
7-
5+
Positive Passed: 6486/6489 (99.95%)
86
Mismatch: tasks/coverage/typescript/tests/cases/conformance/jsx/jsxReactTestSuite.tsx
97

108
Mismatch: tasks/coverage/typescript/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx

0 commit comments

Comments
 (0)