oxc-parser 0.60.0 → 0.61.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Features
4
4
 
5
+ ### Supports WASM
6
+
7
+ See https://stackblitz.com/edit/oxc-parser for usage example.
8
+
5
9
  ### ESTree
6
10
 
7
11
  When parsing `.js` or `.jsx` files, the AST returned is fully conformant with the
package/deserialize-js.js CHANGED
@@ -361,25 +361,28 @@ function deserializeAssignmentTargetWithDefault(pos) {
361
361
  }
362
362
 
363
363
  function deserializeAssignmentTargetPropertyIdentifier(pos) {
364
+ const start = deserializeU32(pos),
365
+ end = deserializeU32(pos + 4),
366
+ key = deserializeIdentifierReference(pos + 8);
364
367
  const init = deserializeOptionExpression(pos + 40),
365
- binding = deserializeIdentifierReference(pos + 8),
368
+ keyCopy = { ...key },
366
369
  value = init === null
367
- ? binding
370
+ ? keyCopy
368
371
  : {
369
372
  type: 'AssignmentPattern',
370
- start: deserializeU32(pos),
371
- end: deserializeU32(pos + 4),
372
- left: binding,
373
+ start: start,
374
+ end: end,
375
+ left: keyCopy,
373
376
  right: init,
374
377
  };
375
378
  return {
376
379
  type: 'Property',
377
- start: deserializeU32(pos),
378
- end: deserializeU32(pos + 4),
380
+ start,
381
+ end,
379
382
  method: false,
380
383
  shorthand: true,
381
384
  computed: false,
382
- key: deserializeIdentifierReference(pos + 8),
385
+ key,
383
386
  value,
384
387
  kind: 'init',
385
388
  };
@@ -449,7 +452,7 @@ function deserializeDirective(pos) {
449
452
  start: deserializeU32(pos),
450
453
  end: deserializeU32(pos + 4),
451
454
  expression: deserializeStringLiteral(pos + 8),
452
- directive: deserializeStr(pos + 48),
455
+ directive: deserializeStr(pos + 56),
453
456
  };
454
457
  }
455
458
 
@@ -749,6 +752,7 @@ function deserializeBindingRestElement(pos) {
749
752
  }
750
753
 
