Skip to content

Commit 4c35f4a

Browse files
committed
perf(napi/parser): optimize raw transfer deserializer for TSClassImplements (#12158)
Reduce property lookups in deserializer.
1 parent 853d2bc commit 4c35f4a

File tree

3 files changed

+18
-12
lines changed
  • crates/oxc_ast/src/serialize
  • napi/parser/generated/deserialize

3 files changed

+18
-12
lines changed

crates/oxc_ast/src/serialize/ts.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,27 +297,29 @@ impl ESTree for TSTypeNameIdentifierReference<'_, '_> {
297297
raw_deser = "
298298
let expression = DESER[TSTypeName](POS_OFFSET.expression);
299299
if (expression.type === 'TSQualifiedName') {
300+
let object = expression.left;
300301
let parent = expression = {
301302
type: 'MemberExpression',
302-
object: expression.left,
303+
object,
303304
property: expression.right,
304305
optional: false,
305306
computed: false,
306307
start: expression.start,
307308
end: expression.end,
308309
};
309310
310-
while (parent.object.type === 'TSQualifiedName') {
311-
const object = parent.object;
311+
while (object.type === 'TSQualifiedName') {
312+
const { left } = object;
312313
parent = parent.object = {
313314
type: 'MemberExpression',
314-
object: object.left,
315+
object: left,
315316
property: object.right,
316317
optional: false,
317318
computed: false,
318319
start: object.start,
319320
end: object.end,
320321
};
322+
object = left;
321323
}
322324
}
323325
expression

napi/parser/generated/deserialize/js.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,27 +1627,29 @@ function deserializeTSTypeAliasDeclaration(pos) {
16271627
function deserializeTSClassImplements(pos) {
16281628
let expression = deserializeTSTypeName(pos + 8);
16291629
if (expression.type === 'TSQualifiedName') {
1630+
let object = expression.left;
16301631
let parent = expression = {
16311632
type: 'MemberExpression',
1632-
object: expression.left,
1633+
object,
16331634
property: expression.right,
16341635
optional: false,
16351636
computed: false,
16361637
start: expression.start,
16371638
end: expression.end,
16381639
};
16391640

1640-
while (parent.object.type === 'TSQualifiedName') {
1641-
const object = parent.object;
1641+
while (object.type === 'TSQualifiedName') {
1642+
const { left } = object;
16421643
parent = parent.object = {
16431644
type: 'MemberExpression',
1644-
object: object.left,
1645+
object: left,
16451646
property: object.right,
16461647
optional: false,
16471648
computed: false,
16481649
start: object.start,
16491650
end: object.end,
16501651
};
1652+
object = left;
16511653
}
16521654
}
16531655
return {

napi/parser/generated/deserialize/ts.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,27 +1758,29 @@ function deserializeTSTypeAliasDeclaration(pos) {
17581758
function deserializeTSClassImplements(pos) {
17591759
let expression = deserializeTSTypeName(pos + 8);
17601760
if (expression.type === 'TSQualifiedName') {
1761+
let object = expression.left;
17611762
let parent = expression = {
17621763
type: 'MemberExpression',
1763-
object: expression.left,
1764+
object,
17641765
property: expression.right,
17651766
optional: false,
17661767
computed: false,
17671768
start: expression.start,
17681769
end: expression.end,
17691770
};
17701771

1771-
while (parent.object.type === 'TSQualifiedName') {
1772-
const object = parent.object;
1772+
while (object.type === 'TSQualifiedName') {
1773+
const { left } = object;
17731774
parent = parent.object = {
17741775
type: 'MemberExpression',
1775-
object: object.left,
1776+
object: left,
17761777
property: object.right,
17771778
optional: false,
17781779
computed: false,
17791780
start: object.start,
17801781
end: object.end,
17811782
};
1783+
object = left;
17821784
}
17831785
}
17841786
return {

0 commit comments

Comments
 (0)