oxc-parser 0.56.5 → 0.58.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 -12
- package/deserialize-js.js +13 -12
- package/deserialize-ts.js +13 -12
- package/index.d.ts +3 -3
- package/index.js +41 -3
- package/package.json +25 -15
package/README.md
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
### ESTree
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
When parsing `.js` or `.jsx` files, the AST returned is fully conformant with the
|
|
8
|
+
[ESTree standard](https://github.com/estree/estree).
|
|
8
9
|
|
|
9
10
|
It is fully aligned with Acorn's AST, and any deviation would be considered a bug.
|
|
10
11
|
|
|
11
12
|
The returned TypeScript AST will conform to [@typescript-eslint/typescript-estree](https://www.npmjs.com/package/@typescript-eslint/typescript-estree) in the near future.
|
|
12
13
|
|
|
14
|
+
If you need all ASTs in the same with-TS-properties format, use the `astType: 'ts'` option.
|
|
15
|
+
|
|
13
16
|
### AST Types
|
|
14
17
|
|
|
15
18
|
[@oxc-project/types](https://www.npmjs.com/package/@oxc-project/types) can be used. For example:
|
|
@@ -41,17 +44,6 @@ Fast mode is best suited for parser plugins, where other parts of your build pip
|
|
|
41
44
|
|
|
42
45
|
Please note that turning off fast mode incurs a small performance overhead.
|
|
43
46
|
|
|
44
|
-
### ESTree compatibility
|
|
45
|
-
|
|
46
|
-
When parsing JS or JSX files, the AST returned is fully conformant with the
|
|
47
|
-
[ESTree standard](https://github.com/estree/estree).
|
|
48
|
-
|
|
49
|
-
When parsing TS or TSX files, the AST has additional properties related to TypeScript syntax.
|
|
50
|
-
These extra properties are broadly (but not entirely) in line with
|
|
51
|
-
[TypeScript ESLint](https://typescript-eslint.io/packages/parser/)'s AST.
|
|
52
|
-
|
|
53
|
-
If you need all ASTs in the same with-TS-properties format, use the `astType: 'ts'` option.
|
|
54
|
-
|
|
55
47
|
### Returns ESM information.
|
|
56
48
|
|
|
57
49
|
It is likely that you are writing a parser plugin that requires ESM information.
|
package/deserialize-js.js
CHANGED
|
@@ -894,13 +894,13 @@ function deserializeAccessorProperty(pos) {
|
|
|
894
894
|
}
|
|
895
895
|
|
|
896
896
|
function deserializeImportExpression(pos) {
|
|
897
|
-
const
|
|
897
|
+
const options = deserializeVecExpression(pos + 24);
|
|
898
898
|
return {
|
|
899
899
|
type: 'ImportExpression',
|
|
900
900
|
start: deserializeU32(pos),
|
|
901
901
|
end: deserializeU32(pos + 4),
|
|
902
902
|
source: deserializeExpression(pos + 8),
|
|
903
|
-
options:
|
|
903
|
+
options: options.length === 0 ? null : options[0],
|
|
904
904
|
};
|
|
905
905
|
}
|
|
906
906
|
|
|
@@ -1180,7 +1180,7 @@ function deserializeJSXNamespacedName(pos) {
|
|
|
1180
1180
|
start: deserializeU32(pos),
|
|
1181
1181
|
end: deserializeU32(pos + 4),
|
|
1182
1182
|
namespace: deserializeJSXIdentifier(pos + 8),
|
|
1183
|
-
|
|
1183
|
+
name: deserializeJSXIdentifier(pos + 32),
|
|
1184
1184
|
};
|
|
1185
1185
|
}
|
|
1186
1186
|
|
|
@@ -1254,6 +1254,7 @@ function deserializeJSXText(pos) {
|
|
|
1254
1254
|
start: deserializeU32(pos),
|
|
1255
1255
|
end: deserializeU32(pos + 4),
|
|
1256
1256
|
value: deserializeStr(pos + 8),
|
|
1257
|
+
raw: deserializeOptionStr(pos + 24),
|
|
1257
1258
|
};
|
|
1258
1259
|
}
|
|
1259
1260
|
|
|
@@ -1771,11 +1772,11 @@ function deserializeTSImportType(pos) {
|
|
|
1771
1772
|
type: 'TSImportType',
|
|
1772
1773
|
start: deserializeU32(pos),
|
|
1773
1774
|
end: deserializeU32(pos + 4),
|
|
1774
|
-
|
|
1775
|
-
|
|
1775
|
+
argument: deserializeTSType(pos + 8),
|
|
1776
|
+
options: deserializeOptionBoxTSImportAttributes(pos + 24),
|
|
1776
1777
|
qualifier: deserializeOptionTSTypeName(pos + 32),
|
|
1777
|
-
|
|
1778
|
-
|
|
1778
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
|
|
1779
|
+
isTypeOf: deserializeBool(pos + 56),
|
|
1779
1780
|
};
|
|
1780
1781
|
}
|
|
1781
1782
|
|
|
@@ -5515,11 +5516,6 @@ function deserializeBoxTSTypeParameter(pos) {
|
|
|
5515
5516
|
return deserializeTSTypeParameter(uint32[pos >> 2]);
|
|
5516
5517
|
}
|
|
5517
5518
|
|
|
5518
|
-
function deserializeOptionTSTypeName(pos) {
|
|
5519
|
-
if (uint8[pos] === 2) return null;
|
|
5520
|
-
return deserializeTSTypeName(pos);
|
|
5521
|
-
}
|
|
5522
|
-
|
|
5523
5519
|
function deserializeBoxTSImportAttributes(pos) {
|
|
5524
5520
|
return deserializeTSImportAttributes(uint32[pos >> 2]);
|
|
5525
5521
|
}
|
|
@@ -5529,6 +5525,11 @@ function deserializeOptionBoxTSImportAttributes(pos) {
|
|
|
5529
5525
|
return deserializeBoxTSImportAttributes(pos);
|
|
5530
5526
|
}
|
|
5531
5527
|
|
|
5528
|
+
function deserializeOptionTSTypeName(pos) {
|
|
5529
|
+
if (uint8[pos] === 2) return null;
|
|
5530
|
+
return deserializeTSTypeName(pos);
|
|
5531
|
+
}
|
|
5532
|
+
|
|
5532
5533
|
function deserializeVecTSImportAttribute(pos) {
|
|
5533
5534
|
const arr = [],
|
|
5534
5535
|
pos32 = pos >> 2,
|
package/deserialize-ts.js
CHANGED
|
@@ -941,13 +941,13 @@ function deserializeAccessorProperty(pos) {
|
|
|
941
941
|
}
|
|
942
942
|
|
|
943
943
|
function deserializeImportExpression(pos) {
|
|
944
|
-
const
|
|
944
|
+
const options = deserializeVecExpression(pos + 24);
|
|
945
945
|
return {
|
|
946
946
|
type: 'ImportExpression',
|
|
947
947
|
start: deserializeU32(pos),
|
|
948
948
|
end: deserializeU32(pos + 4),
|
|
949
949
|
source: deserializeExpression(pos + 8),
|
|
950
|
-
options:
|
|
950
|
+
options: options.length === 0 ? null : options[0],
|
|
951
951
|
};
|
|
952
952
|
}
|
|
953
953
|
|
|
@@ -1233,7 +1233,7 @@ function deserializeJSXNamespacedName(pos) {
|
|
|
1233
1233
|
start: deserializeU32(pos),
|
|
1234
1234
|
end: deserializeU32(pos + 4),
|
|
1235
1235
|
namespace: deserializeJSXIdentifier(pos + 8),
|
|
1236
|
-
|
|
1236
|
+
name: deserializeJSXIdentifier(pos + 32),
|
|
1237
1237
|
};
|
|
1238
1238
|
}
|
|
1239
1239
|
|
|
@@ -1307,6 +1307,7 @@ function deserializeJSXText(pos) {
|
|
|
1307
1307
|
start: deserializeU32(pos),
|
|
1308
1308
|
end: deserializeU32(pos + 4),
|
|
1309
1309
|
value: deserializeStr(pos + 8),
|
|
1310
|
+
raw: deserializeOptionStr(pos + 24),
|
|
1310
1311
|
};
|
|
1311
1312
|
}
|
|
1312
1313
|
|
|
@@ -1824,11 +1825,11 @@ function deserializeTSImportType(pos) {
|
|
|
1824
1825
|
type: 'TSImportType',
|
|
1825
1826
|
start: deserializeU32(pos),
|
|
1826
1827
|
end: deserializeU32(pos + 4),
|
|
1827
|
-
|
|
1828
|
-
|
|
1828
|
+
argument: deserializeTSType(pos + 8),
|
|
1829
|
+
options: deserializeOptionBoxTSImportAttributes(pos + 24),
|
|
1829
1830
|
qualifier: deserializeOptionTSTypeName(pos + 32),
|
|
1830
|
-
|
|
1831
|
-
|
|
1831
|
+
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
|
|
1832
|
+
isTypeOf: deserializeBool(pos + 56),
|
|
1832
1833
|
};
|
|
1833
1834
|
}
|
|
1834
1835
|
|
|
@@ -5568,11 +5569,6 @@ function deserializeBoxTSTypeParameter(pos) {
|
|
|
5568
5569
|
return deserializeTSTypeParameter(uint32[pos >> 2]);
|
|
5569
5570
|
}
|
|
5570
5571
|
|
|
5571
|
-
function deserializeOptionTSTypeName(pos) {
|
|
5572
|
-
if (uint8[pos] === 2) return null;
|
|
5573
|
-
return deserializeTSTypeName(pos);
|
|
5574
|
-
}
|
|
5575
|
-
|
|
5576
5572
|
function deserializeBoxTSImportAttributes(pos) {
|
|
5577
5573
|
return deserializeTSImportAttributes(uint32[pos >> 2]);
|
|
5578
5574
|
}
|
|
@@ -5582,6 +5578,11 @@ function deserializeOptionBoxTSImportAttributes(pos) {
|
|
|
5582
5578
|
return deserializeBoxTSImportAttributes(pos);
|
|
5583
5579
|
}
|
|
5584
5580
|
|
|
5581
|
+
function deserializeOptionTSTypeName(pos) {
|
|
5582
|
+
if (uint8[pos] === 2) return null;
|
|
5583
|
+
return deserializeTSTypeName(pos);
|
|
5584
|
+
}
|
|
5585
|
+
|
|
5585
5586
|
function deserializeVecTSImportAttribute(pos) {
|
|
5586
5587
|
const arr = [],
|
|
5587
5588
|
pos32 = pos >> 2,
|
package/index.d.ts
CHANGED
|
@@ -151,11 +151,11 @@ export interface ParserOptions {
|
|
|
151
151
|
*/
|
|
152
152
|
astType?: 'js' | 'ts'
|
|
153
153
|
/**
|
|
154
|
-
* Emit `ParenthesizedExpression` in AST.
|
|
154
|
+
* Emit `ParenthesizedExpression` and `TSParenthesizedType` in AST.
|
|
155
155
|
*
|
|
156
156
|
* If this option is true, parenthesized expressions are represented by
|
|
157
|
-
* (non-standard) `ParenthesizedExpression`
|
|
158
|
-
* containing the expression inside parentheses.
|
|
157
|
+
* (non-standard) `ParenthesizedExpression` and `TSParenthesizedType` nodes that
|
|
158
|
+
* have a single `expression` property containing the expression inside parentheses.
|
|
159
159
|
*
|
|
160
160
|
* @default true
|
|
161
161
|
*/
|
package/index.js
CHANGED
|
@@ -69,7 +69,10 @@ let buffer, encoder;
|
|
|
69
69
|
|
|
70
70
|
function parseSyncRaw(filename, sourceText, options) {
|
|
71
71
|
if (!rawTransferSupported()) {
|
|
72
|
-
throw new Error(
|
|
72
|
+
throw new Error(
|
|
73
|
+
'`experimentalRawTransfer` option is not supported on 32-bit or big-endian systems, ' +
|
|
74
|
+
'versions of NodeJS prior to v22.0.0, versions of Deno prior to v2.0.0, and other runtimes',
|
|
75
|
+
);
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
// Delete `experimentalRawTransfer` option
|
|
@@ -146,10 +149,45 @@ function createBuffer() {
|
|
|
146
149
|
let rawTransferIsSupported = null;
|
|
147
150
|
|
|
148
151
|
// Returns `true` if `experimentalRawTransfer` is option is supported.
|
|
149
|
-
//
|
|
152
|
+
//
|
|
153
|
+
// Raw transfer is only supported on 64-bit little-endian systems,
|
|
154
|
+
// and NodeJS >= v22.0.0 or Deno >= v2.0.0.
|
|
155
|
+
//
|
|
156
|
+
// Versions of NodeJS prior to v22.0.0 do not support creating an `ArrayBuffer` larger than 4 GiB.
|
|
157
|
+
// Bun (as at v1.2.4) also does not support creating an `ArrayBuffer` larger than 4 GiB.
|
|
158
|
+
// Support on Deno v1 is unknown and it's EOL, so treating Deno before v2.0.0 as unsupported.
|
|
150
159
|
function rawTransferSupported() {
|
|
151
|
-
if (rawTransferIsSupported === null)
|
|
160
|
+
if (rawTransferIsSupported === null) {
|
|
161
|
+
rawTransferIsSupported = rawTransferRuntimeSupported() && bindings.rawTransferSupported();
|
|
162
|
+
}
|
|
152
163
|
return rawTransferIsSupported;
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
module.exports.rawTransferSupported = rawTransferSupported;
|
|
167
|
+
|
|
168
|
+
// Checks copied from:
|
|
169
|
+
// https://github.com/unjs/std-env/blob/ab15595debec9e9115a9c1d31bc7597a8e71dbfd/src/runtimes.ts
|
|
170
|
+
// MIT license: https://github.com/unjs/std-env/blob/ab15595debec9e9115a9c1d31bc7597a8e71dbfd/LICENCE
|
|
171
|
+
function rawTransferRuntimeSupported() {
|
|
172
|
+
let global;
|
|
173
|
+
try {
|
|
174
|
+
global = globalThis;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const isBun = !!global.Bun || !!global.process?.versions?.bun;
|
|
180
|
+
if (isBun) return false;
|
|
181
|
+
|
|
182
|
+
const isDeno = !!global.Deno;
|
|
183
|
+
if (isDeno) {
|
|
184
|
+
const match = Deno.version?.deno?.match(/^(\d+)\./);
|
|
185
|
+
return !!match && match[1] * 1 >= 2;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const isNode = global.process?.release?.name === 'node';
|
|
189
|
+
if (!isNode) return false;
|
|
190
|
+
|
|
191
|
+
const match = process.version?.match(/^v(\d+)\./);
|
|
192
|
+
return !!match && match[1] * 1 >= 22;
|
|
193
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"browser": "browser.js",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=14.0.0"
|
|
8
|
+
},
|
|
6
9
|
"description": "Oxc Parser Node API",
|
|
7
10
|
"keywords": [
|
|
8
11
|
"oxc",
|
|
@@ -15,7 +18,7 @@
|
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
17
20
|
"url": "https://github.com/oxc-project/oxc.git",
|
|
18
|
-
"directory": "
|
|
21
|
+
"directory": "napi/parser"
|
|
19
22
|
},
|
|
20
23
|
"funding": {
|
|
21
24
|
"url": "https://github.com/sponsors/Boshen"
|
|
@@ -33,10 +36,11 @@
|
|
|
33
36
|
"access": "public"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"@oxc-project/types": "^0.
|
|
39
|
+
"@oxc-project/types": "^0.58.0"
|
|
37
40
|
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@codspeed/vitest-plugin": "^4.0.0",
|
|
43
|
+
"vitest": "3.0.7"
|
|
40
44
|
},
|
|
41
45
|
"napi": {
|
|
42
46
|
"binaryName": "parser",
|
|
@@ -61,15 +65,21 @@
|
|
|
61
65
|
"dtsHeaderFile": "header.js"
|
|
62
66
|
},
|
|
63
67
|
"optionalDependencies": {
|
|
64
|
-
"@oxc-parser/binding-win32-x64-msvc": "0.
|
|
65
|
-
"@oxc-parser/binding-win32-arm64-msvc": "0.
|
|
66
|
-
"@oxc-parser/binding-linux-x64-gnu": "0.
|
|
67
|
-
"@oxc-parser/binding-linux-x64-musl": "0.
|
|
68
|
-
"@oxc-parser/binding-linux-arm64-gnu": "0.
|
|
69
|
-
"@oxc-parser/binding-linux-arm64-musl": "0.
|
|
70
|
-
"@oxc-parser/binding-linux-arm-gnueabihf": "0.
|
|
71
|
-
"@oxc-parser/binding-darwin-x64": "0.
|
|
72
|
-
"@oxc-parser/binding-darwin-arm64": "0.
|
|
73
|
-
"@oxc-parser/binding-wasm32-wasi": "0.
|
|
68
|
+
"@oxc-parser/binding-win32-x64-msvc": "0.58.0",
|
|
69
|
+
"@oxc-parser/binding-win32-arm64-msvc": "0.58.0",
|
|
70
|
+
"@oxc-parser/binding-linux-x64-gnu": "0.58.0",
|
|
71
|
+
"@oxc-parser/binding-linux-x64-musl": "0.58.0",
|
|
72
|
+
"@oxc-parser/binding-linux-arm64-gnu": "0.58.0",
|
|
73
|
+
"@oxc-parser/binding-linux-arm64-musl": "0.58.0",
|
|
74
|
+
"@oxc-parser/binding-linux-arm-gnueabihf": "0.58.0",
|
|
75
|
+
"@oxc-parser/binding-darwin-x64": "0.58.0",
|
|
76
|
+
"@oxc-parser/binding-darwin-arm64": "0.58.0",
|
|
77
|
+
"@oxc-parser/binding-wasm32-wasi": "0.58.0"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build-dev": "napi build --no-dts-cache --platform --js bindings.js",
|
|
81
|
+
"build": "pnpm run build-dev --release",
|
|
82
|
+
"test": "vitest --typecheck run ./test && tsc",
|
|
83
|
+
"bench": "vitest bench --run ./bench.bench.mjs"
|
|
74
84
|
}
|
|
75
85
|
}
|