oxc-parser 0.60.0 → 0.61.0

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
@@ -449,7 +449,7 @@ function deserializeDirective(pos) {
449
449
  start: deserializeU32(pos),
450
450
  end: deserializeU32(pos + 4),
451
451
  expression: deserializeStringLiteral(pos + 8),
452
- directive: deserializeStr(pos + 48),
452
+ directive: deserializeStr(pos + 56),
453
453
  };
454
454
  }
455
455
 
@@ -907,7 +907,7 @@ function deserializeImportExpression(pos) {
907
907
  function deserializeImportDeclaration(pos) {
908
908
  let specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8);
909
909
  if (specifiers === null) specifiers = [];
910
- const withClause = deserializeOptionBoxWithClause(pos + 88);
910
+ const withClause = deserializeOptionBoxWithClause(pos + 96);
911
911
  return {
912
912
  type: 'ImportDeclaration',
913
913
  start: deserializeU32(pos),
@@ -924,7 +924,7 @@ function deserializeImportSpecifier(pos) {
924
924
  start: deserializeU32(pos),
925
925
  end: deserializeU32(pos + 4),
926
926
  imported: deserializeModuleExportName(pos + 8),
927
- local: deserializeBindingIdentifier(pos + 56),
927
+ local: deserializeBindingIdentifier(pos + 64),
928
928
  };
929
929
  }
930
930
 
@@ -962,12 +962,12 @@ function deserializeImportAttribute(pos) {
962
962
  start: deserializeU32(pos),
963
963
  end: deserializeU32(pos + 4),
964
964
  key: deserializeImportAttributeKey(pos + 8),
965
- value: deserializeStringLiteral(pos + 56),
965
+ value: deserializeStringLiteral(pos + 64),
966
966
  };
967
967
  }
968
968
 
969
969
  function deserializeExportNamedDeclaration(pos) {
970
- const withClause = deserializeOptionBoxWithClause(pos + 104);
970
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
971
971
  return {
972
972
  type: 'ExportNamedDeclaration',
973
973
  start: deserializeU32(pos),
@@ -984,18 +984,18 @@ function deserializeExportDefaultDeclaration(pos) {
984
984
  type: 'ExportDefaultDeclaration',
985
985
  start: deserializeU32(pos),
986
986
  end: deserializeU32(pos + 4),
987
- declaration: deserializeExportDefaultDeclarationKind(pos + 56),
987
+ declaration: deserializeExportDefaultDeclarationKind(pos + 64),
988
988
  };
989
989
  }
990
990
 
991
991
  function deserializeExportAllDeclaration(pos) {
992
- const withClause = deserializeOptionBoxWithClause(pos + 96);
992
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
993
993
  return {
994
994
  type: 'ExportAllDeclaration',
995
995
  start: deserializeU32(pos),
996
996
  end: deserializeU32(pos + 4),
997
997
  exported: deserializeOptionModuleExportName(pos + 8),
998
- source: deserializeStringLiteral(pos + 56),
998
+ source: deserializeStringLiteral(pos + 64),
999
999
  attributes: withClause === null ? [] : withClause.withEntries,
1000
1000
  };
1001
1001
  }
@@ -1006,7 +1006,7 @@ function deserializeExportSpecifier(pos) {
1006
1006
  start: deserializeU32(pos),
1007
1007
  end: deserializeU32(pos + 4),
1008
1008
  local: deserializeModuleExportName(pos + 8),
1009
- exported: deserializeModuleExportName(pos + 56),
1009
+ exported: deserializeModuleExportName(pos + 64),
1010
1010
  };
1011
1011
  }
1012
1012
 
@@ -1724,9 +1724,9 @@ function deserializeTSModuleDeclaration(pos) {
1724
1724
  start: deserializeU32(pos),
1725
1725
  end: deserializeU32(pos + 4),
1726
1726
  id: deserializeTSModuleDeclarationName(pos + 8),
1727
- body: deserializeOptionTSModuleDeclarationBody(pos + 56),
1728
- kind: deserializeTSModuleDeclarationKind(pos + 72),
1729
- declare: deserializeBool(pos + 73),
1727
+ body: deserializeOptionTSModuleDeclarationBody(pos + 64),
1728
+ kind: deserializeTSModuleDeclarationKind(pos + 80),
1729
+ declare: deserializeBool(pos + 81),
1730
1730
  };
1731
1731
  }
1732
1732
 
