oxc-parser 0.110.0 → 0.112.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 +6 -4
- package/package.json +34 -30
- package/src-js/bindings.js +52 -52
- package/src-js/generated/constants.js +3 -0
- package/src-js/generated/deserialize/js.js +380 -500
- package/src-js/generated/deserialize/js_range.js +684 -722
- package/src-js/generated/deserialize/ts.js +457 -585
- package/src-js/generated/deserialize/ts_range.js +691 -726
- package/src-js/generated/lazy/constructors.js +3 -5
- package/src-js/generated/lazy/walk.js +3 -6
- package/src-js/generated/visit/walk.js +1 -3
- package/src-js/index.d.ts +20 -3
- package/src-js/visit/visitor.js +3 -5
|
@@ -11274,13 +11274,11 @@ const DebugTSImportEqualsDeclaration = class TSImportEqualsDeclaration {};
|
|
|
11274
11274
|
function constructTSModuleReference(pos, ast) {
|
|
11275
11275
|
switch (ast.buffer[pos]) {
|
|
11276
11276
|
case 0:
|
|
11277
|
-
return
|
|
11277
|
+
return constructBoxTSExternalModuleReference(pos + 8, ast);
|
|
11278
11278
|
case 1:
|
|
11279
|
-
return
|
|
11279
|
+
return constructBoxIdentifierReference(pos + 8, ast);
|
|
11280
11280
|
case 2:
|
|
11281
|
-
return
|
|
11282
|
-
case 3:
|
|
11283
|
-
return constructBoxTSExternalModuleReference(pos + 8, ast);
|
|
11281
|
+
return constructBoxTSQualifiedName(pos + 8, ast);
|
|
11284
11282
|
default:
|
|
11285
11283
|
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleReference`);
|
|
11286
11284
|
}
|
|
@@ -4572,16 +4572,13 @@ function walkTSImportEqualsDeclaration(pos, ast, visitors) {
|
|
|
4572
4572
|
function walkTSModuleReference(pos, ast, visitors) {
|
|
4573
4573
|
switch (ast.buffer[pos]) {
|
|
4574
4574
|
case 0:
|
|
4575
|
-
|
|
4575
|
+
walkBoxTSExternalModuleReference(pos + 8, ast, visitors);
|
|
4576
4576
|
return;
|
|
4577
4577
|
case 1:
|
|
4578
|
-
|
|
4578
|
+
walkBoxIdentifierReference(pos + 8, ast, visitors);
|
|
4579
4579
|
return;
|
|
4580
4580
|
case 2:
|
|
4581
|
-
|
|
4582
|
-
return;
|
|
4583
|
-
case 3:
|
|
4584
|
-
walkBoxTSExternalModuleReference(pos + 8, ast, visitors);
|
|
4581
|
+
walkBoxTSQualifiedName(pos + 8, ast, visitors);
|
|
4585
4582
|
return;
|
|
4586
4583
|
default:
|
|
4587
4584
|
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleReference`);
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
export { walkProgram };
|
|
5
5
|
|
|
6
|
-
const { isArray } = Array;
|
|
7
|
-
|
|
8
6
|
function walkNode(node, visitors) {
|
|
9
7
|
if (node == null) return;
|
|
10
|
-
if (isArray(node)) {
|
|
8
|
+
if (Array.isArray(node)) {
|
|
11
9
|
let len = node.length;
|
|
12
10
|
for (let i = 0; i < len; i++) walkNode(node[i], visitors);
|
|
13
11
|
} else
|
package/src-js/index.d.ts
CHANGED
|
@@ -142,9 +142,17 @@ export declare const enum ImportNameKind {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/**
|
|
145
|
-
* Parse asynchronously.
|
|
145
|
+
* Parse JS/TS source asynchronously on a separate thread.
|
|
146
146
|
*
|
|
147
|
-
* Note
|
|
147
|
+
* Note that not all of the workload can happen on a separate thread.
|
|
148
|
+
* Parsing on Rust side does happen in a separate thread, but deserialization of the AST to JS objects
|
|
149
|
+
* has to happen on current thread. This synchronous deserialization work typically outweighs
|
|
150
|
+
* the asynchronous parsing by a factor of between 3 and 20.
|
|
151
|
+
*
|
|
152
|
+
* i.e. the majority of the workload cannot be parallelized by using this method.
|
|
153
|
+
*
|
|
154
|
+
* Generally `parseSync` is preferable to use as it does not have the overhead of spawning a thread.
|
|
155
|
+
* If you need to parallelize parsing multiple files, it is recommended to use worker threads.
|
|
148
156
|
*/
|
|
149
157
|
export declare function parse(filename: string, sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
|
|
150
158
|
|
|
@@ -189,7 +197,16 @@ export interface ParserOptions {
|
|
|
189
197
|
showSemanticErrors?: boolean
|
|
190
198
|
}
|
|
191
199
|
|
|
192
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* Parse JS/TS source synchronously on current thread.
|
|
202
|
+
*
|
|
203
|
+
* This is generally preferable over `parse` (async) as it does not have the overhead
|
|
204
|
+
* of spawning a thread, and the majority of the workload cannot be parallelized anyway
|
|
205
|
+
* (see `parse` documentation for details).
|
|
206
|
+
*
|
|
207
|
+
* If you need to parallelize parsing multiple files, it is recommended to use worker threads
|
|
208
|
+
* with `parseSync` rather than using `parse`.
|
|
209
|
+
*/
|
|
193
210
|
export declare function parseSync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
|
194
211
|
|
|
195
212
|
/** Returns `true` if raw transfer is supported on this platform. */
|
package/src-js/visit/visitor.js
CHANGED
|
@@ -78,8 +78,6 @@ import {
|
|
|
78
78
|
NODE_TYPES_COUNT,
|
|
79
79
|
} from "../generated/visit/type_ids.js";
|
|
80
80
|
|
|
81
|
-
const { isArray } = Array;
|
|
82
|
-
|
|
83
81
|
// Compiled visitor used for visiting each file.
|
|
84
82
|
// Same array is reused for each file.
|
|
85
83
|
//
|
|
@@ -225,7 +223,7 @@ export function addVisitorToCompiled(visitor) {
|
|
|
225
223
|
// Leaf node - store just 1 function, not enter+exit pair
|
|
226
224
|
if (existing === null) {
|
|
227
225
|
compiledVisitor[typeId] = visitFn;
|
|
228
|
-
} else if (isArray(existing)) {
|
|
226
|
+
} else if (Array.isArray(existing)) {
|
|
229
227
|
if (isExit) {
|
|
230
228
|
existing.push(visitFn);
|
|
231
229
|
} else {
|
|
@@ -256,7 +254,7 @@ export function addVisitorToCompiled(visitor) {
|
|
|
256
254
|
const { exit } = existing;
|
|
257
255
|
if (exit === null) {
|
|
258
256
|
existing.exit = visitFn;
|
|
259
|
-
} else if (isArray(exit)) {
|
|
257
|
+
} else if (Array.isArray(exit)) {
|
|
260
258
|
exit.push(visitFn);
|
|
261
259
|
} else {
|
|
262
260
|
existing.exit = createVisitFnArray(exit, visitFn);
|
|
@@ -266,7 +264,7 @@ export function addVisitorToCompiled(visitor) {
|
|
|
266
264
|
const { enter } = existing;
|
|
267
265
|
if (enter === null) {
|
|
268
266
|
existing.enter = visitFn;
|
|
269
|
-
} else if (isArray(enter)) {
|
|
267
|
+
} else if (Array.isArray(enter)) {
|
|
270
268
|
enter.push(visitFn);
|
|
271
269
|
} else {
|
|
272
270
|
existing.enter = createVisitFnArray(enter, visitFn);
|