oxc-parser 0.58.1 → 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 +4 -0
- package/deserialize-js.js +29 -78
- package/deserialize-ts.js +48 -89
- package/index.d.ts +1 -0
- package/index.js +1 -44
- package/package.json +27 -18
- package/wasm.mjs +11 -0
- package/wrap.cjs +42 -0
- package/wrap.mjs +45 -0
- package/browser.js +0 -1
package/README.md
CHANGED
package/deserialize-js.js
CHANGED
|
@@ -152,8 +152,8 @@ function deserializeTemplateElement(pos) {
|
|
|
152
152
|
type: 'TemplateElement',
|
|
153
153
|
start: deserializeU32(pos),
|
|
154
154
|
end: deserializeU32(pos + 4),
|
|
155
|
-
value: deserializeTemplateElementValue(pos +
|
|
156
|
-
tail: deserializeBool(pos +
|
|
155
|
+
value: deserializeTemplateElementValue(pos + 8),
|
|
156
|
+
tail: deserializeBool(pos + 40),
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -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 +
|
|
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 +
|
|
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 +
|
|
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 +
|
|
965
|
+
value: deserializeStringLiteral(pos + 64),
|
|
966
966
|
};
|
|
967
967
|
}
|
|
968
968
|
|
|
969
969
|
function deserializeExportNamedDeclaration(pos) {
|
|
970
|
-
const withClause = deserializeOptionBoxWithClause(pos +
|
|
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 +
|
|
987
|
+
declaration: deserializeExportDefaultDeclarationKind(pos + 64),
|
|
988
988
|
};
|
|
989
989
|
}
|
|
990
990
|
|
|
991
991
|
function deserializeExportAllDeclaration(pos) {
|
|
992
|
-
const withClause = deserializeOptionBoxWithClause(pos +
|
|
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 +
|
|
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 +
|
|
1009
|
+
exported: deserializeModuleExportName(pos + 64),
|
|
1010
1010
|
};
|
|
1011
1011
|
}
|
|
1012
1012
|
|
|
@@ -1533,7 +1533,7 @@ function deserializeTSTypeReference(pos) {
|
|
|
1533
1533
|
start: deserializeU32(pos),
|
|
1534
1534
|
end: deserializeU32(pos + 4),
|
|
1535
1535
|
typeName: deserializeTSTypeName(pos + 8),
|
|
1536
|
-
|
|
1536
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1537
1537
|
};
|
|
1538
1538
|
}
|
|
1539
1539
|
|
|
@@ -1597,7 +1597,7 @@ function deserializeTSClassImplements(pos) {
|
|
|
1597
1597
|
start: deserializeU32(pos),
|
|
1598
1598
|
end: deserializeU32(pos + 4),
|
|
1599
1599
|
expression: deserializeTSTypeName(pos + 8),
|
|
1600
|
-
|
|
1600
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1601
1601
|
};
|
|
1602
1602
|
}
|
|
1603
1603
|
|
|
@@ -1703,7 +1703,7 @@ function deserializeTSInterfaceHeritage(pos) {
|
|
|
1703
1703
|
start: deserializeU32(pos),
|
|
1704
1704
|
end: deserializeU32(pos + 4),
|
|
1705
1705
|
expression: deserializeExpression(pos + 8),
|
|
1706
|
-
|
|
1706
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1707
1707
|
};
|
|
1708
1708
|
}
|
|
1709
1709
|
|
|
@@ -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 +
|
|
1728
|
-
kind: deserializeTSModuleDeclarationKind(pos +
|
|
1729
|
-
declare: deserializeBool(pos +
|
|
1727
|
+
body: deserializeOptionTSModuleDeclarationBody(pos + 64),
|
|
1728
|
+
kind: deserializeTSModuleDeclarationKind(pos + 80),
|
|
1729
|
+
declare: deserializeBool(pos + 81),
|
|
1730
1730
|
};
|
|
1731
1731
|
}
|
|
1732
1732
|
|
|
@@ -1765,7 +1765,7 @@ function deserializeTSTypeQuery(pos) {
|
|
|
1765
1765
|
start: deserializeU32(pos),
|
|
1766
1766
|
end: deserializeU32(pos + 4),
|
|
1767
1767
|
exprName: deserializeTSTypeQueryExprName(pos + 8),
|
|
1768
|
-
|
|
1768
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1769
1769
|
};
|
|
1770
1770
|
}
|
|
1771
1771
|
|
|
@@ -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:
|
|
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',
|
|
@@ -2919,9 +2899,9 @@ function deserializeVariableDeclarationKind(pos) {
|
|
|
2919
2899
|
case 0:
|
|
2920
2900
|
return 'var';
|
|
2921
2901
|
case 1:
|
|
2922
|
-
return 'const';
|
|
2923
|
-
case 2:
|
|
2924
2902
|
return 'let';
|
|
2903
|
+
case 2:
|
|
2904
|
+
return 'const';
|
|
2925
2905
|
case 3:
|
|
2926
2906
|
return 'using';
|
|
2927
2907
|
case 4:
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 +=
|
|
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 +=
|
|
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 +=
|
|
5095
|
+
pos += 128;
|
|
5129
5096
|
}
|
|
5130
5097
|
return arr;
|
|
5131
5098
|
}
|
|
5132
5099
|
|
|
5133
5100
|
function deserializeOptionStringLiteral(pos) {
|
|
5134
|
-
if (
|
|
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
|
|
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
|
|
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
|
|
|
@@ -144,7 +150,7 @@ function deserializeTaggedTemplateExpression(pos) {
|
|
|
144
150
|
end: deserializeU32(pos + 4),
|
|
145
151
|
tag: deserializeExpression(pos + 8),
|
|
146
152
|
quasi: deserializeTemplateLiteral(pos + 24),
|
|
147
|
-
|
|
153
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 96),
|
|
148
154
|
};
|
|
149
155
|
}
|
|
150
156
|
|
|
@@ -153,8 +159,8 @@ function deserializeTemplateElement(pos) {
|
|
|
153
159
|
type: 'TemplateElement',
|
|
154
160
|
start: deserializeU32(pos),
|
|
155
161
|
end: deserializeU32(pos + 4),
|
|
156
|
-
value: deserializeTemplateElementValue(pos +
|
|
157
|
-
tail: deserializeBool(pos +
|
|
162
|
+
value: deserializeTemplateElementValue(pos + 8),
|
|
163
|
+
tail: deserializeBool(pos + 40),
|
|
158
164
|
};
|
|
159
165
|
}
|
|
160
166
|
|
|
@@ -207,9 +213,9 @@ function deserializeCallExpression(pos) {
|
|
|
207
213
|
start: deserializeU32(pos),
|
|
208
214
|
end: deserializeU32(pos + 4),
|
|
209
215
|
callee: deserializeExpression(pos + 8),
|
|
210
|
-
typeParameters: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
211
216
|
arguments: deserializeVecArgument(pos + 32),
|
|
212
217
|
optional: deserializeBool(pos + 64),
|
|
218
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
213
219
|
};
|
|
214
220
|
}
|
|
215
221
|
|
|
@@ -220,7 +226,7 @@ function deserializeNewExpression(pos) {
|
|
|
220
226
|
end: deserializeU32(pos + 4),
|
|
221
227
|
callee: deserializeExpression(pos + 8),
|
|
222
228
|
arguments: deserializeVecArgument(pos + 24),
|
|
223
|
-
|
|
229
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 56),
|
|
224
230
|
};
|
|
225
231
|
}
|
|
226
232
|
|
|
@@ -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 +
|
|
461
|
+
directive: deserializeStr(pos + 56),
|
|
456
462
|
};
|
|
457
463
|
}
|
|
458
464
|
|
|
@@ -510,6 +516,7 @@ function deserializeExpressionStatement(pos) {
|
|
|
510
516
|
start: deserializeU32(pos),
|
|
511
517
|
end: deserializeU32(pos + 4),
|
|
512
518
|
expression: deserializeExpression(pos + 8),
|
|
519
|
+
directive: null,
|
|
513
520
|
};
|
|
514
521
|
}
|
|
515
522
|
|
|
@@ -844,6 +851,7 @@ function deserializeYieldExpression(pos) {
|
|
|
844
851
|
}
|
|
845
852
|
|
|
846
853
|
function deserializeClass(pos) {
|
|
854
|
+
const classImplements = deserializeOptionVecTSClassImplements(pos + 112);
|
|
847
855
|
return {
|
|
848
856
|
type: deserializeClassType(pos + 8),
|
|
849
857
|
start: deserializeU32(pos),
|
|
@@ -853,8 +861,8 @@ function deserializeClass(pos) {
|
|
|
853
861
|
body: deserializeBoxClassBody(pos + 144),
|
|
854
862
|
decorators: deserializeVecDecorator(pos + 16),
|
|
855
863
|
typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 80),
|
|
856
|
-
|
|
857
|
-
implements:
|
|
864
|
+
superTypeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 104),
|
|
865
|
+
implements: classImplements === null ? [] : classImplements,
|
|
858
866
|
abstract: deserializeBool(pos + 152),
|
|
859
867
|
declare: deserializeBool(pos + 153),
|
|
860
868
|
};
|
|
@@ -954,7 +962,7 @@ function deserializeImportExpression(pos) {
|
|
|
954
962
|
function deserializeImportDeclaration(pos) {
|
|
955
963
|
let specifiers = deserializeOptionVecImportDeclarationSpecifier(pos + 8);
|
|
956
964
|
if (specifiers === null) specifiers = [];
|
|
957
|
-
const withClause = deserializeOptionBoxWithClause(pos +
|
|
965
|
+
const withClause = deserializeOptionBoxWithClause(pos + 96);
|
|
958
966
|
return {
|
|
959
967
|
type: 'ImportDeclaration',
|
|
960
968
|
start: deserializeU32(pos),
|
|
@@ -962,7 +970,7 @@ function deserializeImportDeclaration(pos) {
|
|
|
962
970
|
specifiers,
|
|
963
971
|
source: deserializeStringLiteral(pos + 40),
|
|
964
972
|
attributes: withClause === null ? [] : withClause.withEntries,
|
|
965
|
-
importKind: deserializeImportOrExportKind(pos +
|
|
973
|
+
importKind: deserializeImportOrExportKind(pos + 104),
|
|
966
974
|
};
|
|
967
975
|
}
|
|
968
976
|
|
|
@@ -972,8 +980,8 @@ function deserializeImportSpecifier(pos) {
|
|
|
972
980
|
start: deserializeU32(pos),
|
|
973
981
|
end: deserializeU32(pos + 4),
|
|
974
982
|
imported: deserializeModuleExportName(pos + 8),
|
|
975
|
-
local: deserializeBindingIdentifier(pos +
|
|
976
|
-
importKind: deserializeImportOrExportKind(pos +
|
|
983
|
+
local: deserializeBindingIdentifier(pos + 64),
|
|
984
|
+
importKind: deserializeImportOrExportKind(pos + 96),
|
|
977
985
|
};
|
|
978
986
|
}
|
|
979
987
|
|
|
@@ -1011,12 +1019,12 @@ function deserializeImportAttribute(pos) {
|
|
|
1011
1019
|
start: deserializeU32(pos),
|
|
1012
1020
|
end: deserializeU32(pos + 4),
|
|
1013
1021
|
key: deserializeImportAttributeKey(pos + 8),
|
|
1014
|
-
value: deserializeStringLiteral(pos +
|
|
1022
|
+
value: deserializeStringLiteral(pos + 64),
|
|
1015
1023
|
};
|
|
1016
1024
|
}
|
|
1017
1025
|
|
|
1018
1026
|
function deserializeExportNamedDeclaration(pos) {
|
|
1019
|
-
const withClause = deserializeOptionBoxWithClause(pos +
|
|
1027
|
+
const withClause = deserializeOptionBoxWithClause(pos + 112);
|
|
1020
1028
|
return {
|
|
1021
1029
|
type: 'ExportNamedDeclaration',
|
|
1022
1030
|
start: deserializeU32(pos),
|
|
@@ -1024,8 +1032,8 @@ function deserializeExportNamedDeclaration(pos) {
|
|
|
1024
1032
|
declaration: deserializeOptionDeclaration(pos + 8),
|
|
1025
1033
|
specifiers: deserializeVecExportSpecifier(pos + 24),
|
|
1026
1034
|
source: deserializeOptionStringLiteral(pos + 56),
|
|
1027
|
-
exportKind: deserializeImportOrExportKind(pos + 96),
|
|
1028
1035
|
attributes: withClause === null ? [] : withClause.withEntries,
|
|
1036
|
+
exportKind: deserializeImportOrExportKind(pos + 104),
|
|
1029
1037
|
};
|
|
1030
1038
|
}
|
|
1031
1039
|
|
|
@@ -1034,20 +1042,20 @@ function deserializeExportDefaultDeclaration(pos) {
|
|
|
1034
1042
|
type: 'ExportDefaultDeclaration',
|
|
1035
1043
|
start: deserializeU32(pos),
|
|
1036
1044
|
end: deserializeU32(pos + 4),
|
|
1037
|
-
declaration: deserializeExportDefaultDeclarationKind(pos +
|
|
1045
|
+
declaration: deserializeExportDefaultDeclarationKind(pos + 64),
|
|
1038
1046
|
};
|
|
1039
1047
|
}
|
|
1040
1048
|
|
|
1041
1049
|
function deserializeExportAllDeclaration(pos) {
|
|
1042
|
-
const withClause = deserializeOptionBoxWithClause(pos +
|
|
1050
|
+
const withClause = deserializeOptionBoxWithClause(pos + 112);
|
|
1043
1051
|
return {
|
|
1044
1052
|
type: 'ExportAllDeclaration',
|
|
1045
1053
|
start: deserializeU32(pos),
|
|
1046
1054
|
end: deserializeU32(pos + 4),
|
|
1047
1055
|
exported: deserializeOptionModuleExportName(pos + 8),
|
|
1048
|
-
source: deserializeStringLiteral(pos +
|
|
1056
|
+
source: deserializeStringLiteral(pos + 64),
|
|
1049
1057
|
attributes: withClause === null ? [] : withClause.withEntries,
|
|
1050
|
-
exportKind: deserializeImportOrExportKind(pos +
|
|
1058
|
+
exportKind: deserializeImportOrExportKind(pos + 120),
|
|
1051
1059
|
};
|
|
1052
1060
|
}
|
|
1053
1061
|
|
|
@@ -1057,8 +1065,8 @@ function deserializeExportSpecifier(pos) {
|
|
|
1057
1065
|
start: deserializeU32(pos),
|
|
1058
1066
|
end: deserializeU32(pos + 4),
|
|
1059
1067
|
local: deserializeModuleExportName(pos + 8),
|
|
1060
|
-
exported: deserializeModuleExportName(pos +
|
|
1061
|
-
exportKind: deserializeImportOrExportKind(pos +
|
|
1068
|
+
exported: deserializeModuleExportName(pos + 64),
|
|
1069
|
+
exportKind: deserializeImportOrExportKind(pos + 120),
|
|
1062
1070
|
};
|
|
1063
1071
|
}
|
|
1064
1072
|
|
|
@@ -1187,7 +1195,7 @@ function deserializeJSXOpeningElement(pos) {
|
|
|
1187
1195
|
attributes: deserializeVecJSXAttributeItem(pos + 32),
|
|
1188
1196
|
name: deserializeJSXElementName(pos + 16),
|
|
1189
1197
|
selfClosing: deserializeBool(pos + 8),
|
|
1190
|
-
|
|
1198
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 64),
|
|
1191
1199
|
};
|
|
1192
1200
|
}
|
|
1193
1201
|
|
|
@@ -1586,7 +1594,7 @@ function deserializeTSTypeReference(pos) {
|
|
|
1586
1594
|
start: deserializeU32(pos),
|
|
1587
1595
|
end: deserializeU32(pos + 4),
|
|
1588
1596
|
typeName: deserializeTSTypeName(pos + 8),
|
|
1589
|
-
|
|
1597
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1590
1598
|
};
|
|
1591
1599
|
}
|
|
1592
1600
|
|
|
@@ -1650,7 +1658,7 @@ function deserializeTSClassImplements(pos) {
|
|
|
1650
1658
|
start: deserializeU32(pos),
|
|
1651
1659
|
end: deserializeU32(pos + 4),
|
|
1652
1660
|
expression: deserializeTSTypeName(pos + 8),
|
|
1653
|
-
|
|
1661
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1654
1662
|
};
|
|
1655
1663
|
}
|
|
1656
1664
|
|
|
@@ -1756,7 +1764,7 @@ function deserializeTSInterfaceHeritage(pos) {
|
|
|
1756
1764
|
start: deserializeU32(pos),
|
|
1757
1765
|
end: deserializeU32(pos + 4),
|
|
1758
1766
|
expression: deserializeExpression(pos + 8),
|
|
1759
|
-
|
|
1767
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1760
1768
|
};
|
|
1761
1769
|
}
|
|
1762
1770
|
|
|
@@ -1777,9 +1785,9 @@ function deserializeTSModuleDeclaration(pos) {
|
|
|
1777
1785
|
start: deserializeU32(pos),
|
|
1778
1786
|
end: deserializeU32(pos + 4),
|
|
1779
1787
|
id: deserializeTSModuleDeclarationName(pos + 8),
|
|
1780
|
-
body: deserializeOptionTSModuleDeclarationBody(pos +
|
|
1781
|
-
kind: deserializeTSModuleDeclarationKind(pos +
|
|
1782
|
-
declare: deserializeBool(pos +
|
|
1788
|
+
body: deserializeOptionTSModuleDeclarationBody(pos + 64),
|
|
1789
|
+
kind: deserializeTSModuleDeclarationKind(pos + 80),
|
|
1790
|
+
declare: deserializeBool(pos + 81),
|
|
1783
1791
|
};
|
|
1784
1792
|
}
|
|
1785
1793
|
|
|
@@ -1818,7 +1826,7 @@ function deserializeTSTypeQuery(pos) {
|
|
|
1818
1826
|
start: deserializeU32(pos),
|
|
1819
1827
|
end: deserializeU32(pos + 4),
|
|
1820
1828
|
exprName: deserializeTSTypeQueryExprName(pos + 8),
|
|
1821
|
-
|
|
1829
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1822
1830
|
};
|
|
1823
1831
|
}
|
|
1824
1832
|
|
|
@@ -1828,33 +1836,13 @@ function deserializeTSImportType(pos) {
|
|
|
1828
1836
|
start: deserializeU32(pos),
|
|
1829
1837
|
end: deserializeU32(pos + 4),
|
|
1830
1838
|
argument: deserializeTSType(pos + 8),
|
|
1831
|
-
options:
|
|
1839
|
+
options: deserializeOptionBoxObjectExpression(pos + 24),
|
|
1832
1840
|
qualifier: deserializeOptionTSTypeName(pos + 32),
|
|
1833
1841
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
|
|
1834
1842
|
isTypeOf: deserializeBool(pos + 56),
|
|
1835
1843
|
};
|
|
1836
1844
|
}
|
|
1837
1845
|
|
|
1838
|
-
function deserializeTSImportAttributes(pos) {
|
|
1839
|
-
return {
|
|
1840
|
-
type: 'TSImportAttributes',
|
|
1841
|
-
start: deserializeU32(pos),
|
|
1842
|
-
end: deserializeU32(pos + 4),
|
|
1843
|
-
attributesKeyword: deserializeIdentifierName(pos + 8),
|
|
1844
|
-
elements: deserializeVecTSImportAttribute(pos + 32),
|
|
1845
|
-
};
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
function deserializeTSImportAttribute(pos) {
|
|
1849
|
-
return {
|
|
1850
|
-
type: 'TSImportAttribute',
|
|
1851
|
-
start: deserializeU32(pos),
|
|
1852
|
-
end: deserializeU32(pos + 4),
|
|
1853
|
-
name: deserializeTSImportAttributeName(pos + 8),
|
|
1854
|
-
value: deserializeExpression(pos + 56),
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
1846
|
function deserializeTSFunctionType(pos) {
|
|
1859
1847
|
return {
|
|
1860
1848
|
type: 'TSFunctionType',
|
|
@@ -2972,9 +2960,9 @@ function deserializeVariableDeclarationKind(pos) {
|
|
|
2972
2960
|
case 0:
|
|
2973
2961
|
return 'var';
|
|
2974
2962
|
case 1:
|
|
2975
|
-
return 'const';
|
|
2976
|
-
case 2:
|
|
2977
2963
|
return 'let';
|
|
2964
|
+
case 2:
|
|
2965
|
+
return 'const';
|
|
2978
2966
|
case 3:
|
|
2979
2967
|
return 'using';
|
|
2980
2968
|
case 4:
|
|
@@ -3414,8 +3402,7 @@ function deserializeJSXElementName(pos) {
|
|
|
3414
3402
|
return deserializeBoxJSXIdentifier(pos + 8);
|
|
3415
3403
|
case 1:
|
|
3416
3404
|
const ident = deserializeBoxIdentifierReference(pos + 8);
|
|
3417
|
-
|
|
3418
|
-
return ident;
|
|
3405
|
+
return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
|
|
3419
3406
|
case 2:
|
|
3420
3407
|
return deserializeBoxJSXNamespacedName(pos + 8);
|
|
3421
3408
|
case 3:
|
|
@@ -3432,8 +3419,7 @@ function deserializeJSXMemberExpressionObject(pos) {
|
|
|
3432
3419
|
switch (uint8[pos]) {
|
|
3433
3420
|
case 0:
|
|
3434
3421
|
const ident = deserializeBoxIdentifierReference(pos + 8);
|
|
3435
|
-
|
|
3436
|
-
return ident;
|
|
3422
|
+
return { type: 'JSXIdentifier', start: ident.start, end: ident.end, name: ident.name };
|
|
3437
3423
|
case 1:
|
|
3438
3424
|
return deserializeBoxJSXMemberExpression(pos + 8);
|
|
3439
3425
|
case 2:
|
|
@@ -3915,17 +3901,6 @@ function deserializeTSTypeQueryExprName(pos) {
|
|
|
3915
3901
|
}
|
|
3916
3902
|
}
|
|
3917
3903
|
|
|
3918
|
-
function deserializeTSImportAttributeName(pos) {
|
|
3919
|
-
switch (uint8[pos]) {
|
|
3920
|
-
case 0:
|
|
3921
|
-
return deserializeIdentifierName(pos + 8);
|
|
3922
|
-
case 1:
|
|
3923
|
-
return deserializeStringLiteral(pos + 8);
|
|
3924
|
-
default:
|
|
3925
|
-
throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`);
|
|
3926
|
-
}
|
|
3927
|
-
}
|
|
3928
|
-
|
|
3929
3904
|
function deserializeTSMappedTypeModifierOperator(pos) {
|
|
3930
3905
|
switch (uint8[pos]) {
|
|
3931
3906
|
case 0:
|
|
@@ -4390,7 +4365,7 @@ function deserializeVecDirective(pos) {
|
|
|
4390
4365
|
pos = uint32[pos32];
|
|
4391
4366
|
for (let i = 0; i < len; i++) {
|
|
4392
4367
|
arr.push(deserializeDirective(pos));
|
|
4393
|
-
pos +=
|
|
4368
|
+
pos += 72;
|
|
4394
4369
|
}
|
|
4395
4370
|
return arr;
|
|
4396
4371
|
}
|
|
@@ -5161,7 +5136,7 @@ function deserializeVecImportAttribute(pos) {
|
|
|
5161
5136
|
pos = uint32[pos32];
|
|
5162
5137
|
for (let i = 0; i < len; i++) {
|
|
5163
5138
|
arr.push(deserializeImportAttribute(pos));
|
|
5164
|
-
pos +=
|
|
5139
|
+
pos += 112;
|
|
5165
5140
|
}
|
|
5166
5141
|
return arr;
|
|
5167
5142
|
}
|
|
@@ -5178,13 +5153,13 @@ function deserializeVecExportSpecifier(pos) {
|
|
|
5178
5153
|
pos = uint32[pos32];
|
|
5179
5154
|
for (let i = 0; i < len; i++) {
|
|
5180
5155
|
arr.push(deserializeExportSpecifier(pos));
|
|
5181
|
-
pos +=
|
|
5156
|
+
pos += 128;
|
|
5182
5157
|
}
|
|
5183
5158
|
return arr;
|
|
5184
5159
|
}
|
|
5185
5160
|
|
|
5186
5161
|
function deserializeOptionStringLiteral(pos) {
|
|
5187
|
-
if (
|
|
5162
|
+
if (uint8[pos + 40] === 2) return null;
|
|
5188
5163
|
return deserializeStringLiteral(pos);
|
|
5189
5164
|
}
|
|
5190
5165
|
|
|
@@ -5571,13 +5546,9 @@ function deserializeBoxTSTypeParameter(pos) {
|
|
|
5571
5546
|
return deserializeTSTypeParameter(uint32[pos >> 2]);
|
|
5572
5547
|
}
|
|
5573
5548
|
|
|
5574
|
-
function
|
|
5575
|
-
return deserializeTSImportAttributes(uint32[pos >> 2]);
|
|
5576
|
-
}
|
|
5577
|
-
|
|
5578
|
-
function deserializeOptionBoxTSImportAttributes(pos) {
|
|
5549
|
+
function deserializeOptionBoxObjectExpression(pos) {
|
|
5579
5550
|
if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
|
|
5580
|
-
return
|
|
5551
|
+
return deserializeBoxObjectExpression(pos);
|
|
5581
5552
|
}
|
|
5582
5553
|
|
|
5583
5554
|
function deserializeOptionTSTypeName(pos) {
|
|
@@ -5585,18 +5556,6 @@ function deserializeOptionTSTypeName(pos) {
|
|
|
5585
5556
|
return deserializeTSTypeName(pos);
|
|
5586
5557
|
}
|
|
5587
5558
|
|
|
5588
|
-
function deserializeVecTSImportAttribute(pos) {
|
|
5589
|
-
const arr = [],
|
|
5590
|
-
pos32 = pos >> 2,
|
|
5591
|
-
len = uint32[pos32 + 6];
|
|
5592
|
-
pos = uint32[pos32];
|
|
5593
|
-
for (let i = 0; i < len; i++) {
|
|
5594
|
-
arr.push(deserializeTSImportAttribute(pos));
|
|
5595
|
-
pos += 72;
|
|
5596
|
-
}
|
|
5597
|
-
return arr;
|
|
5598
|
-
}
|
|
5599
|
-
|
|
5600
5559
|
function deserializeBoxTSExternalModuleReference(pos) {
|
|
5601
5560
|
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
|
|
5602
5561
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const bindings = require('./bindings.js');
|
|
2
2
|
const deserializeJS = require('./deserialize-js.js');
|
|
3
3
|
const deserializeTS = require('./deserialize-ts.js');
|
|
4
|
+
const { wrap } = require('./wrap.cjs');
|
|
4
5
|
|
|
5
6
|
module.exports.ParseResult = bindings.ParseResult;
|
|
6
7
|
module.exports.ExportExportNameKind = bindings.ExportExportNameKind;
|
|
@@ -10,49 +11,6 @@ module.exports.ImportNameKind = bindings.ImportNameKind;
|
|
|
10
11
|
module.exports.parseWithoutReturn = bindings.parseWithoutReturn;
|
|
11
12
|
module.exports.Severity = bindings.Severity;
|
|
12
13
|
|
|
13
|
-
function wrap(result) {
|
|
14
|
-
let program, module, comments, errors;
|
|
15
|
-
return {
|
|
16
|
-
get program() {
|
|
17
|
-
if (!program) {
|
|
18
|
-
// Note: This code is repeated in `wasm/parser/update-bindings.mjs` and `crates/oxc-wasm/update-bindings.mjs`.
|
|
19
|
-
// Any changes should be applied in those 2 scripts too.
|
|
20
|
-
program = JSON.parse(result.program, function(key, value) {
|
|
21
|
-
// Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
|
|
22
|
-
// This is not possible to do on Rust side, as neither can be represented correctly in JSON.
|
|
23
|
-
if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
|
|
24
|
-
if (Object.hasOwn(this, 'bigint')) {
|
|
25
|
-
return BigInt(this.bigint);
|
|
26
|
-
}
|
|
27
|
-
if (Object.hasOwn(this, 'regex')) {
|
|
28
|
-
const { regex } = this;
|
|
29
|
-
try {
|
|
30
|
-
return RegExp(regex.pattern, regex.flags);
|
|
31
|
-
} catch (_err) {
|
|
32
|
-
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return program;
|
|
40
|
-
},
|
|
41
|
-
get module() {
|
|
42
|
-
if (!module) module = result.module;
|
|
43
|
-
return module;
|
|
44
|
-
},
|
|
45
|
-
get comments() {
|
|
46
|
-
if (!comments) comments = result.comments;
|
|
47
|
-
return comments;
|
|
48
|
-
},
|
|
49
|
-
get errors() {
|
|
50
|
-
if (!errors) errors = result.errors;
|
|
51
|
-
return errors;
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
14
|
module.exports.parseAsync = async function parseAsync(...args) {
|
|
57
15
|
return wrap(await bindings.parseAsync(...args));
|
|
58
16
|
};
|
|
@@ -61,7 +19,6 @@ module.exports.parseSync = function parseSync(filename, sourceText, options) {
|
|
|
61
19
|
if (options?.experimentalRawTransfer) {
|
|
62
20
|
return parseSyncRaw(filename, sourceText, options);
|
|
63
21
|
}
|
|
64
|
-
|
|
65
22
|
return wrap(bindings.parseSync(filename, sourceText, options));
|
|
66
23
|
};
|
|
67
24
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.0",
|
|
4
4
|
"main": "index.js",
|
|
5
|
-
"browser": "
|
|
5
|
+
"browser": "wasm.mjs",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=14.0.0"
|
|
8
8
|
},
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"index.d.ts",
|
|
28
28
|
"index.js",
|
|
29
|
-
"
|
|
29
|
+
"wrap.cjs",
|
|
30
|
+
"wrap.mjs",
|
|
31
|
+
"wasm.mjs",
|
|
30
32
|
"bindings.js",
|
|
31
33
|
"deserialize-js.js",
|
|
32
34
|
"deserialize-ts.js"
|
|
@@ -36,11 +38,14 @@
|
|
|
36
38
|
"access": "public"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@oxc-project/types": "^0.
|
|
41
|
+
"@oxc-project/types": "^0.61.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@codspeed/vitest-plugin": "^4.0.0",
|
|
43
|
-
"
|
|
45
|
+
"@napi-rs/wasm-runtime": "^0.2.7",
|
|
46
|
+
"@vitest/browser": "3.0.8",
|
|
47
|
+
"playwright": "^1.51.0",
|
|
48
|
+
"vitest": "3.0.8"
|
|
44
49
|
},
|
|
45
50
|
"napi": {
|
|
46
51
|
"binaryName": "parser",
|
|
@@ -59,27 +64,31 @@
|
|
|
59
64
|
],
|
|
60
65
|
"wasm": {
|
|
61
66
|
"browser": {
|
|
62
|
-
"fs":
|
|
67
|
+
"fs": false
|
|
63
68
|
}
|
|
64
69
|
},
|
|
65
70
|
"dtsHeaderFile": "header.js"
|
|
66
71
|
},
|
|
67
72
|
"optionalDependencies": {
|
|
68
|
-
"@oxc-parser/binding-win32-x64-msvc": "0.
|
|
69
|
-
"@oxc-parser/binding-win32-arm64-msvc": "0.
|
|
70
|
-
"@oxc-parser/binding-linux-x64-gnu": "0.
|
|
71
|
-
"@oxc-parser/binding-linux-x64-musl": "0.
|
|
72
|
-
"@oxc-parser/binding-linux-arm64-gnu": "0.
|
|
73
|
-
"@oxc-parser/binding-linux-arm64-musl": "0.
|
|
74
|
-
"@oxc-parser/binding-linux-arm-gnueabihf": "0.
|
|
75
|
-
"@oxc-parser/binding-darwin-x64": "0.
|
|
76
|
-
"@oxc-parser/binding-darwin-arm64": "0.
|
|
77
|
-
"@oxc-parser/binding-wasm32-wasi": "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"
|
|
78
83
|
},
|
|
79
84
|
"scripts": {
|
|
80
85
|
"build-dev": "napi build --no-dts-cache --platform --js bindings.js",
|
|
81
|
-
"build": "pnpm run build-dev --release",
|
|
82
|
-
"
|
|
86
|
+
"build": "pnpm run build-dev --features allocator --release",
|
|
87
|
+
"build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads",
|
|
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": "pnpm run test-node run && tsc",
|
|
90
|
+
"test-node": "vitest --dir ./test",
|
|
91
|
+
"test-browser": "vitest -c vitest.config.browser.mts",
|
|
83
92
|
"bench": "vitest bench --run ./bench.bench.mjs"
|
|
84
93
|
}
|
|
85
94
|
}
|
package/wasm.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from '@oxc-parser/binding-wasm32-wasi';
|
|
2
|
+
import * as bindings from '@oxc-parser/binding-wasm32-wasi';
|
|
3
|
+
import { wrap } from './wrap.mjs';
|
|
4
|
+
|
|
5
|
+
export async function parseAsync(...args) {
|
|
6
|
+
return wrap(await bindings.parseAsync(...args));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function parseSync(filename, sourceText, options) {
|
|
10
|
+
return wrap(bindings.parseSync(filename, sourceText, options));
|
|
11
|
+
}
|
package/wrap.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module.exports.wrap = function wrap(result) {
|
|
2
|
+
let program, module, comments, errors;
|
|
3
|
+
return {
|
|
4
|
+
get program() {
|
|
5
|
+
if (!program) {
|
|
6
|
+
// Note: This code is repeated in `crates/oxc-wasm/update-bindings.mjs` and `napi/parser/wrap.cjs`.
|
|
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
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return program;
|
|
28
|
+
},
|
|
29
|
+
get module() {
|
|
30
|
+
if (!module) module = result.module;
|
|
31
|
+
return module;
|
|
32
|
+
},
|
|
33
|
+
get comments() {
|
|
34
|
+
if (!comments) comments = result.comments;
|
|
35
|
+
return comments;
|
|
36
|
+
},
|
|
37
|
+
get errors() {
|
|
38
|
+
if (!errors) errors = result.errors;
|
|
39
|
+
return errors;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
package/wrap.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function wrap(result) {
|
|
2
|
+
let program, module, comments, errors;
|
|
3
|
+
return {
|
|
4
|
+
get program() {
|
|
5
|
+
if (!program) {
|
|
6
|
+
program = jsonParseAst(result.program);
|
|
7
|
+
}
|
|
8
|
+
return program;
|
|
9
|
+
},
|
|
10
|
+
get module() {
|
|
11
|
+
if (!module) module = result.module;
|
|
12
|
+
return module;
|
|
13
|
+
},
|
|
14
|
+
get comments() {
|
|
15
|
+
if (!comments) comments = result.comments;
|
|
16
|
+
return comments;
|
|
17
|
+
},
|
|
18
|
+
get errors() {
|
|
19
|
+
if (!errors) errors = result.errors;
|
|
20
|
+
return errors;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
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
|
+
}
|
package/browser.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@oxc-parser/binding-wasm32-wasi'
|