oxc-parser 0.75.0 → 0.76.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 +11 -0
- package/bindings.js +0 -3
- package/generated/deserialize/js.js +287 -287
- package/generated/deserialize/ts.js +300 -300
- package/generated/{deserialize/lazy.js → lazy/constructors.js} +206 -416
- package/generated/{deserialize/lazy-visit.js → lazy/walk.js} +1 -1
- package/index.d.ts +0 -68
- package/index.js +0 -1
- package/package.json +20 -20
- package/raw-transfer/lazy.js +7 -7
- package/raw-transfer/visitor.js +4 -4
- /package/generated/{deserialize/lazy-types.js → lazy/types.js} +0 -0
package/index.d.ts
CHANGED
|
@@ -113,14 +113,6 @@ export declare const enum ExportLocalNameKind {
|
|
|
113
113
|
None = 'None'
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
/**
|
|
117
|
-
* Get offset within a `Uint8Array` which is aligned on 4 GiB.
|
|
118
|
-
*
|
|
119
|
-
* Does not check that the offset is within bounds of `buffer`.
|
|
120
|
-
* To ensure it always is, provide a `Uint8Array` of at least 4 GiB size.
|
|
121
|
-
*/
|
|
122
|
-
export declare function getBufferOffset(buffer: Uint8Array): number
|
|
123
|
-
|
|
124
116
|
export interface ImportName {
|
|
125
117
|
kind: ImportNameKind
|
|
126
118
|
name?: string
|
|
@@ -144,38 +136,6 @@ export declare const enum ImportNameKind {
|
|
|
144
136
|
*/
|
|
145
137
|
export declare function parseAsync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
|
|
146
138
|
|
|
147
|
-
/**
|
|
148
|
-
* Parse AST into provided `Uint8Array` buffer, asynchronously.
|
|
149
|
-
*
|
|
150
|
-
* Note: This function can be slower than `parseSyncRaw` due to the overhead of spawning a thread.
|
|
151
|
-
*
|
|
152
|
-
* Source text must be written into the start of the buffer, and its length (in UTF-8 bytes)
|
|
153
|
-
* provided as `source_len`.
|
|
154
|
-
*
|
|
155
|
-
* This function will parse the source, and write the AST into the buffer, starting at the end.
|
|
156
|
-
*
|
|
157
|
-
* It also writes to the very end of the buffer the offset of `Program` within the buffer.
|
|
158
|
-
*
|
|
159
|
-
* Caller can deserialize data from the buffer on JS side.
|
|
160
|
-
*
|
|
161
|
-
* # SAFETY
|
|
162
|
-
*
|
|
163
|
-
* Caller must ensure:
|
|
164
|
-
* * Source text is written into start of the buffer.
|
|
165
|
-
* * Source text's UTF-8 byte length is `source_len`.
|
|
166
|
-
* * The 1st `source_len` bytes of the buffer comprises a valid UTF-8 string.
|
|
167
|
-
* * Contents of buffer must not be mutated by caller until the `AsyncTask` returned by this
|
|
168
|
-
* function resolves.
|
|
169
|
-
*
|
|
170
|
-
* If source text is originally a JS string on JS side, and converted to a buffer with
|
|
171
|
-
* `Buffer.from(str)` or `new TextEncoder().encode(str)`, this guarantees it's valid UTF-8.
|
|
172
|
-
*
|
|
173
|
-
* # Panics
|
|
174
|
-
*
|
|
175
|
-
* Panics if source text is too long, or AST takes more memory than is available in the buffer.
|
|
176
|
-
*/
|
|
177
|
-
export declare function parseAsyncRaw(filename: string, buffer: Uint8Array, sourceLen: number, options?: ParserOptions | undefined | null): Promise<unknown>
|
|
178
|
-
|
|
179
139
|
export interface ParserOptions {
|
|
180
140
|
/** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
|
|
181
141
|
lang?: 'js' | 'jsx' | 'ts' | 'tsx'
|
|
@@ -220,34 +180,6 @@ export interface ParserOptions {
|
|
|
220
180
|
/** Parse synchronously. */
|
|
221
181
|
export declare function parseSync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
|
222
182
|
|
|
223
|
-
/**
|
|
224
|
-
* Parse AST into provided `Uint8Array` buffer, synchronously.
|
|
225
|
-
*
|
|
226
|
-
* Source text must be written into the start of the buffer, and its length (in UTF-8 bytes)
|
|
227
|
-
* provided as `source_len`.
|
|
228
|
-
*
|
|
229
|
-
* This function will parse the source, and write the AST into the buffer, starting at the end.
|
|
230
|
-
*
|
|
231
|
-
* It also writes to the very end of the buffer the offset of `Program` within the buffer.
|
|
232
|
-
*
|
|
233
|
-
* Caller can deserialize data from the buffer on JS side.
|
|
234
|
-
*
|
|
235
|
-
* # SAFETY
|
|
236
|
-
*
|
|
237
|
-
* Caller must ensure:
|
|
238
|
-
* * Source text is written into start of the buffer.
|
|
239
|
-
* * Source text's UTF-8 byte length is `source_len`.
|
|
240
|
-
* * The 1st `source_len` bytes of the buffer comprises a valid UTF-8 string.
|
|
241
|
-
*
|
|
242
|
-
* If source text is originally a JS string on JS side, and converted to a buffer with
|
|
243
|
-
* `Buffer.from(str)` or `new TextEncoder().encode(str)`, this guarantees it's valid UTF-8.
|
|
244
|
-
*
|
|
245
|
-
* # Panics
|
|
246
|
-
*
|
|
247
|
-
* Panics if source text is too long, or AST takes more memory than is available in the buffer.
|
|
248
|
-
*/
|
|
249
|
-
export declare function parseSyncRaw(filename: string, buffer: Uint8Array, sourceLen: number, options?: ParserOptions | undefined | null): void
|
|
250
|
-
|
|
251
183
|
/** Returns `true` if raw transfer is supported on this platform. */
|
|
252
184
|
export declare function rawTransferSupported(): boolean
|
|
253
185
|
|
package/index.js
CHANGED
|
@@ -11,7 +11,6 @@ module.exports.ExportExportNameKind = bindings.ExportExportNameKind;
|
|
|
11
11
|
module.exports.ExportImportNameKind = bindings.ExportImportNameKind;
|
|
12
12
|
module.exports.ExportLocalNameKind = bindings.ExportLocalNameKind;
|
|
13
13
|
module.exports.ImportNameKind = bindings.ImportNameKind;
|
|
14
|
-
module.exports.parseWithoutReturn = bindings.parseWithoutReturn;
|
|
15
14
|
module.exports.Severity = bindings.Severity;
|
|
16
15
|
|
|
17
16
|
module.exports.parseSync = parseSync;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"browser": "wasm.mjs",
|
|
6
6
|
"engines": {
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"webcontainer-fallback.js",
|
|
34
34
|
"generated/deserialize/js.js",
|
|
35
35
|
"generated/deserialize/ts.js",
|
|
36
|
-
"generated/
|
|
37
|
-
"generated/
|
|
38
|
-
"generated/
|
|
36
|
+
"generated/lazy/constructors.js",
|
|
37
|
+
"generated/lazy/types.js",
|
|
38
|
+
"generated/lazy/walk.js",
|
|
39
39
|
"raw-transfer/common.js",
|
|
40
40
|
"raw-transfer/eager.js",
|
|
41
41
|
"raw-transfer/lazy.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@oxc-project/types": "^0.
|
|
52
|
+
"@oxc-project/types": "^0.76.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@codspeed/vitest-plugin": "^4.0.0",
|
|
@@ -89,21 +89,21 @@
|
|
|
89
89
|
"dtsHeaderFile": "header.js"
|
|
90
90
|
},
|
|
91
91
|
"optionalDependencies": {
|
|
92
|
-
"@oxc-parser/binding-win32-x64-msvc": "0.
|
|
93
|
-
"@oxc-parser/binding-win32-arm64-msvc": "0.
|
|
94
|
-
"@oxc-parser/binding-linux-x64-gnu": "0.
|
|
95
|
-
"@oxc-parser/binding-linux-x64-musl": "0.
|
|
96
|
-
"@oxc-parser/binding-freebsd-x64": "0.
|
|
97
|
-
"@oxc-parser/binding-linux-arm64-gnu": "0.
|
|
98
|
-
"@oxc-parser/binding-linux-arm64-musl": "0.
|
|
99
|
-
"@oxc-parser/binding-linux-arm-gnueabihf": "0.
|
|
100
|
-
"@oxc-parser/binding-linux-arm-musleabihf": "0.
|
|
101
|
-
"@oxc-parser/binding-linux-s390x-gnu": "0.
|
|
102
|
-
"@oxc-parser/binding-linux-riscv64-gnu": "0.
|
|
103
|
-
"@oxc-parser/binding-darwin-x64": "0.
|
|
104
|
-
"@oxc-parser/binding-darwin-arm64": "0.
|
|
105
|
-
"@oxc-parser/binding-android-arm64": "0.
|
|
106
|
-
"@oxc-parser/binding-wasm32-wasi": "0.
|
|
92
|
+
"@oxc-parser/binding-win32-x64-msvc": "0.76.0",
|
|
93
|
+
"@oxc-parser/binding-win32-arm64-msvc": "0.76.0",
|
|
94
|
+
"@oxc-parser/binding-linux-x64-gnu": "0.76.0",
|
|
95
|
+
"@oxc-parser/binding-linux-x64-musl": "0.76.0",
|
|
96
|
+
"@oxc-parser/binding-freebsd-x64": "0.76.0",
|
|
97
|
+
"@oxc-parser/binding-linux-arm64-gnu": "0.76.0",
|
|
98
|
+
"@oxc-parser/binding-linux-arm64-musl": "0.76.0",
|
|
99
|
+
"@oxc-parser/binding-linux-arm-gnueabihf": "0.76.0",
|
|
100
|
+
"@oxc-parser/binding-linux-arm-musleabihf": "0.76.0",
|
|
101
|
+
"@oxc-parser/binding-linux-s390x-gnu": "0.76.0",
|
|
102
|
+
"@oxc-parser/binding-linux-riscv64-gnu": "0.76.0",
|
|
103
|
+
"@oxc-parser/binding-darwin-x64": "0.76.0",
|
|
104
|
+
"@oxc-parser/binding-darwin-arm64": "0.76.0",
|
|
105
|
+
"@oxc-parser/binding-android-arm64": "0.76.0",
|
|
106
|
+
"@oxc-parser/binding-wasm32-wasi": "0.76.0"
|
|
107
107
|
},
|
|
108
108
|
"scripts": {
|
|
109
109
|
"build-dev": "napi build --platform --js bindings.js",
|
package/raw-transfer/lazy.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const { parseSyncRawImpl, parseAsyncRawImpl, returnBufferToCache } = require('./common.js'),
|
|
4
4
|
{ TOKEN } = require('./lazy-common.js'),
|
|
5
|
-
|
|
6
|
-
walkProgram = require('../generated/
|
|
5
|
+
{ RawTransferData } = require('../generated/lazy/constructors.js'),
|
|
6
|
+
walkProgram = require('../generated/lazy/walk.js'),
|
|
7
7
|
{ Visitor, getVisitorsArr } = require('./visitor.js');
|
|
8
8
|
|
|
9
9
|
module.exports = { parseSyncLazy, parseAsyncLazy, Visitor };
|
|
@@ -104,7 +104,10 @@ function construct(buffer, sourceText, sourceLen) {
|
|
|
104
104
|
bufferRecycleRegistry.register(ast, buffer, ast);
|
|
105
105
|
|
|
106
106
|
// Get root data class instance
|
|
107
|
-
|
|
107
|
+
// (2 * 1024 * 1024 * 1024 - 16) >> 2
|
|
108
|
+
const metadataPos32 = 536870908;
|
|
109
|
+
const rawDataPos = buffer.uint32[metadataPos32];
|
|
110
|
+
const data = new RawTransferData(rawDataPos, ast);
|
|
108
111
|
|
|
109
112
|
return {
|
|
110
113
|
get program() {
|
|
@@ -121,10 +124,7 @@ function construct(buffer, sourceText, sourceLen) {
|
|
|
121
124
|
},
|
|
122
125
|
dispose: dispose.bind(null, ast),
|
|
123
126
|
visit(visitor) {
|
|
124
|
-
|
|
125
|
-
const metadataPos32 = 536870908;
|
|
126
|
-
const pos = buffer.uint32[metadataPos32];
|
|
127
|
-
walkProgram(pos, ast, getVisitorsArr(visitor));
|
|
127
|
+
walkProgram(rawDataPos, ast, getVisitorsArr(visitor));
|
|
128
128
|
},
|
|
129
129
|
};
|
|
130
130
|
}
|
package/raw-transfer/visitor.js
CHANGED
|
@@ -4,7 +4,7 @@ const {
|
|
|
4
4
|
NODE_TYPE_IDS_MAP,
|
|
5
5
|
NODE_TYPES_COUNT,
|
|
6
6
|
LEAF_NODE_TYPES_COUNT,
|
|
7
|
-
} = require('../generated/
|
|
7
|
+
} = require('../generated/lazy/types.js');
|
|
8
8
|
|
|
9
9
|
// Getter for private `#visitorsArr` property of `Visitor` class. Initialized in class body below.
|
|
10
10
|
let getVisitorsArr;
|
|
@@ -64,7 +64,7 @@ module.exports = { Visitor, getVisitorsArr };
|
|
|
64
64
|
*/
|
|
65
65
|
function createVisitorsArr(visitor) {
|
|
66
66
|
if (visitor === null || typeof visitor !== 'object') {
|
|
67
|
-
throw new Error('`
|
|
67
|
+
throw new Error('`visitor` must be an object');
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// Create empty visitors array
|
|
@@ -77,14 +77,14 @@ function createVisitorsArr(visitor) {
|
|
|
77
77
|
for (let name of Object.keys(visitor)) {
|
|
78
78
|
const visitFn = visitor[name];
|
|
79
79
|
if (typeof visitFn !== 'function') {
|
|
80
|
-
throw new Error(`'${name}' property of \`
|
|
80
|
+
throw new Error(`'${name}' property of \`visitor\` object is not a function`);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const isExit = name.endsWith(':exit');
|
|
84
84
|
if (isExit) name = name.slice(0, -5);
|
|
85
85
|
|
|
86
86
|
const typeId = NODE_TYPE_IDS_MAP.get(name);
|
|
87
|
-
if (typeId === void 0) throw new Error(`Unknown node type '${name}' in \`
|
|
87
|
+
if (typeId === void 0) throw new Error(`Unknown node type '${name}' in \`visitor\` object`);
|
|
88
88
|
|
|
89
89
|
if (typeId < LEAF_NODE_TYPES_COUNT) {
|
|
90
90
|
// Leaf node. Store just 1 function.
|
|
File without changes
|