751
754
  function deserializeFunction(pos) {
755
+ const params = deserializeBoxFormalParameters(pos + 72);
752
756
  return {
753
757
  type: deserializeFunctionType(pos + 8),
754
758
  start: deserializeU32(pos),
@@ -757,7 +761,7 @@ function deserializeFunction(pos) {
757
761
  expression: false,
758
762
  generator: deserializeBool(pos + 48),
759
763
  async: deserializeBool(pos + 49),
760
- params: deserializeBoxFormalParameters(pos + 72),
764
+ params,
761
765
  body: deserializeOptionBoxFunctionBody(pos + 88),
762
766
  };
763
767
  }
@@ -794,17 +798,18 @@ function deserializeFunctionBody(pos) {
794
798
  }
795
799
 
796
800
  function deserializeArrowFunctionExpression(pos) {
801
+ const expression = deserializeBool(pos + 8);
797
802
  let body = deserializeBoxFunctionBody(pos + 40);
798
803
  return {
799
804
  type: 'ArrowFunctionExpression',
800
805
  start: deserializeU32(pos),
801
806
  end: deserializeU32(pos + 4),
802
807
  id: null,
803
- expression: deserializeBool(pos + 8),
808
+ expression,
804
809
  generator: false,
805
810
  async: deserializeBool(pos + 9),
806
811
  params: deserializeBoxFormalParameters(pos + 24),
807
- body: deserializeBool(pos + 8) ? body.body[0].expression : body,
812
+ body: expression ? body.body[0].expression : body,
808
813
  };
809
814
  }
810
815
 
@@ -907,7 +912,7 @@ function deserializeImportExpression(pos) {
907
912
  function deserializeImportDeclaration(pos) {
908
913
  let specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8);
909
914
  if (specifiers === null) specifiers = [];
910
- const withClause = deserializeOptionBoxWithClause(pos + 88);
915
+ const withClause = deserializeOptionBoxWithClause(pos + 96);
911
916
  return {
912
917
  type: 'ImportDeclaration',
913
918
  start: deserializeU32(pos),
@@ -924,7 +929,7 @@ function deserializeImportSpecifier(pos) {
924
929
  start: deserializeU32(pos),
925
930
  end: deserializeU32(pos + 4),
926
931
  imported: deserializeModuleExportName(pos + 8),
927
- local: deserializeBindingIdentifier(pos + 56),
932
+ local: deserializeBindingIdentifier(pos + 64),
928
933
  };
929
934
  }
930
935
 
@@ -962,12 +967,12 @@ function deserializeImportAttribute(pos) {
962
967
  start: deserializeU32(pos),
963
968
  end: deserializeU32(pos + 4),
964
969
  key: deserializeImportAttributeKey(pos + 8),
965
- value: deserializeStringLiteral(pos + 56),
970
+ value: deserializeStringLiteral(pos + 64),
966
971
  };
967
972
  }
968
973
 
969
974
  function deserializeExportNamedDeclaration(pos) {
970
- const withClause = deserializeOptionBoxWithClause(pos + 104);
975
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
971
976
  return {
972
977
  type: 'ExportNamedDeclaration',
973
978
  start: deserializeU32(pos),
@@ -984,18 +989,18 @@ function deserializeExportDefaultDeclaration(pos) {
984
989
  type: 'ExportDefaultDeclaration',
985
990
  start: deserializeU32(pos),
986
991
  end: deserializeU32(pos + 4),
987
- declaration: deserializeExportDefaultDeclarationKind(pos + 56),
992
+ declaration: deserializeExportDefaultDeclarationKind(pos + 64),
988
993
  };
989
994
  }
990
995
 
991
996
  function deserializeExportAllDeclaration(pos) {
992
- const withClause = deserializeOptionBoxWithClause(pos + 96);
997
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
993
998
  return {
994
999
  type: 'ExportAllDeclaration',
995
1000
  start: deserializeU32(pos),
996
1001
  end: deserializeU32(pos + 4),
997
1002
  exported: deserializeOptionModuleExportName(pos + 8),
998
- source: deserializeStringLiteral(pos + 56),
1003
+ source: deserializeStringLiteral(pos + 64),
999
1004
  attributes: withClause === null ? [] : withClause.withEntries,
1000
1005
  };
1001
1006
  }
@@ -1006,7 +1011,7 @@ function deserializeExportSpecifier(pos) {
1006
1011
  start: deserializeU32(pos),
1007
1012
  end: deserializeU32(pos + 4),
1008
1013
  local: deserializeModuleExportName(pos + 8),
1009
- exported: deserializeModuleExportName(pos + 56),
1014
+ exported: deserializeModuleExportName(pos + 64),
1010
1015
  };
1011
1016
  }
1012
1017
 
@@ -1262,10 +1267,13 @@ function deserializeJSXText(pos) {
1262
1267
 
1263
1268
  function deserializeTSThisParameter(pos) {
1264
1269
  return {
1265
- type: 'TSThisParameter',
1270
+ type: 'Identifier',
1266
1271
  start: deserializeU32(pos),
1267
1272
  end: deserializeU32(pos + 4),
1273
+ name: 'this',
1268
1274
  typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
1275
+ decorators: [],
1276
+ optional: false,
1269
1277
  };
1270
1278
  }
1271
1279
 
@@ -1654,7 +1662,6 @@ function deserializeTSCallSignatureDeclaration(pos) {
1654
1662
  start: deserializeU32(pos),
1655
1663
  end: deserializeU32(pos + 4),
1656
1664
  typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 8),
1657
- thisParam: deserializeOptionTSThisParameter(pos + 16),
1658
1665
  params: deserializeBoxFormalParameters(pos + 48),
1659
1666
  returnType: deserializeOptionBoxTSTypeAnnotation(pos + 56),
1660
1667
  };
@@ -1719,14 +1726,16 @@ function deserializeTSTypePredicate(pos) {
1719
1726
  }
1720
1727
 
1721
1728
  function deserializeTSModuleDeclaration(pos) {
1729
+ const kind = deserializeTSModuleDeclarationKind(pos + 80);
1722
1730
  return {
1723
1731
  type: 'TSModuleDeclaration',
1724
1732
  start: deserializeU32(pos),
1725
1733
  end: deserializeU32(pos + 4),
1726
1734
  id: deserializeTSModuleDeclarationName(pos + 8),
1727
- body: deserializeOptionTSModuleDeclarationBody(pos + 56),
1728
- kind: deserializeTSModuleDeclarationKind(pos + 72),
1729
- declare: deserializeBool(pos + 73),
1735
+ body: deserializeOptionTSModuleDeclarationBody(pos + 64),
1736
+ kind,
1737
+ declare: deserializeBool(pos + 81),
1738
+ global: kind === 'global',
1730
1739
  };
1731
1740
  }
1732
1741
 
@@ -1775,40 +1784,19 @@ function deserializeTSImportType(pos) {
1775
1784
  start: deserializeU32(pos),
1776
1785
  end: deserializeU32(pos + 4),
1777
1786
  argument: deserializeTSType(pos + 8),
1778
- options: deserializeOptionBoxTSImportAttributes(pos + 24),
1787
+ options: deserializeOptionBoxObjectExpression(pos + 24),
1779
1788
  qualifier: deserializeOptionTSTypeName(pos + 32),
1780
1789
  typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
1781
1790
  isTypeOf: deserializeBool(pos + 56),
1782
1791
  };
1783
1792
  }
1784
1793
 
1785
- function deserializeTSImportAttributes(pos) {
1786
- return {
1787
- type: 'TSImportAttributes',
1788
- start: deserializeU32(pos),
1789
- end: deserializeU32(pos + 4),
1790
- attributesKeyword: deserializeIdentifierName(pos + 8),
1791
- elements: deserializeVecTSImportAttribute(pos + 32),
1792
- };
1793
- }
1794
-
1795
- function deserializeTSImportAttribute(pos) {
1796
- return {
1797
- type: 'TSImportAttribute',
1798
- start: deserializeU32(pos),
1799
- end: deserializeU32(pos + 4),
1800
- name: deserializeTSImportAttributeName(pos + 8),
1801
- value: deserializeExpression(pos + 56),
1802
- };
1803
- }
1804
-
1805
1794
  function deserializeTSFunctionType(pos) {
1806
1795
  return {
1807
1796
  type: 'TSFunctionType',
1808
1797
  start: deserializeU32(pos),
1809
1798
  end: deserializeU32(pos + 4),
1810
1799
  typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 8),
1811
- thisParam: deserializeOptionBoxTSThisParameter(pos + 16),
1812
1800
  params: deserializeBoxFormalParameters(pos + 24),
1813
1801
  returnType: deserializeBoxTSTypeAnnotation(pos + 32),
1814
1802
  };
