oxc-parser 0.66.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 +60 -15
- package/deserialize-ts.js +62 -15
- package/package.json +12 -12
- package/wrap.cjs +27 -22
- package/wrap.mjs +23 -20
package/deserialize-js.js
CHANGED
|
@@ -1622,11 +1622,36 @@ function deserializeTSTypeAliasDeclaration(pos) {
|
|
|
1622
1622
|
}
|
|
1623
1623
|
|
|
1624
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
|
+
}
|
|
1625
1650
|
return {
|
|
1626
1651
|
type: 'TSClassImplements',
|
|
1627
1652
|
start: deserializeU32(pos),
|
|
1628
1653
|
end: deserializeU32(pos + 4),
|
|
1629
|
-
expression
|
|
1654
|
+
expression,
|
|
1630
1655
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1631
1656
|
};
|
|
1632
1657
|
}
|
|
@@ -1761,17 +1786,31 @@ function deserializeTSTypePredicate(pos) {
|
|
|
1761
1786
|
}
|
|
1762
1787
|
|
|
1763
1788
|
function deserializeTSModuleDeclaration(pos) {
|
|
1764
|
-
const kind = deserializeTSModuleDeclarationKind(pos + 80)
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
body
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
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;
|
|
1775
1814
|
}
|
|
1776
1815
|
|
|
1777
1816
|
function deserializeTSModuleBlock(pos) {
|
|
@@ -3782,7 +3821,9 @@ function deserializeTSTupleElement(pos) {
|
|
|
3782
3821
|
function deserializeTSTypeName(pos) {
|
|
3783
3822
|
switch (uint8[pos]) {
|
|
3784
3823
|
case 0:
|
|
3785
|
-
|
|
3824
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3825
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3826
|
+
return id;
|
|
3786
3827
|
case 1:
|
|
3787
3828
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3788
3829
|
default:
|
|
@@ -3882,7 +3923,9 @@ function deserializeTSModuleDeclarationBody(pos) {
|
|
|
3882
3923
|
function deserializeTSTypeQueryExprName(pos) {
|
|
3883
3924
|
switch (uint8[pos]) {
|
|
3884
3925
|
case 0:
|
|
3885
|
-
|
|
3926
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3927
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3928
|
+
return id;
|
|
3886
3929
|
case 1:
|
|
3887
3930
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3888
3931
|
case 2:
|
|
@@ -3900,7 +3943,9 @@ function deserializeTSMappedTypeModifierOperator(pos) {
|
|
|
3900
3943
|
function deserializeTSModuleReference(pos) {
|
|
3901
3944
|
switch (uint8[pos]) {
|
|
3902
3945
|
case 0:
|
|
3903
|
-
|
|
3946
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3947
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3948
|
+
return id;
|
|
3904
3949
|
case 1:
|
|
3905
3950
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3906
3951
|
case 2:
|
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
|
|
|
@@ -1772,11 +1774,36 @@ function deserializeTSTypeAliasDeclaration(pos) {
|
|
|
1772
1774
|
}
|
|
1773
1775
|
|
|
1774
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
|
+
}
|
|
1775
1802
|
return {
|
|
1776
1803
|
type: 'TSClassImplements',
|
|
1777
1804
|
start: deserializeU32(pos),
|
|
1778
1805
|
end: deserializeU32(pos + 4),
|
|
1779
|
-
expression
|
|
1806
|
+
expression,
|
|
1780
1807
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 24),
|
|
1781
1808
|
};
|
|
1782
1809
|
}
|
|
@@ -1911,17 +1938,31 @@ function deserializeTSTypePredicate(pos) {
|
|
|
1911
1938
|
}
|
|
1912
1939
|
|
|
1913
1940
|
function deserializeTSModuleDeclaration(pos) {
|
|
1914
|
-
const kind = deserializeTSModuleDeclarationKind(pos + 80)
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
body
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
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;
|
|
1925
1966
|
}
|
|
1926
1967
|
|
|
1927
1968
|
function deserializeTSModuleBlock(pos) {
|
|
@@ -3932,7 +3973,9 @@ function deserializeTSTupleElement(pos) {
|
|
|
3932
3973
|
function deserializeTSTypeName(pos) {
|
|
3933
3974
|
switch (uint8[pos]) {
|
|
3934
3975
|
case 0:
|
|
3935
|
-
|
|
3976
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
3977
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3978
|
+
return id;
|
|
3936
3979
|
case 1:
|
|
3937
3980
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
3938
3981
|
default:
|
|
@@ -4032,7 +4075,9 @@ function deserializeTSModuleDeclarationBody(pos) {
|
|
|
4032
4075
|
function deserializeTSTypeQueryExprName(pos) {
|
|
4033
4076
|
switch (uint8[pos]) {
|
|
4034
4077
|
case 0:
|
|
4035
|
-
|
|
4078
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
4079
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
4080
|
+
return id;
|
|
4036
4081
|
case 1:
|
|
4037
4082
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
4038
4083
|
case 2:
|
|
@@ -4050,7 +4095,9 @@ function deserializeTSMappedTypeModifierOperator(pos) {
|
|
|
4050
4095
|
function deserializeTSModuleReference(pos) {
|
|
4051
4096
|
switch (uint8[pos]) {
|
|
4052
4097
|
case 0:
|
|
4053
|
-
|
|
4098
|
+
let id = deserializeIdentifierReference(pos + 8);
|
|
4099
|
+
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
4100
|
+
return id;
|
|
4054
4101
|
case 1:
|
|
4055
4102
|
return deserializeBoxTSQualifiedName(pos + 8);
|
|
4056
4103
|
case 2:
|
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,7 +39,7 @@
|
|
|
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",
|
|
@@ -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
|
}
|