@@ -1775,33 +1775,13 @@ function deserializeTSImportType(pos) {
1775
1775
  start: deserializeU32(pos),
1776
1776
  end: deserializeU32(pos + 4),
1777
1777
  argument: deserializeTSType(pos + 8),
1778
- options: deserializeOptionBoxTSImportAttributes(pos + 24),
1778
+ options: deserializeOptionBoxObjectExpression(pos + 24),
1779
1779
  qualifier: deserializeOptionTSTypeName(pos + 32),
1780
1780
  typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
1781
1781
  isTypeOf: deserializeBool(pos + 56),
1782
1782
  };
1783
1783
  }
1784
1784
 
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
1785
  function deserializeTSFunctionType(pos) {
1806
1786
  return {
1807
1787
  type: 'TSFunctionType',
@@ -3361,8 +3341,7 @@ function deserializeJSXElementName(pos) {
3361
3341
  return deserializeBoxJSXIdentifier(pos + 8);
3362
3342
  case 1:
3363
3343
  const ident = deserializeBoxIdentifierReference(pos + 8);
3364
- ident.type = 'JSXIdentifier';
3365
- return ident;
3344
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3366
3345
  case 2:
3367
3346
  return deserializeBoxJSXNamespacedName(pos + 8);
3368
3347
  case 3:
@@ -3379,8 +3358,7 @@ function deserializeJSXMemberExpressionObject(pos) {
3379
3358
  switch (uint8[pos]) {
3380
3359
  case 0:
3381
3360
  const ident = deserializeBoxIdentifierReference(pos + 8);
3382
- ident.type = 'JSXIdentifier';
3383
- return ident;
3361
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3384
3362
  case 1:
3385
3363
  return deserializeBoxJSXMemberExpression(pos + 8);
3386
3364
  case 2:
@@ -3862,17 +3840,6 @@ function deserializeTSTypeQueryExprName(pos) {
3862
3840
  }
3863
3841
  }
3864
3842
 
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
3843
  function deserializeTSMappedTypeModifierOperator(pos) {
3877
3844
  switch (uint8[pos]) {
3878
3845
  case 0:
@@ -4337,7 +4304,7 @@ function deserializeVecDirective(pos) {
4337
4304
  pos = uint32[pos32];
4338
4305
  for (let i = 0; i < len; i++) {
4339
4306
  arr.push(deserializeDirective(pos));
4340
- pos += 64;
4307
+ pos += 72;
4341
4308
  }
4342
4309
  return arr;
4343
4310
  }
@@ -5108,7 +5075,7 @@ function deserializeVecImportAttribute(pos) {
5108
5075
  pos = uint32[pos32];
5109
5076
  for (let i = 0; i < len; i++) {
5110
5077
  arr.push(deserializeImportAttribute(pos));
5111
- pos += 96;
5078
+ pos += 112;
5112
5079
  }
5113
5080
  return arr;
5114
5081
  }
@@ -5125,13 +5092,13 @@ function deserializeVecExportSpecifier(pos) {
5125
5092
  pos = uint32[pos32];
5126
5093
  for (let i = 0; i < len; i++) {
5127
5094
  arr.push(deserializeExportSpecifier(pos));
5128
- pos += 112;
5095
+ pos += 128;
5129
5096
  }
5130
5097
  return arr;
5131
5098
  }
5132
5099
 
5133
5100
  function deserializeOptionStringLiteral(pos) {
5134
- if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
5101
+ if (uint8[pos + 40] === 2) return null;
5135
5102
  return deserializeStringLiteral(pos);
5136
5103
  }
5137
5104
 
@@ -5518,13 +5485,9 @@ function deserializeBoxTSTypeParameter(pos) {
5518
5485
  return deserializeTSTypeParameter(uint32[pos >> 2]);
5519
5486
  }
5520
5487
 
5521
- function deserializeBoxTSImportAttributes(pos) {
5522
- return deserializeTSImportAttributes(uint32[pos >> 2]);
5523
- }
5524
-
5525
- function deserializeOptionBoxTSImportAttributes(pos) {
5488
+ function deserializeOptionBoxObjectExpression(pos) {
5526
5489
  if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
5527
- return deserializeBoxTSImportAttributes(pos);
5490
+ return deserializeBoxObjectExpression(pos);
5528
5491
  }
5529
5492
 
5530
5493
  function deserializeOptionTSTypeName(pos) {
@@ -5532,18 +5495,6 @@ function deserializeOptionTSTypeName(pos) {
5532
5495
  return deserializeTSTypeName(pos);
5533
5496
  }
5534
5497
 
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
5498
  function deserializeBoxTSExternalModuleReference(pos) {
5548
5499
  return deserializeTSExternalModuleReference(uint32[pos >> 2]);
5549
5500
  }
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
 
@@ -452,7 +458,7 @@ function deserializeDirective(pos) {
452
458
  start: deserializeU32(pos),
453
459
  end: deserializeU32(pos + 4),
454
460
  expression: deserializeStringLiteral(pos + 8),
455
- directive: deserializeStr(pos + 48),
461
+ directive: deserializeStr(pos + 56),
456
462
  };
457
463
  }
458
464
 
@@ -956,7 +962,7 @@ function deserializeImportExpression(pos) {
956
962
  function deserializeImportDeclaration(pos) {
957
963
  let specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8);
958
964
  if (specifiers === null) specifiers = [];
959
- const withClause = deserializeOptionBoxWithClause(pos + 88);
965
+ const withClause = deserializeOptionBoxWithClause(pos + 96);
960
966
  return {
961
967
  type: 'ImportDeclaration',
962
968
  start: deserializeU32(pos),
@@ -964,7 +970,7 @@ function deserializeImportDeclaration(pos) {
964
970
  specifiers,
965
971
  source: deserializeStringLiteral(pos + 40),
966
972
  attributes: withClause === null ? [] : withClause.withEntries,
967
- importKind: deserializeImportOrExportKind(pos + 96),
973
+ importKind: deserializeImportOrExportKind(pos + 104),
968
974
  };
969
975
  }
970
976
 
@@ -974,8 +980,8 @@ function deserializeImportSpecifier(pos) {
974
980
  start: deserializeU32(pos),
975
981
  end: deserializeU32(pos + 4),
976
982
  imported: deserializeModuleExportName(pos + 8),
977
- local: deserializeBindingIdentifier(pos + 56),
978
- importKind: deserializeImportOrExportKind(pos + 88),
983
+ local: deserializeBindingIdentifier(pos + 64),
984
+ importKind: deserializeImportOrExportKind(pos + 96),
979
985
  };
980
986
  }
981
987
 
@@ -1013,12 +1019,12 @@ function deserializeImportAttribute(pos) {
1013
1019
  start: deserializeU32(pos),
1014
1020
  end: deserializeU32(pos + 4),
1015
1021
  key: deserializeImportAttributeKey(pos + 8),
1016
- value: deserializeStringLiteral(pos + 56),
1022
+ value: deserializeStringLiteral(pos + 64),
1017
1023
  };
1018
1024
  }
1019
1025
 
1020
1026
  function deserializeExportNamedDeclaration(pos) {
1021
- const withClause = deserializeOptionBoxWithClause(pos + 104);
1027
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
1022
1028
  return {
1023
1029
  type: 'ExportNamedDeclaration',
1024
1030
  start: deserializeU32(pos),
@@ -1027,7 +1033,7 @@ function deserializeExportNamedDeclaration(pos) {
1027
1033
  specifiers: deserializeVecExportSpecifier(pos + 24),
1028
1034
  source: deserializeOptionStringLiteral(pos + 56),
1029
1035
  attributes: withClause === null ? [] : withClause.withEntries,
1030
- exportKind: deserializeImportOrExportKind(pos + 96),
1036
+ exportKind: deserializeImportOrExportKind(pos + 104),
1031
1037
  };
1032
1038
  }
1033
1039
 
@@ -1036,20 +1042,20 @@ function deserializeExportDefaultDeclaration(pos) {
1036
1042
  type: 'ExportDefaultDeclaration',
1037
1043
  start: deserializeU32(pos),
1038
1044
  end: deserializeU32(pos + 4),
1039
- declaration: deserializeExportDefaultDeclarationKind(pos + 56),
1045
+ declaration: deserializeExportDefaultDeclarationKind(pos + 64),
1040
1046
  };
1041
1047
  }
1042
1048
 
1043
1049
  function deserializeExportAllDeclaration(pos) {
1044
- const withClause = deserializeOptionBoxWithClause(pos + 96);
1050
+ const withClause = deserializeOptionBoxWithClause(pos + 112);
1045
1051
  return {
1046
1052
  type: 'ExportAllDeclaration',
1047
1053
  start: deserializeU32(pos),
1048
1054
  end: deserializeU32(pos + 4),
1049
1055
  exported: deserializeOptionModuleExportName(pos + 8),
1050
- source: deserializeStringLiteral(pos + 56),
1056
+ source: deserializeStringLiteral(pos + 64),
1051
1057
  attributes: withClause === null ? [] : withClause.withEntries,
1052
- exportKind: deserializeImportOrExportKind(pos + 104),
1058
+ exportKind: deserializeImportOrExportKind(pos + 120),
1053
1059
  };
1054
1060
  }
1055
1061
 
@@ -1059,8 +1065,8 @@ function deserializeExportSpecifier(pos) {
1059
1065
  start: deserializeU32(pos),
1060
1066
  end: deserializeU32(pos + 4),
1061
1067
  local: deserializeModuleExportName(pos + 8),
1062
- exported: deserializeModuleExportName(pos + 56),
1063
- exportKind: deserializeImportOrExportKind(pos + 104),
1068
+ exported: deserializeModuleExportName(pos + 64),
1069
+ exportKind: deserializeImportOrExportKind(pos + 120),
1064
1070
  };
1065
1071
  }
1066
1072
 
@@ -1779,9 +1785,9 @@ function deserializeTSModuleDeclaration(pos) {
1779
1785
  start: deserializeU32(pos),
1780
1786
  end: deserializeU32(pos + 4),
1781
1787
  id: deserializeTSModuleDeclarationName(pos + 8),
1782
- body: deserializeOptionTSModuleDeclarationBody(pos + 56),
1783
- kind: deserializeTSModuleDeclarationKind(pos + 72),
1784
- declare: deserializeBool(pos + 73),
1788
+ body: deserializeOptionTSModuleDeclarationBody(pos + 64),
1789
+ kind: deserializeTSModuleDeclarationKind(pos + 80),
1790
+ declare: deserializeBool(pos + 81),
1785
1791
  };
1786
1792
  }
1787
1793
 
@@ -1830,33 +1836,13 @@ function deserializeTSImportType(pos) {
1830
1836
  start: deserializeU32(pos),
1831
1837
  end: deserializeU32(pos + 4),
1832
1838
  argument: deserializeTSType(pos + 8),
1833
- options: deserializeOptionBoxTSImportAttributes(pos + 24),
1839
+ options: deserializeOptionBoxObjectExpression(pos + 24),
1834
1840
  qualifier: deserializeOptionTSTypeName(pos + 32),
1835
1841
  typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
1836
1842
  isTypeOf: deserializeBool(pos + 56),
1837
1843
  };
1838
1844
  }
1839
1845
 
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
1846
  function deserializeTSFunctionType(pos) {
1861
1847
  return {
1862
1848
  type: 'TSFunctionType',
@@ -3416,8 +3402,7 @@ function deserializeJSXElementName(pos) {
3416
3402
  return deserializeBoxJSXIdentifier(pos + 8);
3417
3403
  case 1:
3418
3404
  const ident = deserializeBoxIdentifierReference(pos + 8);
3419
- ident.type = 'JSXIdentifier';
3420
- return ident;
3405
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3421
3406
  case 2:
3422
3407
  return deserializeBoxJSXNamespacedName(pos + 8);
3423
3408
  case 3:
@@ -3434,8 +3419,7 @@ function deserializeJSXMemberExpressionObject(pos) {
3434
3419
  switch (uint8[pos]) {
3435
3420
  case 0:
3436
3421
  const ident = deserializeBoxIdentifierReference(pos + 8);
3437
- ident.type = 'JSXIdentifier';
3438
- return ident;
3422
+ return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
3439
3423
  case 1:
3440
3424
  return deserializeBoxJSXMemberExpression(pos + 8);
3441
3425
  case 2:
@@ -3917,17 +3901,6 @@ function deserializeTSTypeQueryExprName(pos) {
3917
3901
  }
3918
3902
  }
3919
3903
 
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
3904
  function deserializeTSMappedTypeModifierOperator(pos) {
3932
3905
  switch (uint8[pos]) {
3933
3906
  case 0:
@@ -4392,7 +4365,7 @@ function deserializeVecDirective(pos) {
4392
4365
  pos = uint32[pos32];
4393
4366
  for (let i = 0; i < len; i++) {
4394
4367
  arr.push(deserializeDirective(pos));
4395
- pos += 64;
4368
+ pos += 72;
4396
4369
  }
4397
4370
  return arr;
4398
4371
  }
@@ -5163,7 +5136,7 @@ function deserializeVecImportAttribute(pos) {
5163
5136
  pos = uint32[pos32];
5164
5137
  for (let i = 0; i < len; i++) {
5165
5138
  arr.push(deserializeImportAttribute(pos));
5166
- pos += 96;
5139
+ pos += 112;
5167
5140
  }
5168
5141
  return arr;
5169
5142
  }
@@ -5180,13 +5153,13 @@ function deserializeVecExportSpecifier(pos) {
5180
5153
  pos = uint32[pos32];
5181
5154
  for (let i = 0; i < len; i++) {
5182
5155
  arr.push(deserializeExportSpecifier(pos));
5183
- pos += 112;
5156
+ pos += 128;
5184
5157
  }
5185
5158
  return arr;
5186
5159
  }
5187
5160
 
5188
5161
  function deserializeOptionStringLiteral(pos) {
5189
- if (uint32[(pos + 8) >> 2] === 0 && uint32[(pos + 12) >> 2] === 0) return null;
5162
+ if (uint8[pos + 40] === 2) return null;
5190
5163
  return deserializeStringLiteral(pos);
5191
5164
  }
5192
5165
 
@@ -5573,13 +5546,9 @@ function deserializeBoxTSTypeParameter(pos) {
5573
5546
  return deserializeTSTypeParameter(uint32[pos >> 2]);
5574
5547
  }
5575
5548
 
5576
- function deserializeBoxTSImportAttributes(pos) {
5577
- return deserializeTSImportAttributes(uint32[pos >> 2]);
5578
- }
5579
-
5580
- function deserializeOptionBoxTSImportAttributes(pos) {
5549
+ function deserializeOptionBoxObjectExpression(pos) {
5581
5550
  if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
5582
- return deserializeBoxTSImportAttributes(pos);
5551
+ return deserializeBoxObjectExpression(pos);
5583
5552
  }
5584
5553
 
5585
5554
  function deserializeOptionTSTypeName(pos) {
@@ -5587,18 +5556,6 @@ function deserializeOptionTSTypeName(pos) {
5587
5556
  return deserializeTSTypeName(pos);
5588
5557
  }
5589
5558
 
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
5559
  function deserializeBoxTSExternalModuleReference(pos) {
5603
5560
  return deserializeTSExternalModuleReference(uint32[pos >> 2]);
5604
5561
  }
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.0",
4
4
  "main": "index.js",
5
5
  "browser": "wasm.mjs",
6
6
  "engines": {
@@ -38,12 +38,12 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@oxc-project/types": "^0.60.0"
41
+ "@oxc-project/types": "^0.61.0"
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
47
  "playwright": "^1.51.0",
48
48
  "vitest": "3.0.8"
49
49
  },
@@ -70,23 +70,24 @@
70
70
  "dtsHeaderFile": "header.js"
71
71
  },
72
72
  "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"
73
+ "@oxc-parser/binding-win32-x64-msvc": "0.61.0",
74
+ "@oxc-parser/binding-win32-arm64-msvc": "0.61.0",
75
+ "@oxc-parser/binding-linux-x64-gnu": "0.61.0",
76
+ "@oxc-parser/binding-linux-x64-musl": "0.61.0",
77
+ "@oxc-parser/binding-linux-arm64-gnu": "0.61.0",
78
+ "@oxc-parser/binding-linux-arm64-musl": "0.61.0",
79
+ "@oxc-parser/binding-linux-arm-gnueabihf": "0.61.0",
80
+ "@oxc-parser/binding-darwin-x64": "0.61.0",
81
+ "@oxc-parser/binding-darwin-arm64": "0.61.0",
82
+ "@oxc-parser/binding-wasm32-wasi": "0.61.0"
83
83
  },
84
84
  "scripts": {
85
85
  "build-dev": "napi build --no-dts-cache --platform --js bindings.js",
86
- "build": "pnpm run build-dev --release",
86
+ "build": "pnpm run build-dev --features allocator --release",
87
87
  "build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
88
88
  "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",
89
+ "test": "pnpm run test-node run && tsc",
90
+ "test-node": "vitest --dir ./test",
90
91
  "test-browser": "vitest -c vitest.config.browser.mts",
91
92
  "bench": "vitest bench --run ./bench.bench.mjs"
92
93
  }
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
+ }