@@ -3361,8 +3349,7 @@ function deserializeJSXElementName(pos) {
3361
3349
  return deserializeBoxJSXIdentifier(pos + 8);
3362
3350
  case 1:
3363
3351
  const ident = deserializeBoxIdentifierReference(pos + 8);
3364
- ident.type = 'JSXIdentifier';
3365
- return ident;
3352
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3366
3353
  case 2:
3367
3354
  return deserializeBoxJSXNamespacedName(pos + 8);
3368
3355
  case 3:
@@ -3379,8 +3366,7 @@ function deserializeJSXMemberExpressionObject(pos) {
3379
3366
  switch (uint8[pos]) {
3380
3367
  case 0:
3381
3368
  const ident = deserializeBoxIdentifierReference(pos + 8);
3382
- ident.type = 'JSXIdentifier';
3383
- return ident;
3369
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3384
3370
  case 1:
3385
3371
  return deserializeBoxJSXMemberExpression(pos + 8);
3386
3372
  case 2:
@@ -3862,17 +3848,6 @@ function deserializeTSTypeQueryExprName(pos) {
3862
3848
  }
3863
3849
  }
3864
3850
 
3865
- function deserializeTSImportAttributeName(pos) {
3866
- switch (uint8[pos]) {
3867
- case 0:
3868
- return deserializeIdentifierName(pos + 8);
3869
- case 1:
3870
- return deserializeStringLiteral(pos + 8);
3871
- default:
3872
- throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`);
3873
- }
3874
- }
3875
-
3876
3851
  function deserializeTSMappedTypeModifierOperator(pos) {
3877
3852
  switch (uint8[pos]) {
3878
3853
  case 0:
@@ -4337,7 +4312,7 @@ function deserializeVecDirective(pos) {
4337
4312
  pos = uint32[pos32];
4338
4313
  for (let i = 0; i < len; i++) {
4339
4314
  arr.push(deserializeDirective(pos));
4340
- pos += 64;
4315
+ pos += 72;
4341
4316
  }
4342
4317
  return arr;
4343
4318
  }
@@ -5108,7 +5083,7 @@ function deserializeVecImportAttribute(pos) {
5108
5083
  pos = uint32[pos32];
5109
5084
  for (let i = 0; i < len; i++) {
5110
5085
  arr.push(deserializeImportAttribute(pos));
5111
- pos += 96;
5086
+ pos += 112;
5112
5087
  }
5113
5088
  return arr;
5114
5089
  }
@@ -5125,13 +5100,13 @@ function deserializeVecExportSpecifier(pos) {
5125
5100
  pos = uint32[pos32];
5126
5101
  for (let i = 0; i < len; i++) {
5127
5102
  arr.push(deserializeExportSpecifier(pos));
5128
- pos += 112;
5103
+ pos += 128;
5129
5104
  }
5130
5105
  return arr;
5131
5106
  }
5132
5107
 
5133
5108
  function deserializeOptionStringLiteral(pos) {
5134
- if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
5109
+ if (uint8[pos + 40] === 2) return null;
5135
5110
  return deserializeStringLiteral(pos);
5136
5111
  }
5137
5112
 
@@ -5518,13 +5493,9 @@ function deserializeBoxTSTypeParameter(pos) {
5518
5493
  return deserializeTSTypeParameter(uint32[pos >> 2]);
5519
5494
  }
5520
5495
 
5521
- function deserializeBoxTSImportAttributes(pos) {
5522
- return deserializeTSImportAttributes(uint32[pos >> 2]);
5523
- }
5524
-
5525
- function deserializeOptionBoxTSImportAttributes(pos) {
5496
+ function deserializeOptionBoxObjectExpression(pos) {
5526
5497
  if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
5527
- return deserializeBoxTSImportAttributes(pos);
5498
+ return deserializeBoxObjectExpression(pos);
5528
5499
  }
5529
5500
 
5530
5501
  function deserializeOptionTSTypeName(pos) {
@@ -5532,18 +5503,6 @@ function deserializeOptionTSTypeName(pos) {
5532
5503
  return deserializeTSTypeName(pos);
5533
5504
  }
5534
5505
 
5535
- function deserializeVecTSImportAttribute(pos) {
5536
- const arr = [],
5537
- pos32 = pos >> 2,
5538
- len = uint32[pos32 + 6];
5539
- pos = uint32[pos32];
5540
- for (let i = 0; i < len; i++) {
5541
- arr.push(deserializeTSImportAttribute(pos));
5542
- pos += 72;
5543
- }
5544
- return arr;
5545
- }
5546
-
5547
5506
  function deserializeBoxTSExternalModuleReference(pos) {
5548
5507
  return deserializeTSExternalModuleReference(uint32[pos >> 2]);
5549
5508
  }
package/deserialize-ts.js CHANGED
@@ -53,6 +53,9 @@ function deserializeIdentifierName(pos) {
53
53
  start: deserializeU32(pos),
54
54
  end: deserializeU32(pos + 4),
55
55
  name: deserializeStr(pos + 8),
56
+ decorators: [],
57
+ optional: false,
58
+ typeAnnotation: null,
56
59
  };
57
60
  }
58
61
 
@@ -62,6 +65,9 @@ function deserializeIdentifierReference(pos) {
62
65
  start: deserializeU32(pos),
63
66
  end: deserializeU32(pos + 4),
64
67
  name: deserializeStr(pos + 8),
68
+ decorators: [],
69
+ optional: false,
70
+ typeAnnotation: null,
65
71
  };
66
72
  }
67
73
 
@@ -71,6 +77,9 @@ function deserializeBindingIdentifier(pos) {
71
77
  start: deserializeU32(pos),
72
78
  end: deserializeU32(pos + 4),
73
79
  name: deserializeStr(pos + 8),
80
+ decorators: [],
81
+ optional: false,
82
+ typeAnnotation: null,
74
83
  };
75
84
  }
76
85
 
@@ -364,25 +373,28 @@ function deserializeAssignmentTargetWithDefault(pos) {
364
373
  }
365
374
 
366
375
  function deserializeAssignmentTargetPropertyIdentifier(pos) {
376
+ const start = deserializeU32(pos),
377
+ end = deserializeU32(pos + 4),
378
+ key = deserializeIdentifierReference(pos + 8);
367
379
  const init = deserializeOptionExpression(pos + 40),
368
- binding = deserializeIdentifierReference(pos + 8),
380
+ keyCopy = { ...key },
369
381
  value = init === null
370
- ? binding
382
+ ? keyCopy
371
383
  : {
372
384
  type: 'AssignmentPattern',
373
- start: deserializeU32(pos),
374
- end: deserializeU32(pos + 4),
375
- left: binding,
385
+ start: start,
386
+ end: end,
387
+ left: keyCopy,
376
388
  right: init,
377
389
  };
378
390
  return {
379
391
  type: 'Property',
380
- start: deserializeU32(pos),
381
- end: deserializeU32(pos + 4),
392
+ start,
393
+ end,
382
394
  method: false,
383
395
  shorthand: true,
384
396
  computed: false,
385
- key: deserializeIdentifierReference(pos + 8),
397
+ key,
386
398
  value,
387
399
  kind: 'init',
388
400
  };
@@ -452,7 +464,7 @@ function deserializeDirective(pos) {
452
464
  start: deserializeU32(pos),
453
465
  end: deserializeU32(pos + 4),
454
466
  expression: deserializeStringLiteral(pos + 8),
455
- directive: deserializeStr(pos + 48),
467
+ directive: deserializeStr(pos + 56),
456
468
  };
457
469
  }
458
470
 
@@ -708,6 +720,7 @@ function deserializeAssignmentPattern(pos) {
708
720
  end: deserializeU32(pos + 4),
709
721
  left: deserializeBindingPattern(pos + 8),
710
722
  right: deserializeExpression(pos + 40),
723
+ decorators: [],
711
724
  };
712
725
  }
713
726
 
@@ -746,6 +759,9 @@ function deserializeArrayPattern(pos) {
746
759
  start: deserializeU32(pos),
747
760
  end: deserializeU32(pos + 4),
748
761
  elements,
762
+ decorators: [],
763
+ optional: false,
764
+ typeAnnotation: null,
749
765
  };
750
766
  }
751
767
 
@@ -759,6 +775,9 @@ function deserializeBindingRestElement(pos) {
759
775
  }
760
776
 
761
777
  function deserializeFunction(pos) {
778
+ const params = deserializeBoxFormalParameters(pos + 72);
779
+ const thisParam = deserializeOptionBoxTSThisParameter(pos + 64);
780
+ if (thisParam !== null) params.unshift(thisParam);
762
781
  return {
763
782
  type: deserializeFunctionType(pos + 8),
764
783
  start: deserializeU32(pos),
@@ -767,11 +786,10 @@ function deserializeFunction(pos) {
767
786
  expression: false,
768
787
  generator: deserializeBool(pos + 48),
769
788
  async: deserializeBool(pos + 49),
770
- params: deserializeBoxFormalParameters(pos + 72),
789
+ params,
771
790
  body: deserializeOptionBoxFunctionBody(pos + 88),
772
791
  declare: deserializeBool(pos + 50),
773
792
  typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 56),
774
- thisParam: deserializeOptionBoxTSThisParameter(pos + 64),
775
793
  returnType: deserializeOptionBoxTSTypeAnnotation(pos + 80),
776
794
  };
777
795
  }
@@ -800,9 +818,6 @@ function deserializeFormalParameter(pos) {
800
818
  typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 56),
801
819
  optional: deserializeBool(pos + 64),
802
820
  decorators: deserializeVecDecorator(pos + 8),
803
- accessibility: deserializeOptionTSAccessibility(pos + 72),
804
- readonly: deserializeBool(pos + 73),
805
- override: deserializeBool(pos + 74),
806
821
  };
807
822
  }
808
823
 
@@ -818,17 +833,18 @@ function deserializeFunctionBody(pos) {
818
833
  }
819
834
 
820
835
  function deserializeArrowFunctionExpression(pos) {
836
+ const expression = deserializeBool(pos + 8);
821
837
  let body = deserializeBoxFunctionBody(pos + 40);
822
838
  return {
823
839
  type: 'ArrowFunctionExpression',
824
840
  start: deserializeU32(pos),
825
841
  end: deserializeU32(pos + 4),
826
842
  id: null,
827
- expression: deserializeBool(pos + 8),
843
+ expression,
828
844
  generator: false,
829
845
  async: deserializeBool(pos + 9),
830
846
  params: deserializeBoxFormalParameters(pos + 24),
831
- body: deserializeBool(pos + 8) ? body.body[0].expression : body,
847
+ body: expression ? body.body[0].expression : body,
832
848
  typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 16),
833
849
  returnType: deserializeOptionBoxTSTypeAnnotation(pos + 32),
834
850
  };
@@ -956,7 +972,7 @@ function deserializeImportExpression(pos) {
956
972
  function deserializeImportDeclaration(pos) {
957
973
  let specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8);
958
974
  if (specifiers === null) specifiers = [];
959
- const withClause = deserializeOptionBoxWithClause(pos + 88);
975
+ const withClause = deserializeOptionBoxWithClause(pos + 96);
960
976
  return {
961
977
  type: 'ImportDeclaration',
962
978
  start: deserializeU32(pos),
@@ -964,7 +980,7 @@ function deserializeImportDeclaration(pos) {
964
980
  specifiers,
965
981
  source: deserializeStringLiteral(pos + 40),
966
982
  attributes: withClause === null ? [] : withClause.withEntries,
967
- importKind: deserializeImportOrExportKind(pos + 96),
983
+ importKind: deserializeImportOrExportKind(pos + 104),
968
984
  };
969
985
  }
970
986
 
@@ -974,8 +990,8 @@ function deserializeImportSpecifier(pos) {
974
990
  start: deserializeU32(pos),
975
991
  end: deserializeU32(pos + 4),
976
992
  imported: deserializeModuleExportName(pos + 8),
977
- local: deserializeBindingIdentifier(pos + 56),
978
- importKind: deserializeImportOrExportKind(pos + 88),
993
+ local: deserializeBindingIdentifier(pos + 64),
994
+ importKind: deserializeImportOrExportKind(pos + 96),
979
995
  };
980
996
  }
981
997
 
@@ -1013,12 +1029,12 @@ function deserializeImportAttribute(pos) {
1013
1029
  start: deserializeU32(pos),
1014
1030
  end: deserializeU32(pos + 4),
1015
1031
  key: deserializeImportAttributeKey(pos + 8),
1016
- value: deserializeStringLiteral(pos + 56),
1032
+ value: deserializeStringLiteral(pos + 64),
1017
1033
  };
1018
1034
  }
1019
1035
 
1020
1036
  function deserializeExportNamedDeclaration(pos) {
1021
- const withClause = deserializeOptionBoxWithClause(pos + 104);
1037
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
1022
1038
  return {
1023
1039
  type: 'ExportNamedDeclaration',
1024
1040
  start: deserializeU32(pos),
@@ -1027,7 +1043,7 @@ function deserializeExportNamedDeclaration(pos) {
1027
1043
  specifiers: deserializeVecExportSpecifier(pos + 24),
1028
1044
  source: deserializeOptionStringLiteral(pos + 56),
1029
1045
  attributes: withClause === null ? [] : withClause.withEntries,
1030
- exportKind: deserializeImportOrExportKind(pos + 96),
1046
+ exportKind: deserializeImportOrExportKind(pos + 104),
1031
1047
  };
1032
1048
  }
1033
1049
 
@@ -1036,20 +1052,20 @@ function deserializeExportDefaultDeclaration(pos) {
1036
1052
  type: 'ExportDefaultDeclaration',
1037
1053
  start: deserializeU32(pos),
1038
1054
  end: deserializeU32(pos + 4),
1039
- declaration: deserializeExportDefaultDeclarationKind(pos + 56),
1055
+ declaration: deserializeExportDefaultDeclarationKind(pos + 64),
1040
1056
  };
1041
1057
  }
1042
1058
 
1043
1059
  function deserializeExportAllDeclaration(pos) {
1044
- const withClause = deserializeOptionBoxWithClause(pos + 96);
1060
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
1045
1061
  return {
1046
1062
  type: 'ExportAllDeclaration',
1047
1063
  start: deserializeU32(pos),
1048
1064
  end: deserializeU32(pos + 4),
1049
1065
  exported: deserializeOptionModuleExportName(pos + 8),
1050
- source: deserializeStringLiteral(pos + 56),
1066
+ source: deserializeStringLiteral(pos + 64),
1051
1067
  attributes: withClause === null ? [] : withClause.withEntries,
1052
- exportKind: deserializeImportOrExportKind(pos + 104),
1068
+ exportKind: deserializeImportOrExportKind(pos + 120),
1053
1069
  };
1054
1070
  }
1055
1071
 
@@ -1059,8 +1075,8 @@ function deserializeExportSpecifier(pos) {
1059
1075
  start: deserializeU32(pos),
1060
1076
  end: deserializeU32(pos + 4),
1061
1077
  local: deserializeModuleExportName(pos + 8),
1062
- exported: deserializeModuleExportName(pos + 56),
1063
- exportKind: deserializeImportOrExportKind(pos + 104),
1078
+ exported: deserializeModuleExportName(pos + 64),
1079
+ exportKind: deserializeImportOrExportKind(pos + 120),
1064
1080
  };
1065
1081
  }
1066
1082
 
@@ -1317,10 +1333,13 @@ function deserializeJSXText(pos) {
1317
1333
 
1318
1334
  function deserializeTSThisParameter(pos) {
1319
1335
  return {
1320
- type: 'TSThisParameter',
1336
+ type: 'Identifier',
1321
1337
  start: deserializeU32(pos),
1322
1338
  end: deserializeU32(pos + 4),
1339
+ name: 'this',
1323
1340
  typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 16),
1341
+ decorators: [],
1342
+ optional: false,
1324
1343
  };
1325
1344
  }
1326
1345
 
@@ -1700,6 +1719,7 @@ function deserializeTSIndexSignature(pos) {
1700
1719
  typeAnnotation: deserializeBoxTSTypeAnnotation(pos + 40),
1701
1720
  readonly: deserializeBool(pos + 48),
1702
1721
  static: deserializeBool(pos + 49),
1722
+ accessibility: null,
1703
1723
  };
1704
1724
  }
1705
1725
 
@@ -1709,7 +1729,6 @@ function deserializeTSCallSignatureDeclaration(pos) {
1709
1729
  start: deserializeU32(pos),
1710
1730
  end: deserializeU32(pos + 4),
1711
1731
  typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 8),
1712
- thisParam: deserializeOptionTSThisParameter(pos + 16),
1713
1732
  params: deserializeBoxFormalParameters(pos + 48),
1714
1733
  returnType: deserializeOptionBoxTSTypeAnnotation(pos + 56),
1715
1734
  };
@@ -1749,6 +1768,8 @@ function deserializeTSIndexSignatureName(pos) {
1749
1768
  end: deserializeU32(pos + 4),
1750
1769
  name: deserializeStr(pos + 8),
1751
1770
  typeAnnotation: deserializeBoxTSTypeAnnotation(pos + 24),
1771
+ decorators: [],
1772
+ optional: false,
1752
1773
  };
1753
1774
  }
1754
1775
 
@@ -1774,14 +1795,16 @@ function deserializeTSTypePredicate(pos) {
1774
1795
  }
1775
1796
 
1776
1797
  function deserializeTSModuleDeclaration(pos) {
1798
+ const kind = deserializeTSModuleDeclarationKind(pos + 80);
1777
1799
  return {
1778
1800
  type: 'TSModuleDeclaration',
1779
1801
  start: deserializeU32(pos),
1780
1802
  end: deserializeU32(pos + 4),
1781
1803
  id: deserializeTSModuleDeclarationName(pos + 8),
1782
- body: deserializeOptionTSModuleDeclarationBody(pos + 56),
1783
- kind: deserializeTSModuleDeclarationKind(pos + 72),
1784
- declare: deserializeBool(pos + 73),
1804
+ body: deserializeOptionTSModuleDeclarationBody(pos + 64),
1805
+ kind,
1806
+ declare: deserializeBool(pos + 81),
1807
+ global: kind === 'global',
1785
1808
  };
1786
1809
  }
1787
1810
 
@@ -1830,40 +1853,19 @@ function deserializeTSImportType(pos) {
1830
1853
  start: deserializeU32(pos),
1831
1854
  end: deserializeU32(pos + 4),
1832
1855
  argument: deserializeTSType(pos + 8),
1833
- options: deserializeOptionBoxTSImportAttributes(pos + 24),
1856
+ options: deserializeOptionBoxObjectExpression(pos + 24),
1834
1857
  qualifier: deserializeOptionTSTypeName(pos + 32),
1835
1858
  typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
1836
1859
  isTypeOf: deserializeBool(pos + 56),
1837
1860
  };
1838
1861
  }
1839
1862
 
1840
- function deserializeTSImportAttributes(pos) {
1841
- return {
1842
- type: 'TSImportAttributes',
1843
- start: deserializeU32(pos),
1844
- end: deserializeU32(pos + 4),
1845
- attributesKeyword: deserializeIdentifierName(pos + 8),
1846
- elements: deserializeVecTSImportAttribute(pos + 32),
1847
- };
1848
- }
1849
-
1850
- function deserializeTSImportAttribute(pos) {
1851
- return {
1852
- type: 'TSImportAttribute',
1853
- start: deserializeU32(pos),
1854
- end: deserializeU32(pos + 4),
1855
- name: deserializeTSImportAttributeName(pos + 8),
1856
- value: deserializeExpression(pos + 56),
1857
- };
1858
- }
1859
-
1860
1863
  function deserializeTSFunctionType(pos) {
1861
1864
  return {
1862
1865
  type: 'TSFunctionType',
1863
1866
  start: deserializeU32(pos),
1864
1867
  end: deserializeU32(pos + 4),
1865
1868
  typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 8),
1866
- thisParam: deserializeOptionBoxTSThisParameter(pos + 16),
1867
1869
  params: deserializeBoxFormalParameters(pos + 24),
1868
1870
  returnType: deserializeBoxTSTypeAnnotation(pos + 32),
1869
1871
  };
@@ -3416,8 +3418,7 @@ function deserializeJSXElementName(pos) {
3416
3418
  return deserializeBoxJSXIdentifier(pos + 8);
3417
3419
  case 1:
3418
3420
  const ident = deserializeBoxIdentifierReference(pos + 8);
3419
- ident.type = 'JSXIdentifier';
3420
- return ident;
3421
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3421
3422
  case 2:
3422
3423
  return deserializeBoxJSXNamespacedName(pos + 8);
3423
3424
  case 3:
@@ -3434,8 +3435,7 @@ function deserializeJSXMemberExpressionObject(pos) {
3434
3435
  switch (uint8[pos]) {
3435
3436
  case 0:
3436
3437
  const ident = deserializeBoxIdentifierReference(pos + 8);
3437
- ident.type = 'JSXIdentifier';
3438
- return ident;
3438
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3439
3439
  case 1:
3440
3440
  return deserializeBoxJSXMemberExpression(pos + 8);
3441
3441
  case 2:
@@ -3917,17 +3917,6 @@ function deserializeTSTypeQueryExprName(pos) {
3917
3917
  }
3918
3918
  }
3919
3919
 
3920
- function deserializeTSImportAttributeName(pos) {
3921
- switch (uint8[pos]) {
3922
- case 0:
3923
- return deserializeIdentifierName(pos + 8);
3924
- case 1:
3925
- return deserializeStringLiteral(pos + 8);
3926
- default:
3927
- throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`);
3928
- }
3929
- }
3930
-
3931
3920
  function deserializeTSMappedTypeModifierOperator(pos) {
3932
3921
  switch (uint8[pos]) {
3933
3922
  case 0:
@@ -4392,7 +4381,7 @@ function deserializeVecDirective(pos) {
4392
4381
  pos = uint32[pos32];
4393
4382
  for (let i = 0; i < len; i++) {
4394
4383
  arr.push(deserializeDirective(pos));
4395
- pos += 64;
4384
+ pos += 72;
4396
4385
  }
4397
4386
  return arr;
4398
4387
  }
@@ -5163,7 +5152,7 @@ function deserializeVecImportAttribute(pos) {
5163
5152
  pos = uint32[pos32];
5164
5153
  for (let i = 0; i < len; i++) {
5165
5154
  arr.push(deserializeImportAttribute(pos));
5166
- pos += 96;
5155
+ pos += 112;
5167
5156
  }
5168
5157
  return arr;
5169
5158
  }
@@ -5180,13 +5169,13 @@ function deserializeVecExportSpecifier(pos) {
5180
5169
  pos = uint32[pos32];
5181
5170
  for (let i = 0; i < len; i++) {
5182
5171
  arr.push(deserializeExportSpecifier(pos));
5183
- pos += 112;
5172
+ pos += 128;
5184
5173
  }
5185
5174
  return arr;
5186
5175
  }
5187
5176
 
5188
5177
  function deserializeOptionStringLiteral(pos) {
5189
- if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
5178
+ if (uint8[pos + 40] === 2) return null;
5190
5179
  return deserializeStringLiteral(pos);
5191
5180
  }
5192
5181
 
@@ -5573,13 +5562,9 @@ function deserializeBoxTSTypeParameter(pos) {
5573
5562
  return deserializeTSTypeParameter(uint32[pos >> 2]);
5574
5563
  }
5575
5564
 
5576
- function deserializeBoxTSImportAttributes(pos) {
5577
- return deserializeTSImportAttributes(uint32[pos >> 2]);
5578
- }
5579
-
5580
- function deserializeOptionBoxTSImportAttributes(pos) {
5565
+ function deserializeOptionBoxObjectExpression(pos) {
5581
5566
  if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
5582
- return deserializeBoxTSImportAttributes(pos);
5567
+ return deserializeBoxObjectExpression(pos);
5583
5568
  }
5584
5569
 
5585
5570
  function deserializeOptionTSTypeName(pos) {
@@ -5587,18 +5572,6 @@ function deserializeOptionTSTypeName(pos) {
5587
5572
  return deserializeTSTypeName(pos);
5588
5573
  }
5589
5574
 
5590
- function deserializeVecTSImportAttribute(pos) {
5591
- const arr = [],
5592
- pos32 = pos >> 2,
5593
- len = uint32[pos32 + 6];
5594
- pos = uint32[pos32];
5595
- for (let i = 0; i < len; i++) {
5596
- arr.push(deserializeTSImportAttribute(pos));
5597
- pos += 72;
5598
- }
5599
- return arr;
5600
- }
5601
-
5602
5575
  function deserializeBoxTSExternalModuleReference(pos) {
5603
5576
  return deserializeTSExternalModuleReference(uint32[pos >> 2]);
5604
5577
  }
package/index.d.ts CHANGED
@@ -129,6 +129,7 @@ export interface OxcError {
129
129
  message: string
130
130
  labels: Array<ErrorLabel>
131
131
  helpMessage?: string
132
+ codeframe?: string
132
133
  }
133
134
 
134
135
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.60.0",
3
+ "version": "0.61.2",
4
4
  "main": "index.js",
5
5
  "browser": "wasm.mjs",
6
6
  "engines": {
@@ -38,12 +38,13 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@oxc-project/types": "^0.60.0"
41
+ "@oxc-project/types": "^0.61.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@codspeed/vitest-plugin": "^4.0.0",
45
45
  "@napi-rs/wasm-runtime": "^0.2.7",
46
- "@vitest/browser": "3.0.7",
46
+ "@vitest/browser": "3.0.8",
47
+ "esbuild": "^0.25.0",
47
48
  "playwright": "^1.51.0",
48
49
  "vitest": "3.0.8"
49
50
  },
@@ -70,23 +71,25 @@
70
71
  "dtsHeaderFile": "header.js"
71
72
  },
72
73
  "optionalDependencies": {
73
- "@oxc-parser/binding-win32-x64-msvc": "0.60.0",
74
- "@oxc-parser/binding-win32-arm64-msvc": "0.60.0",
75
- "@oxc-parser/binding-linux-x64-gnu": "0.60.0",
76
- "@oxc-parser/binding-linux-x64-musl": "0.60.0",
77
- "@oxc-parser/binding-linux-arm64-gnu": "0.60.0",
78
- "@oxc-parser/binding-linux-arm64-musl": "0.60.0",
79
- "@oxc-parser/binding-linux-arm-gnueabihf": "0.60.0",
80
- "@oxc-parser/binding-darwin-x64": "0.60.0",
81
- "@oxc-parser/binding-darwin-arm64": "0.60.0",
82
- "@oxc-parser/binding-wasm32-wasi": "0.60.0"
74
+ "@oxc-parser/binding-win32-x64-msvc": "0.61.2",
75
+ "@oxc-parser/binding-win32-arm64-msvc": "0.61.2",
76
+ "@oxc-parser/binding-linux-x64-gnu": "0.61.2",
77
+ "@oxc-parser/binding-linux-x64-musl": "0.61.2",
78
+ "@oxc-parser/binding-linux-arm64-gnu": "0.61.2",
79
+ "@oxc-parser/binding-linux-arm64-musl": "0.61.2",
80
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.61.2",
81
+ "@oxc-parser/binding-darwin-x64": "0.61.2",
82
+ "@oxc-parser/binding-darwin-arm64": "0.61.2",
83
+ "@oxc-parser/binding-wasm32-wasi": "0.61.2"
83
84
  },
84
85
  "scripts": {
85
86
  "build-dev": "napi build --no-dts-cache --platform --js bindings.js",
86
- "build": "pnpm run build-dev --release",
87
+ "build": "pnpm run build-dev --features allocator --release",
87
88
  "build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
88
89
  "build-npm-dir": "rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir .",
89
- "test": "vitest --typecheck run ./test/ && tsc",
90
+ "build-browser-bundle": "node build-browser-bundle.mjs",
91
+ "test": "pnpm run test-node run && tsc",
92
+ "test-node": "vitest --dir ./test",
90
93
  "test-browser": "vitest -c vitest.config.browser.mts",
91
94
  "bench": "vitest bench --run ./bench.bench.mjs"
92
95
  }
package/wrap.cjs CHANGED
@@ -3,7 +3,7 @@ module.exports.wrap = function wrap(result) {
3
3
  return {
4
4
  get program() {
5
5
  if (!program) {
6
- // Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
6
+ // Note: This code is repeated in `crates/oxc-wasm/update-bindings.mjs` and `napi/parser/wrap.cjs`.
7
7
  // Any changes should be applied in those 2 scripts too.
8
8
  program = JSON.parse(result.program, function(key, value) {
9
9
  // Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
package/wrap.mjs CHANGED
@@ -3,26 +3,7 @@ export function wrap(result) {
3
3
  return {
4
4
  get program() {
5
5
  if (!program) {
6
- // Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
7
- // Any changes should be applied in those 2 scripts too.
8
- program = JSON.parse(result.program, function(key, value) {
9
- // Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
10
- // This is not possible to do on Rust side, as neither can be represented correctly in JSON.
11
- if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
12
- if (Object.hasOwn(this, 'bigint')) {
13
- return BigInt(this.bigint);
14
- }
15
- if (Object.hasOwn(this, 'regex')) {
16
- const { regex } = this;
17
- try {
18
- return RegExp(regex.pattern, regex.flags);
19
- } catch (_err) {
20
- // Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
21
- }
22
- }
23
- }
24
- return value;
25
- });
6
+ program = jsonParseAst(result.program);
26
7
  }
27
8
  return program;
28
9
  },
@@ -40,3 +21,25 @@ export function wrap(result) {
40
21
  },
41
22
  };
42
23
  }
24
+
25
+ // Used by napi/playground/patch.mjs
26
+ export function jsonParseAst(ast) {
27
+ return JSON.parse(ast, function(key, value) {
28
+ // Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
29
+ // This is not possible to do on Rust side, as neither can be represented correctly in JSON.
30
+ if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
31
+ if (Object.hasOwn(this, 'bigint')) {
32
+ return BigInt(this.bigint);
33
+ }
34
+ if (Object.hasOwn(this, 'regex')) {
35
+ const { regex } = this;
36
+ try {
37
+ return RegExp(regex.pattern, regex.flags);
38
+ } catch (_err) {
39
+ // Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
40
+ }
41
+ }
42
+ }
43
+ return value;
44
+ });
45
+ }