oxc-parser 0.67.0 → 0.68.1
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.
|
@@ -1853,12 +1853,22 @@ function deserializeTSTypeQuery(pos) {
|
|
|
1853
1853
|
}
|
|
1854
1854
|
|
|
1855
1855
|
function deserializeTSImportType(pos) {
|
|
1856
|
+
let options = deserializeOptionBoxObjectExpression(pos + 24);
|
|
1857
|
+
if (options !== null && options.properties.length === 1) {
|
|
1858
|
+
const prop = options.properties[0];
|
|
1859
|
+
if (
|
|
1860
|
+
!prop.method && !prop.shorthand && !prop.computed &&
|
|
1861
|
+
prop.key.type === 'Identifier' && prop.key.name === 'assert'
|
|
1862
|
+
) {
|
|
1863
|
+
prop.key.name = 'with';
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1856
1866
|
return {
|
|
1857
1867
|
type: 'TSImportType',
|
|
1858
1868
|
start: deserializeU32(pos),
|
|
1859
1869
|
end: deserializeU32(pos + 4),
|
|
1860
1870
|
argument: deserializeTSType(pos + 8),
|
|
1861
|
-
options
|
|
1871
|
+
options,
|
|
1862
1872
|
qualifier: deserializeOptionTSTypeName(pos + 32),
|
|
1863
1873
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
|
|
1864
1874
|
};
|
|
@@ -1898,8 +1908,8 @@ function deserializeTSMappedType(pos) {
|
|
|
1898
1908
|
end: deserializeU32(pos + 4),
|
|
1899
1909
|
nameType: deserializeOptionTSType(pos + 16),
|
|
1900
1910
|
typeAnnotation: deserializeOptionTSType(pos + 32),
|
|
1901
|
-
optional:
|
|
1902
|
-
readonly:
|
|
1911
|
+
optional: deserializeOptionTSMappedTypeModifierOperator(pos + 48),
|
|
1912
|
+
readonly: deserializeOptionTSMappedTypeModifierOperator(pos + 49),
|
|
1903
1913
|
key: typeParameter.name,
|
|
1904
1914
|
constraint: typeParameter.constraint,
|
|
1905
1915
|
};
|
|
@@ -3821,7 +3831,7 @@ function deserializeTSTupleElement(pos) {
|
|
|
3821
3831
|
function deserializeTSTypeName(pos) {
|
|
3822
3832
|
switch (uint8[pos]) {
|
|
3823
3833
|
case 0:
|
|
3824
|
-
let id =
|
|
3834
|
+
let id = deserializeBoxIdentifierReference(pos + 8);
|
|
3825
3835
|
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3826
3836
|
return id;
|
|
3827
3837
|
case 1:
|
|
@@ -3923,7 +3933,7 @@ function deserializeTSModuleDeclarationBody(pos) {
|
|
|
3923
3933
|
function deserializeTSTypeQueryExprName(pos) {
|
|
3924
3934
|
switch (uint8[pos]) {
|
|
3925
3935
|
case 0:
|
|
3926
|
-
let id =
|
|
3936
|
+
let id = deserializeBoxIdentifierReference(pos + 8);
|
|
3927
3937
|
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3928
3938
|
return id;
|
|
3929
3939
|
case 1:
|
|
@@ -3936,14 +3946,22 @@ function deserializeTSTypeQueryExprName(pos) {
|
|
|
3936
3946
|
}
|
|
3937
3947
|
|
|
3938
3948
|
function deserializeTSMappedTypeModifierOperator(pos) {
|
|
3939
|
-
|
|
3940
|
-
|
|
3949
|
+
switch (uint8[pos]) {
|
|
3950
|
+
case 0:
|
|
3951
|
+
return true;
|
|
3952
|
+
case 1:
|
|
3953
|
+
return '+';
|
|
3954
|
+
case 2:
|
|
3955
|
+
return '-';
|
|
3956
|
+
default:
|
|
3957
|
+
throw new Error(`Unexpected discriminant ${uint8[pos]} for TSMappedTypeModifierOperator`);
|
|
3958
|
+
}
|
|
3941
3959
|
}
|
|
3942
3960
|
|
|
3943
3961
|
function deserializeTSModuleReference(pos) {
|
|
3944
3962
|
switch (uint8[pos]) {
|
|
3945
3963
|
case 0:
|
|
3946
|
-
let id =
|
|
3964
|
+
let id = deserializeBoxIdentifierReference(pos + 8);
|
|
3947
3965
|
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3948
3966
|
return id;
|
|
3949
3967
|
case 1:
|
|
@@ -5560,6 +5578,11 @@ function deserializeOptionTSTypeName(pos) {
|
|
|
5560
5578
|
return deserializeTSTypeName(pos);
|
|
5561
5579
|
}
|
|
5562
5580
|
|
|
5581
|
+
function deserializeOptionTSMappedTypeModifierOperator(pos) {
|
|
5582
|
+
if (uint8[pos] === 3) return null;
|
|
5583
|
+
return deserializeTSMappedTypeModifierOperator(pos);
|
|
5584
|
+
}
|
|
5585
|
+
|
|
5563
5586
|
function deserializeBoxTSExternalModuleReference(pos) {
|
|
5564
5587
|
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
|
|
5565
5588
|
}
|
|
@@ -2005,12 +2005,22 @@ function deserializeTSTypeQuery(pos) {
|
|
|
2005
2005
|
}
|
|
2006
2006
|
|
|
2007
2007
|
function deserializeTSImportType(pos) {
|
|
2008
|
+
let options = deserializeOptionBoxObjectExpression(pos + 24);
|
|
2009
|
+
if (options !== null && options.properties.length === 1) {
|
|
2010
|
+
const prop = options.properties[0];
|
|
2011
|
+
if (
|
|
2012
|
+
!prop.method && !prop.shorthand && !prop.computed &&
|
|
2013
|
+
prop.key.type === 'Identifier' && prop.key.name === 'assert'
|
|
2014
|
+
) {
|
|
2015
|
+
prop.key.name = 'with';
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2008
2018
|
return {
|
|
2009
2019
|
type: 'TSImportType',
|
|
2010
2020
|
start: deserializeU32(pos),
|
|
2011
2021
|
end: deserializeU32(pos + 4),
|
|
2012
2022
|
argument: deserializeTSType(pos + 8),
|
|
2013
|
-
options
|
|
2023
|
+
options,
|
|
2014
2024
|
qualifier: deserializeOptionTSTypeName(pos + 32),
|
|
2015
2025
|
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
|
|
2016
2026
|
};
|
|
@@ -2050,8 +2060,8 @@ function deserializeTSMappedType(pos) {
|
|
|
2050
2060
|
end: deserializeU32(pos + 4),
|
|
2051
2061
|
nameType: deserializeOptionTSType(pos + 16),
|
|
2052
2062
|
typeAnnotation: deserializeOptionTSType(pos + 32),
|
|
2053
|
-
optional:
|
|
2054
|
-
readonly:
|
|
2063
|
+
optional: deserializeOptionTSMappedTypeModifierOperator(pos + 48),
|
|
2064
|
+
readonly: deserializeOptionTSMappedTypeModifierOperator(pos + 49),
|
|
2055
2065
|
key: typeParameter.name,
|
|
2056
2066
|
constraint: typeParameter.constraint,
|
|
2057
2067
|
};
|
|
@@ -3973,7 +3983,7 @@ function deserializeTSTupleElement(pos) {
|
|
|
3973
3983
|
function deserializeTSTypeName(pos) {
|
|
3974
3984
|
switch (uint8[pos]) {
|
|
3975
3985
|
case 0:
|
|
3976
|
-
let id =
|
|
3986
|
+
let id = deserializeBoxIdentifierReference(pos + 8);
|
|
3977
3987
|
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
3978
3988
|
return id;
|
|
3979
3989
|
case 1:
|
|
@@ -4075,7 +4085,7 @@ function deserializeTSModuleDeclarationBody(pos) {
|
|
|
4075
4085
|
function deserializeTSTypeQueryExprName(pos) {
|
|
4076
4086
|
switch (uint8[pos]) {
|
|
4077
4087
|
case 0:
|
|
4078
|
-
let id =
|
|
4088
|
+
let id = deserializeBoxIdentifierReference(pos + 8);
|
|
4079
4089
|
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
4080
4090
|
return id;
|
|
4081
4091
|
case 1:
|
|
@@ -4088,14 +4098,22 @@ function deserializeTSTypeQueryExprName(pos) {
|
|
|
4088
4098
|
}
|
|
4089
4099
|
|
|
4090
4100
|
function deserializeTSMappedTypeModifierOperator(pos) {
|
|
4091
|
-
|
|
4092
|
-
|
|
4101
|
+
switch (uint8[pos]) {
|
|
4102
|
+
case 0:
|
|
4103
|
+
return true;
|
|
4104
|
+
case 1:
|
|
4105
|
+
return '+';
|
|
4106
|
+
case 2:
|
|
4107
|
+
return '-';
|
|
4108
|
+
default:
|
|
4109
|
+
throw new Error(`Unexpected discriminant ${uint8[pos]} for TSMappedTypeModifierOperator`);
|
|
4110
|
+
}
|
|
4093
4111
|
}
|
|
4094
4112
|
|
|
4095
4113
|
function deserializeTSModuleReference(pos) {
|
|
4096
4114
|
switch (uint8[pos]) {
|
|
4097
4115
|
case 0:
|
|
4098
|
-
let id =
|
|
4116
|
+
let id = deserializeBoxIdentifierReference(pos + 8);
|
|
4099
4117
|
if (id.name === 'this') id = { type: 'ThisExpression', start: id.start, end: id.end };
|
|
4100
4118
|
return id;
|
|
4101
4119
|
case 1:
|
|
@@ -5712,6 +5730,11 @@ function deserializeOptionTSTypeName(pos) {
|
|
|
5712
5730
|
return deserializeTSTypeName(pos);
|
|
5713
5731
|
}
|
|
5714
5732
|
|
|
5733
|
+
function deserializeOptionTSMappedTypeModifierOperator(pos) {
|
|
5734
|
+
if (uint8[pos] === 3) return null;
|
|
5735
|
+
return deserializeTSMappedTypeModifierOperator(pos);
|
|
5736
|
+
}
|
|
5737
|
+
|
|
5715
5738
|
function deserializeBoxTSExternalModuleReference(pos) {
|
|
5716
5739
|
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
|
|
5717
5740
|
}
|
package/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
const bindings = require('./bindings.js');
|
|
2
|
-
const deserializeJS = require('./deserialize-js.js');
|
|
3
|
-
const deserializeTS = require('./deserialize-ts.js');
|
|
4
2
|
const { wrap } = require('./wrap.cjs');
|
|
5
3
|
|
|
6
4
|
module.exports.ParseResult = bindings.ParseResult;
|
|
@@ -22,7 +20,7 @@ module.exports.parseSync = function parseSync(filename, sourceText, options) {
|
|
|
22
20
|
return wrap(bindings.parseSync(filename, sourceText, options));
|
|
23
21
|
};
|
|
24
22
|
|
|
25
|
-
let buffer, encoder;
|
|
23
|
+
let buffer, encoder, deserializeJS, deserializeTS;
|
|
26
24
|
|
|
27
25
|
function parseSyncRaw(filename, sourceText, options) {
|
|
28
26
|
if (!rawTransferSupported()) {
|
|
@@ -62,9 +60,23 @@ function parseSyncRaw(filename, sourceText, options) {
|
|
|
62
60
|
const astTypeFlagPos = 2147483636;
|
|
63
61
|
let isJsAst = buffer[astTypeFlagPos] === 0;
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
// Lazy load deserializer, and deserialize buffer to JS objects
|
|
64
|
+
let data;
|
|
65
|
+
if (isJsAst) {
|
|
66
|
+
if (!deserializeJS) deserializeJS = require('./generated/deserialize/js.js');
|
|
67
|
+
data = deserializeJS(buffer, sourceText, sourceByteLen);
|
|
68
|
+
|
|
69
|
+
// Add a line comment for hashbang
|
|
70
|
+
const { hashbang } = data.program;
|
|
71
|
+
if (hashbang !== null) {
|
|
72
|
+
data.comments.unshift({ type: 'Line', value: hashbang.value, start: hashbang.start, end: hashbang.end });
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
if (!deserializeTS) deserializeTS = require('./generated/deserialize/ts.js');
|
|
76
|
+
data = deserializeTS(buffer, sourceText, sourceByteLen);
|
|
77
|
+
// Note: Do not add line comment for hashbang, to match `@typescript-eslint/parser`.
|
|
78
|
+
// See https://github.com/oxc-project/oxc/blob/ea784f5f082e4c53c98afde9bf983afd0b95e44e/napi/parser/src/lib.rs#L106-L130
|
|
79
|
+
}
|
|
68
80
|
|
|
69
81
|
return {
|
|
70
82
|
get program() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.68.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"browser": "wasm.mjs",
|
|
6
6
|
"engines": {
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
"wasm.mjs",
|
|
32
32
|
"bindings.js",
|
|
33
33
|
"webcontainer-fallback.js",
|
|
34
|
-
"deserialize
|
|
35
|
-
"deserialize
|
|
34
|
+
"generated/deserialize/js.js",
|
|
35
|
+
"generated/deserialize/ts.js"
|
|
36
36
|
],
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"registry": "https://registry.npmjs.org/",
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@oxc-project/types": "^0.
|
|
42
|
+
"@oxc-project/types": "^0.68.1"
|
|
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.68.1",
|
|
76
|
+
"@oxc-parser/binding-win32-arm64-msvc": "0.68.1",
|
|
77
|
+
"@oxc-parser/binding-linux-x64-gnu": "0.68.1",
|
|
78
|
+
"@oxc-parser/binding-linux-x64-musl": "0.68.1",
|
|
79
|
+
"@oxc-parser/binding-linux-arm64-gnu": "0.68.1",
|
|
80
|
+
"@oxc-parser/binding-linux-arm64-musl": "0.68.1",
|
|
81
|
+
"@oxc-parser/binding-linux-arm-gnueabihf": "0.68.1",
|
|
82
|
+
"@oxc-parser/binding-darwin-x64": "0.68.1",
|
|
83
|
+
"@oxc-parser/binding-darwin-arm64": "0.68.1",
|
|
84
|
+
"@oxc-parser/binding-wasm32-wasi": "0.68.1"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"build-dev": "napi build --no-dts-cache --platform --js bindings.js",
|