oxc-parser 0.65.0 → 0.67.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/deserialize-js.js +63 -25
- package/deserialize-ts.js +91 -28
- package/package.json +14 -14
- package/wrap.cjs +27 -22
- package/wrap.mjs +23 -20
package/deserialize-js.js
CHANGED
|
@@ -788,9 +788,7 @@ function deserializeFormalParameters(pos) {
|
|
|
788
788
|
}
|
|
789
789
|
|
|
790
790
|
function deserializeFormalParameter(pos) {
|
|
791
|
-
return
|
|
792
|
-
...deserializeBindingPatternKind(pos + 40),
|
|
793
|
-
};
|
|
791
|
+
return deserializeBindingPatternKind(pos + 40);
|
|
794
792
|
}
|
|
795
793
|
|
|
796
794
|
function deserializeFunctionBody(pos) {
|
|
@@ -1624,11 +1622,36 @@ function deserializeTSTypeAliasDeclaration(pos) {
|
|
|
1624
1622
|
}
|
|
1625
1623
|
|
|
1626
1624
|
function deserializeTSClassImplements(pos) {
|
|
1625
|
+
let expression = deserializeTSTypeName(pos + 8);
|
|
1626
|
+
if (expression.type === 'TSQualifiedName') {
|
|
1627
|
+
let parent = expression = {
|
|
1628
|
+
type: 'MemberExpression',
|
|
1629
|
+
start: expression.start,
|
|
1630
|
+
end: expression.end,
|
|
1631
|
+
object: expression.left,
|
|
1632
|
+
property: expression.right,
|
|
1633
|
+
computed: false,
|
|
1634
|
+
optional: false,
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
while (parent.object.type === 'TSQualifiedName') {
|
|
1638
|
+
const object = parent.object;
|
|
1639
|
+
parent = parent.object = {
|
|
1640
|
+
type: 'MemberExpression',
|
|
1641
|
+
start: object.start,
|
|
1642
|
+
end: object.end,
|
|
1643
|
+
object: object.left,
|
|
1644
|
+
property: object.right,
|
|
1645
|
+
computed: false,
|
|
1646
|
+
optional: false,
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1627
1650
|
return {
|
|
1628
1651
|
type: 'TSClassImplements',
|
|
1629
1652
|
start: deserializeU32(pos),
|
|
1630
1653
|
end: deserializeU32(pos + 4),
|
|
1631
|
-
expression
|
|
1654
|
+
expression,
|
|
1632
1655
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1633
1656
|
};
|
|
1634
1657
|
}
|
|
@@ -1684,7 +1707,7 @@ function deserializeTSIndexSignature(pos) {
|
|
|
1684
1707
|
}
|
|
1685
1708
|
|
|
1686
1709
|
function deserializeTSCallSignatureDeclaration(pos) {
|
|
1687
|
-
const params = deserializeBoxFormalParameters(pos +
|
|
1710
|
+
const params = deserializeBoxFormalParameters(pos + 24);
|
|
1688
1711
|
const thisParam = deserializeOptionBoxTSThisParameter(pos + 16);
|
|
1689
1712
|
if (thisParam !== null) params.unshift(thisParam);
|
|
1690
1713
|
return {
|
|
@@ -1693,7 +1716,7 @@ function deserializeTSCallSignatureDeclaration(pos) {
|
|
|
1693
1716
|
end: deserializeU32(pos + 4),
|
|
1694
1717
|
typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 8),
|
|
1695
1718
|
params,
|
|
1696
|
-
returnType: deserializeOptionBoxTSTypeAnnotation(pos +
|
|
1719
|
+
returnType: deserializeOptionBoxTSTypeAnnotation(pos + 32),
|
|
1697
1720
|
};
|
|
1698
1721
|
}
|
|
1699
1722
|
|
|
@@ -1763,17 +1786,31 @@ function deserializeTSTypePredicate(pos) {
|
|
|
1763
1786
|
}
|
|
1764
1787
|
|
|
1765
1788
|
function deserializeTSModuleDeclaration(pos) {
|
|
1766
|
-
const kind = deserializeTSModuleDeclarationKind(pos + 80)
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
body
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1789
|
+
const kind = deserializeTSModuleDeclarationKind(pos + 80),
|
|
1790
|
+
global = kind === 'global',
|
|
1791
|
+
start = deserializeU32(pos),
|
|
1792
|
+
end = deserializeU32(pos + 4),
|
|
1793
|
+
declare = deserializeBool(pos + 81);
|
|
1794
|
+
let id = deserializeTSModuleDeclarationName(pos + 8),
|
|
1795
|
+
body = deserializeOptionTSModuleDeclarationBody(pos + 64);
|
|
1796
|
+
|
|
1797
|
+
// Flatten `body`, and nest `id`
|
|
1798
|
+
if (body !== null && body.type === 'TSModuleDeclaration') {
|
|
1799
|
+
id = {
|
|
1800
|
+
type: 'TSQualifiedName',
|
|
1801
|
+
start: body.id.start,
|
|
1802
|
+
end: id.end,
|
|
1803
|
+
left: body.id,
|
|
1804
|
+
right: id,
|
|
1805
|
+
};
|
|
1806
|
+
body = Object.hasOwn(body, 'body') ? body.body : null;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
// Skip `body` field if `null`
|
|
1810
|
+
const node = body === null
|
|
1811
|
+
? { type: 'TSModuleDeclaration', start, end, id, kind, declare, global }
|
|
1812
|
+
: { type: 'TSModuleDeclaration', start, end, id, body, kind, declare, global };
|
|
1813
|
+
return node;
|
|
1777
1814
|
}
|
|
1778
1815
|
|
|
1779
1816
|
function deserializeTSModuleBlock(pos) {
|
|
@@ -3784,7 +3821,9 @@ function deserializeTSTupleElement(pos) {
|
|
|
3784
3821
|
function deserializeTSTypeName(pos) {
|
|
3785
3822
|
switch (uint8[pos]) {
|
|
3786
3823
|
case 0:
|
|
3787
|
-
|
|
3824
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3825
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3826
|
+
return id;
|
|
3788
3827
|
case 1:
|
|
3789
3828
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3790
3829
|
default:
|
|
@@ -3884,7 +3923,9 @@ function deserializeTSModuleDeclarationBody(pos) {
|
|
|
3884
3923
|
function deserializeTSTypeQueryExprName(pos) {
|
|
3885
3924
|
switch (uint8[pos]) {
|
|
3886
3925
|
case 0:
|
|
3887
|
-
|
|
3926
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3927
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3928
|
+
return id;
|
|
3888
3929
|
case 1:
|
|
3889
3930
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3890
3931
|
case 2:
|
|
@@ -3902,7 +3943,9 @@ function deserializeTSMappedTypeModifierOperator(pos) {
|
|
|
3902
3943
|
function deserializeTSModuleReference(pos) {
|
|
3903
3944
|
switch (uint8[pos]) {
|
|
3904
3945
|
case 0:
|
|
3905
|
-
|
|
3946
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3947
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3948
|
+
return id;
|
|
3906
3949
|
case 1:
|
|
3907
3950
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3908
3951
|
case 2:
|
|
@@ -5494,11 +5537,6 @@ function deserializeVecTSIndexSignatureName(pos) {
|
|
|
5494
5537
|
return arr;
|
|
5495
5538
|
}
|
|
5496
5539
|
|
|
5497
|
-
function deserializeOptionTSThisParameter(pos) {
|
|
5498
|
-
if (uint8[pos] === 0) return null;
|
|
5499
|
-
return deserializeTSThisParameter(pos + 8);
|
|
5500
|
-
}
|
|
5501
|
-
|
|
5502
5540
|
function deserializeOptionTSModuleDeclarationBody(pos) {
|
|
5503
5541
|
if (uint8[pos] === 2) return null;
|
|
5504
5542
|
return deserializeTSModuleDeclarationBody(pos);
|
package/deserialize-ts.js
CHANGED
|
@@ -781,6 +781,8 @@ function deserializeObjectPattern(pos) {
|
|
|
781
781
|
end: deserializeU32(pos + 4),
|
|
782
782
|
properties,
|
|
783
783
|
decorators: [],
|
|
784
|
+
optional: false,
|
|
785
|
+
typeAnnotation: null,
|
|
784
786
|
};
|
|
785
787
|
}
|
|
786
788
|
|
|
@@ -860,18 +862,39 @@ function deserializeFormalParameters(pos) {
|
|
|
860
862
|
pos + 24,
|
|
861
863
|
),
|
|
862
864
|
optional: deserializeBool(pos + 32),
|
|
865
|
+
decorators: [],
|
|
866
|
+
value: null,
|
|
863
867
|
});
|
|
864
868
|
}
|
|
865
869
|
return params;
|
|
866
870
|
}
|
|
867
871
|
|
|
868
872
|
function deserializeFormalParameter(pos) {
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
873
|
+
const accessibility = deserializeOptionTSAccessibility(pos + 72),
|
|
874
|
+
readonly = deserializeBool(pos + 73),
|
|
875
|
+
override = deserializeBool(pos + 74);
|
|
876
|
+
let param;
|
|
877
|
+
if (accessibility === null && !readonly && !override) {
|
|
878
|
+
param = {
|
|
879
|
+
...deserializeBindingPatternKind(pos + 40),
|
|
880
|
+
typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 56),
|
|
881
|
+
optional: deserializeBool(pos + 64),
|
|
882
|
+
decorators: deserializeVecDecorator(pos + 8),
|
|
883
|
+
};
|
|
884
|
+
} else {
|
|
885
|
+
param = {
|
|
886
|
+
type: 'TSParameterProperty',
|
|
887
|
+
start: deserializeU32(pos),
|
|
888
|
+
end: deserializeU32(pos + 4),
|
|
889
|
+
accessibility,
|
|
890
|
+
decorators: deserializeVecDecorator(pos + 8),
|
|
891
|
+
override,
|
|
892
|
+
parameter: deserializeBindingPattern(pos + 40),
|
|
893
|
+
readonly,
|
|
894
|
+
static: false,
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return param;
|
|
875
898
|
}
|
|
876
899
|
|
|
877
900
|
function deserializeFunctionBody(pos) {
|
|
@@ -1751,11 +1774,36 @@ function deserializeTSTypeAliasDeclaration(pos) {
|
|
|
1751
1774
|
}
|
|
1752
1775
|
|
|
1753
1776
|
function deserializeTSClassImplements(pos) {
|
|
1777
|
+
let expression = deserializeTSTypeName(pos + 8);
|
|
1778
|
+
if (expression.type === 'TSQualifiedName') {
|
|
1779
|
+
let parent = expression = {
|
|
1780
|
+
type: 'MemberExpression',
|
|
1781
|
+
start: expression.start,
|
|
1782
|
+
end: expression.end,
|
|
1783
|
+
object: expression.left,
|
|
1784
|
+
property: expression.right,
|
|
1785
|
+
computed: false,
|
|
1786
|
+
optional: false,
|
|
1787
|
+
};
|
|
1788
|
+
|
|
1789
|
+
while (parent.object.type === 'TSQualifiedName') {
|
|
1790
|
+
const object = parent.object;
|
|
1791
|
+
parent = parent.object = {
|
|
1792
|
+
type: 'MemberExpression',
|
|
1793
|
+
start: object.start,
|
|
1794
|
+
end: object.end,
|
|
1795
|
+
object: object.left,
|
|
1796
|
+
property: object.right,
|
|
1797
|
+
computed: false,
|
|
1798
|
+
optional: false,
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1754
1802
|
return {
|
|
1755
1803
|
type: 'TSClassImplements',
|
|
1756
1804
|
start: deserializeU32(pos),
|
|
1757
1805
|
end: deserializeU32(pos + 4),
|
|
1758
|
-
expression
|
|
1806
|
+
expression,
|
|
1759
1807
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1760
1808
|
};
|
|
1761
1809
|
}
|
|
@@ -1811,7 +1859,7 @@ function deserializeTSIndexSignature(pos) {
|
|
|
1811
1859
|
}
|
|
1812
1860
|
|
|
1813
1861
|
function deserializeTSCallSignatureDeclaration(pos) {
|
|
1814
|
-
const params = deserializeBoxFormalParameters(pos +
|
|
1862
|
+
const params = deserializeBoxFormalParameters(pos + 24);
|
|
1815
1863
|
const thisParam = deserializeOptionBoxTSThisParameter(pos + 16);
|
|
1816
1864
|
if (thisParam !== null) params.unshift(thisParam);
|
|
1817
1865
|
return {
|
|
@@ -1820,7 +1868,7 @@ function deserializeTSCallSignatureDeclaration(pos) {
|
|
|
1820
1868
|
end: deserializeU32(pos + 4),
|
|
1821
1869
|
typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 8),
|
|
1822
1870
|
params,
|
|
1823
|
-
returnType: deserializeOptionBoxTSTypeAnnotation(pos +
|
|
1871
|
+
returnType: deserializeOptionBoxTSTypeAnnotation(pos + 32),
|
|
1824
1872
|
};
|
|
1825
1873
|
}
|
|
1826
1874
|
|
|
@@ -1890,17 +1938,31 @@ function deserializeTSTypePredicate(pos) {
|
|
|
1890
1938
|
}
|
|
1891
1939
|
|
|
1892
1940
|
function deserializeTSModuleDeclaration(pos) {
|
|
1893
|
-
const kind = deserializeTSModuleDeclarationKind(pos + 80)
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
body
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1941
|
+
const kind = deserializeTSModuleDeclarationKind(pos + 80),
|
|
1942
|
+
global = kind === 'global',
|
|
1943
|
+
start = deserializeU32(pos),
|
|
1944
|
+
end = deserializeU32(pos + 4),
|
|
1945
|
+
declare = deserializeBool(pos + 81);
|
|
1946
|
+
let id = deserializeTSModuleDeclarationName(pos + 8),
|
|
1947
|
+
body = deserializeOptionTSModuleDeclarationBody(pos + 64);
|
|
1948
|
+
|
|
1949
|
+
// Flatten `body`, and nest `id`
|
|
1950
|
+
if (body !== null && body.type === 'TSModuleDeclaration') {
|
|
1951
|
+
id = {
|
|
1952
|
+
type: 'TSQualifiedName',
|
|
1953
|
+
start: body.id.start,
|
|
1954
|
+
end: id.end,
|
|
1955
|
+
left: body.id,
|
|
1956
|
+
right: id,
|
|
1957
|
+
};
|
|
1958
|
+
body = Object.hasOwn(body, 'body') ? body.body : null;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
// Skip `body` field if `null`
|
|
1962
|
+
const node = body === null
|
|
1963
|
+
? { type: 'TSModuleDeclaration', start, end, id, kind, declare, global }
|
|
1964
|
+
: { type: 'TSModuleDeclaration', start, end, id, body, kind, declare, global };
|
|
1965
|
+
return node;
|
|
1904
1966
|
}
|
|
1905
1967
|
|
|
1906
1968
|
function deserializeTSModuleBlock(pos) {
|
|
@@ -3911,7 +3973,9 @@ function deserializeTSTupleElement(pos) {
|
|
|
3911
3973
|
function deserializeTSTypeName(pos) {
|
|
3912
3974
|
switch (uint8[pos]) {
|
|
3913
3975
|
case 0:
|
|
3914
|
-
|
|
3976
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3977
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3978
|
+
return id;
|
|
3915
3979
|
case 1:
|
|
3916
3980
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3917
3981
|
default:
|
|
@@ -4011,7 +4075,9 @@ function deserializeTSModuleDeclarationBody(pos) {
|
|
|
4011
4075
|
function deserializeTSTypeQueryExprName(pos) {
|
|
4012
4076
|
switch (uint8[pos]) {
|
|
4013
4077
|
case 0:
|
|
4014
|
-
|
|
4078
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
4079
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
4080
|
+
return id;
|
|
4015
4081
|
case 1:
|
|
4016
4082
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
4017
4083
|
case 2:
|
|
@@ -4029,7 +4095,9 @@ function deserializeTSMappedTypeModifierOperator(pos) {
|
|
|
4029
4095
|
function deserializeTSModuleReference(pos) {
|
|
4030
4096
|
switch (uint8[pos]) {
|
|
4031
4097
|
case 0:
|
|
4032
|
-
|
|
4098
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
4099
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
4100
|
+
return id;
|
|
4033
4101
|
case 1:
|
|
4034
4102
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
4035
4103
|
case 2:
|
|
@@ -5621,11 +5689,6 @@ function deserializeVecTSIndexSignatureName(pos) {
|
|
|
5621
5689
|
return arr;
|
|
5622
5690
|
}
|
|
5623
5691
|
|
|
5624
|
-
function deserializeOptionTSThisParameter(pos) {
|
|
5625
|
-
if (uint8[pos] === 0) return null;
|
|
5626
|
-
return deserializeTSThisParameter(pos + 8);
|
|
5627
|
-
}
|
|
5628
|
-
|
|
5629
5692
|
function deserializeOptionTSModuleDeclarationBody(pos) {
|
|
5630
5693
|
if (uint8[pos] === 2) return null;
|
|
5631
5694
|
return deserializeTSModuleDeclarationBody(pos);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"browser": "wasm.mjs",
|
|
6
6
|
"engines": {
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@oxc-project/types": "^0.
|
|
42
|
+
"@oxc-project/types": "^0.67.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@codspeed/vitest-plugin": "^4.0.0",
|
|
46
46
|
"@napi-rs/wasm-runtime": "^0.2.7",
|
|
47
|
-
"@vitest/browser": "3.1.
|
|
47
|
+
"@vitest/browser": "3.1.2",
|
|
48
48
|
"esbuild": "^0.25.0",
|
|
49
49
|
"playwright": "^1.51.0",
|
|
50
|
-
"vitest": "3.1.
|
|
50
|
+
"vitest": "3.1.2"
|
|
51
51
|
},
|
|
52
52
|
"napi": {
|
|
53
53
|
"binaryName": "parser",
|
|
@@ -72,16 +72,16 @@
|
|
|
72
72
|
"dtsHeaderFile": "header.js"
|
|
73
73
|
},
|
|
74
74
|
"optionalDependencies": {
|
|
75
|
-
"@oxc-parser/binding-win32-x64-msvc": "0.
|
|
76
|
-
"@oxc-parser/binding-win32-arm64-msvc": "0.
|
|
77
|
-
"@oxc-parser/binding-linux-x64-gnu": "0.
|
|
78
|
-
"@oxc-parser/binding-linux-x64-musl": "0.
|
|
79
|
-
"@oxc-parser/binding-linux-arm64-gnu": "0.
|
|
80
|
-
"@oxc-parser/binding-linux-arm64-musl": "0.
|
|
81
|
-
"@oxc-parser/binding-linux-arm-gnueabihf": "0.
|
|
82
|
-
"@oxc-parser/binding-darwin-x64": "0.
|
|
83
|
-
"@oxc-parser/binding-darwin-arm64": "0.
|
|
84
|
-
"@oxc-parser/binding-wasm32-wasi": "0.
|
|
75
|
+
"@oxc-parser/binding-win32-x64-msvc": "0.67.0",
|
|
76
|
+
"@oxc-parser/binding-win32-arm64-msvc": "0.67.0",
|
|
77
|
+
"@oxc-parser/binding-linux-x64-gnu": "0.67.0",
|
|
78
|
+
"@oxc-parser/binding-linux-x64-musl": "0.67.0",
|
|
79
|
+
"@oxc-parser/binding-linux-arm64-gnu": "0.67.0",
|
|
80
|
+
"@oxc-parser/binding-linux-arm64-musl": "0.67.0",
|
|
81
|
+
"@oxc-parser/binding-linux-arm-gnueabihf": "0.67.0",
|
|
82
|
+
"@oxc-parser/binding-darwin-x64": "0.67.0",
|
|
83
|
+
"@oxc-parser/binding-darwin-arm64": "0.67.0",
|
|
84
|
+
"@oxc-parser/binding-wasm32-wasi": "0.67.0"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"build-dev": "napi build --no-dts-cache --platform --js bindings.js",
|
package/wrap.cjs
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
|
+
// Note: This code is repeated in `wrap.mjs`.
|
|
2
|
+
// Any changes should be applied in that file too.
|
|
3
|
+
|
|
1
4
|
module.exports.wrap = function wrap(result) {
|
|
2
5
|
let program, module, comments, errors;
|
|
3
6
|
return {
|
|
4
7
|
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
|
-
}
|
|
8
|
+
if (!program) program = jsonParseAst(result.program);
|
|
27
9
|
return program;
|
|
28
10
|
},
|
|
29
11
|
get module() {
|
|
@@ -40,3 +22,26 @@ module.exports.wrap = function wrap(result) {
|
|
|
40
22
|
},
|
|
41
23
|
};
|
|
42
24
|
};
|
|
25
|
+
|
|
26
|
+
function jsonParseAst(program) {
|
|
27
|
+
return JSON.parse(program, transform);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function transform(key, value) {
|
|
31
|
+
// Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
|
|
32
|
+
// This is not possible to do on Rust side, as neither can be represented correctly in JSON.
|
|
33
|
+
if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
|
|
34
|
+
if (Object.hasOwn(this, 'bigint')) {
|
|
35
|
+
return BigInt(this.bigint);
|
|
36
|
+
}
|
|
37
|
+
if (Object.hasOwn(this, 'regex')) {
|
|
38
|
+
const { regex } = this;
|
|
39
|
+
try {
|
|
40
|
+
return RegExp(regex.pattern, regex.flags);
|
|
41
|
+
} catch (_err) {
|
|
42
|
+
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
package/wrap.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// Note: This code is repeated in `wrap.cjs`.
|
|
2
|
+
// Any changes should be applied in that file too.
|
|
3
|
+
|
|
1
4
|
export function wrap(result) {
|
|
2
5
|
let program, module, comments, errors;
|
|
3
6
|
return {
|
|
4
7
|
get program() {
|
|
5
|
-
if (!program)
|
|
6
|
-
program = jsonParseAst(result.program);
|
|
7
|
-
}
|
|
8
|
+
if (!program) program = jsonParseAst(result.program);
|
|
8
9
|
return program;
|
|
9
10
|
},
|
|
10
11
|
get module() {
|
|
@@ -23,23 +24,25 @@ export function wrap(result) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
// Used by napi/playground/patch.mjs
|
|
26
|
-
export function jsonParseAst(
|
|
27
|
-
return JSON.parse(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
export function jsonParseAst(program) {
|
|
28
|
+
return JSON.parse(program, transform);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function transform(key, value) {
|
|
32
|
+
// Set `value` field of `Literal`s for `BigInt`s and `RegExp`s.
|
|
33
|
+
// This is not possible to do on Rust side, as neither can be represented correctly in JSON.
|
|
34
|
+
if (value === null && key === 'value' && Object.hasOwn(this, 'type') && this.type === 'Literal') {
|
|
35
|
+
if (Object.hasOwn(this, 'bigint')) {
|
|
36
|
+
return BigInt(this.bigint);
|
|
37
|
+
}
|
|
38
|
+
if (Object.hasOwn(this, 'regex')) {
|
|
39
|
+
const { regex } = this;
|
|
40
|
+
try {
|
|
41
|
+
return RegExp(regex.pattern, regex.flags);
|
|
42
|
+
} catch (_err) {
|
|
43
|
+
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
45
48
|
}
|