oxc-parser 0.87.0 → 0.89.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/bindings.mjs +579 -0
- package/generated/constants.mjs +9 -0
- package/generated/deserialize/{js.js → js.mjs} +1 -5
- package/generated/deserialize/{ts.js → ts.mjs} +1 -5
- package/generated/lazy/{constructors.js → constructors.mjs} +206 -415
- package/generated/lazy/{types.js → types.mjs} +3 -11
- package/generated/lazy/{walk.js → walk.mjs} +148 -150
- package/{index.js → index.mjs} +18 -22
- package/package.json +35 -36
- package/raw-transfer/{common.js → common.mjs} +8 -16
- package/raw-transfer/{eager.js → eager.mjs} +7 -8
- package/raw-transfer/{lazy-common.js → lazy-common.mjs} +2 -6
- package/raw-transfer/{lazy.js → lazy.mjs} +9 -12
- package/raw-transfer/{node-array.js → node-array.mjs} +2 -6
- package/raw-transfer/{supported.js → supported.mjs} +2 -6
- package/raw-transfer/{visitor.js → visitor.mjs} +5 -11
- package/bindings.js +0 -412
- package/generated/constants.js +0 -18
- package/wrap.cjs +0 -58
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{ Visitor, getVisitorsArr } = require('./visitor.js');
|
|
9
|
-
|
|
10
|
-
module.exports = { parseSyncLazy, parseAsyncLazy, Visitor };
|
|
1
|
+
import { DATA_POINTER_POS_32, PROGRAM_OFFSET } from '../generated/constants.mjs';
|
|
2
|
+
import { RawTransferData } from '../generated/lazy/constructors.mjs';
|
|
3
|
+
import { walkProgram } from '../generated/lazy/walk.mjs';
|
|
4
|
+
import { parseAsyncRawImpl, parseSyncRawImpl, returnBufferToCache } from './common.mjs';
|
|
5
|
+
import { TOKEN } from './lazy-common.mjs';
|
|
6
|
+
import { getVisitorsArr } from './visitor.mjs';
|
|
7
|
+
export { Visitor } from './visitor.mjs';
|
|
11
8
|
|
|
12
9
|
/**
|
|
13
10
|
* Parse JS/TS source synchronously on current thread.
|
|
@@ -32,7 +29,7 @@ module.exports = { parseSyncLazy, parseAsyncLazy, Visitor };
|
|
|
32
29
|
* @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`,
|
|
33
30
|
* and `dispose` and `visit` methods
|
|
34
31
|
*/
|
|
35
|
-
function parseSyncLazy(filename, sourceText, options) {
|
|
32
|
+
export function parseSyncLazy(filename, sourceText, options) {
|
|
36
33
|
let _;
|
|
37
34
|
({ experimentalLazy: _, ...options } = options);
|
|
38
35
|
return parseSyncRawImpl(filename, sourceText, options, construct);
|
|
@@ -65,7 +62,7 @@ function parseSyncLazy(filename, sourceText, options) {
|
|
|
65
62
|
* @returns {Object} - Object with property getters for `program`, `module`, `comments`, and `errors`,
|
|
66
63
|
* and `dispose` and `visit` methods
|
|
67
64
|
*/
|
|
68
|
-
function parseAsyncLazy(filename, sourceText, options) {
|
|
65
|
+
export function parseAsyncLazy(filename, sourceText, options) {
|
|
69
66
|
let _;
|
|
70
67
|
({ experimentalLazy: _, ...options } = options);
|
|
71
68
|
return parseAsyncRawImpl(filename, sourceText, options, construct);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { TOKEN, constructorError } = require('./lazy-common.js');
|
|
1
|
+
import { constructorError, TOKEN } from './lazy-common.mjs';
|
|
4
2
|
|
|
5
3
|
// Internal symbol to get `NodeArray` from a proxy wrapping a `NodeArray`.
|
|
6
4
|
//
|
|
@@ -23,7 +21,7 @@ let getInternalFromProxy, getLength, getElement;
|
|
|
23
21
|
* TODO: Other methods could maybe be more optimal, avoiding going via proxy multiple times
|
|
24
22
|
* e.g. `some`, `indexOf`.
|
|
25
23
|
*/
|
|
26
|
-
class NodeArray extends Array {
|
|
24
|
+
export class NodeArray extends Array {
|
|
27
25
|
#internal;
|
|
28
26
|
|
|
29
27
|
/**
|
|
@@ -153,8 +151,6 @@ class NodeArray extends Array {
|
|
|
153
151
|
|
|
154
152
|
NodeArray.prototype[Symbol.iterator] = NodeArray.prototype.values;
|
|
155
153
|
|
|
156
|
-
module.exports = NodeArray;
|
|
157
|
-
|
|
158
154
|
/**
|
|
159
155
|
* Iterator over values of a `NodeArray`.
|
|
160
156
|
* Returned by `values` method, and also used as iterator for `for (const node of nodeArray) {}`.
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const rawTransferSupportedBinding = require('../bindings.js').rawTransferSupported;
|
|
4
|
-
|
|
5
|
-
module.exports = rawTransferSupported;
|
|
1
|
+
import { rawTransferSupported as rawTransferSupportedBinding } from '../bindings.mjs';
|
|
6
2
|
|
|
7
3
|
let rawTransferIsSupported = null;
|
|
8
4
|
|
|
@@ -21,7 +17,7 @@ let rawTransferIsSupported = null;
|
|
|
21
17
|
*
|
|
22
18
|
* @returns {boolean} - `true` if raw transfer is supported on this platform
|
|
23
19
|
*/
|
|
24
|
-
function rawTransferSupported() {
|
|
20
|
+
export function rawTransferSupported() {
|
|
25
21
|
if (rawTransferIsSupported === null) {
|
|
26
22
|
rawTransferIsSupported = rawTransferRuntimeSupported() && rawTransferSupportedBinding();
|
|
27
23
|
}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
NODE_TYPE_IDS_MAP,
|
|
5
|
-
NODE_TYPES_COUNT,
|
|
6
|
-
LEAF_NODE_TYPES_COUNT,
|
|
7
|
-
} = require('../generated/lazy/types.js');
|
|
1
|
+
import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../generated/lazy/types.mjs';
|
|
8
2
|
|
|
9
3
|
// Getter for private `#visitorsArr` property of `Visitor` class. Initialized in class body below.
|
|
10
|
-
let
|
|
4
|
+
let getVisitorsArrTemp;
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
7
|
* Visitor class, used to visit an AST.
|
|
14
8
|
*/
|
|
15
|
-
class Visitor {
|
|
9
|
+
export class Visitor {
|
|
16
10
|
#visitorsArr;
|
|
17
11
|
|
|
18
12
|
/**
|
|
@@ -43,11 +37,11 @@ class Visitor {
|
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
static {
|
|
46
|
-
|
|
40
|
+
getVisitorsArrTemp = visitor => visitor.#visitorsArr;
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
|
|
44
|
+
export const getVisitorsArr = getVisitorsArrTemp;
|
|
51
45
|
|
|
52
46
|
/**
|
|
53
47
|
* Create array of visitors, keyed by node type ID.
|
package/bindings.js
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
// prettier-ignore
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
// @ts-nocheck
|
|
4
|
-
/* auto-generated by NAPI-RS */
|
|
5
|
-
|
|
6
|
-
const { createRequire } = require('node:module')
|
|
7
|
-
require = createRequire(__filename)
|
|
8
|
-
|
|
9
|
-
const { readFileSync } = require('node:fs')
|
|
10
|
-
let nativeBinding = null
|
|
11
|
-
const loadErrors = []
|
|
12
|
-
|
|
13
|
-
const isMusl = () => {
|
|
14
|
-
let musl = false
|
|
15
|
-
if (process.platform === 'linux') {
|
|
16
|
-
musl = isMuslFromFilesystem()
|
|
17
|
-
if (musl === null) {
|
|
18
|
-
musl = isMuslFromReport()
|
|
19
|
-
}
|
|
20
|
-
if (musl === null) {
|
|
21
|
-
musl = isMuslFromChildProcess()
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return musl
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
-
|
|
29
|
-
const isMuslFromFilesystem = () => {
|
|
30
|
-
try {
|
|
31
|
-
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
-
} catch {
|
|
33
|
-
return null
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const isMuslFromReport = () => {
|
|
38
|
-
let report = null
|
|
39
|
-
if (typeof process.report?.getReport === 'function') {
|
|
40
|
-
process.report.excludeNetwork = true
|
|
41
|
-
report = process.report.getReport()
|
|
42
|
-
}
|
|
43
|
-
if (!report) {
|
|
44
|
-
return null
|
|
45
|
-
}
|
|
46
|
-
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
-
return false
|
|
48
|
-
}
|
|
49
|
-
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
-
if (report.sharedObjects.some(isFileMusl)) {
|
|
51
|
-
return true
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const isMuslFromChildProcess = () => {
|
|
58
|
-
try {
|
|
59
|
-
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
-
} catch (e) {
|
|
61
|
-
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
-
return false
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function requireNative() {
|
|
67
|
-
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
-
try {
|
|
69
|
-
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
loadErrors.push(err)
|
|
72
|
-
}
|
|
73
|
-
} else if (process.platform === 'android') {
|
|
74
|
-
if (process.arch === 'arm64') {
|
|
75
|
-
try {
|
|
76
|
-
return require('./parser.android-arm64.node')
|
|
77
|
-
} catch (e) {
|
|
78
|
-
loadErrors.push(e)
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
return require('@oxc-parser/binding-android-arm64')
|
|
82
|
-
} catch (e) {
|
|
83
|
-
loadErrors.push(e)
|
|
84
|
-
}
|
|
85
|
-
} else if (process.arch === 'arm') {
|
|
86
|
-
try {
|
|
87
|
-
return require('./parser.android-arm-eabi.node')
|
|
88
|
-
} catch (e) {
|
|
89
|
-
loadErrors.push(e)
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
return require('@oxc-parser/binding-android-arm-eabi')
|
|
93
|
-
} catch (e) {
|
|
94
|
-
loadErrors.push(e)
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
98
|
-
}
|
|
99
|
-
} else if (process.platform === 'win32') {
|
|
100
|
-
if (process.arch === 'x64') {
|
|
101
|
-
try {
|
|
102
|
-
return require('./parser.win32-x64-msvc.node')
|
|
103
|
-
} catch (e) {
|
|
104
|
-
loadErrors.push(e)
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
return require('@oxc-parser/binding-win32-x64-msvc')
|
|
108
|
-
} catch (e) {
|
|
109
|
-
loadErrors.push(e)
|
|
110
|
-
}
|
|
111
|
-
} else if (process.arch === 'ia32') {
|
|
112
|
-
try {
|
|
113
|
-
return require('./parser.win32-ia32-msvc.node')
|
|
114
|
-
} catch (e) {
|
|
115
|
-
loadErrors.push(e)
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
return require('@oxc-parser/binding-win32-ia32-msvc')
|
|
119
|
-
} catch (e) {
|
|
120
|
-
loadErrors.push(e)
|
|
121
|
-
}
|
|
122
|
-
} else if (process.arch === 'arm64') {
|
|
123
|
-
try {
|
|
124
|
-
return require('./parser.win32-arm64-msvc.node')
|
|
125
|
-
} catch (e) {
|
|
126
|
-
loadErrors.push(e)
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
return require('@oxc-parser/binding-win32-arm64-msvc')
|
|
130
|
-
} catch (e) {
|
|
131
|
-
loadErrors.push(e)
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
135
|
-
}
|
|
136
|
-
} else if (process.platform === 'darwin') {
|
|
137
|
-
try {
|
|
138
|
-
return require('./parser.darwin-universal.node')
|
|
139
|
-
} catch (e) {
|
|
140
|
-
loadErrors.push(e)
|
|
141
|
-
}
|
|
142
|
-
try {
|
|
143
|
-
return require('@oxc-parser/binding-darwin-universal')
|
|
144
|
-
} catch (e) {
|
|
145
|
-
loadErrors.push(e)
|
|
146
|
-
}
|
|
147
|
-
if (process.arch === 'x64') {
|
|
148
|
-
try {
|
|
149
|
-
return require('./parser.darwin-x64.node')
|
|
150
|
-
} catch (e) {
|
|
151
|
-
loadErrors.push(e)
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
return require('@oxc-parser/binding-darwin-x64')
|
|
155
|
-
} catch (e) {
|
|
156
|
-
loadErrors.push(e)
|
|
157
|
-
}
|
|
158
|
-
} else if (process.arch === 'arm64') {
|
|
159
|
-
try {
|
|
160
|
-
return require('./parser.darwin-arm64.node')
|
|
161
|
-
} catch (e) {
|
|
162
|
-
loadErrors.push(e)
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
return require('@oxc-parser/binding-darwin-arm64')
|
|
166
|
-
} catch (e) {
|
|
167
|
-
loadErrors.push(e)
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
171
|
-
}
|
|
172
|
-
} else if (process.platform === 'freebsd') {
|
|
173
|
-
if (process.arch === 'x64') {
|
|
174
|
-
try {
|
|
175
|
-
return require('./parser.freebsd-x64.node')
|
|
176
|
-
} catch (e) {
|
|
177
|
-
loadErrors.push(e)
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
return require('@oxc-parser/binding-freebsd-x64')
|
|
181
|
-
} catch (e) {
|
|
182
|
-
loadErrors.push(e)
|
|
183
|
-
}
|
|
184
|
-
} else if (process.arch === 'arm64') {
|
|
185
|
-
try {
|
|
186
|
-
return require('./parser.freebsd-arm64.node')
|
|
187
|
-
} catch (e) {
|
|
188
|
-
loadErrors.push(e)
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
return require('@oxc-parser/binding-freebsd-arm64')
|
|
192
|
-
} catch (e) {
|
|
193
|
-
loadErrors.push(e)
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
197
|
-
}
|
|
198
|
-
} else if (process.platform === 'linux') {
|
|
199
|
-
if (process.arch === 'x64') {
|
|
200
|
-
if (isMusl()) {
|
|
201
|
-
try {
|
|
202
|
-
return require('./parser.linux-x64-musl.node')
|
|
203
|
-
} catch (e) {
|
|
204
|
-
loadErrors.push(e)
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
return require('@oxc-parser/binding-linux-x64-musl')
|
|
208
|
-
} catch (e) {
|
|
209
|
-
loadErrors.push(e)
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
try {
|
|
213
|
-
return require('./parser.linux-x64-gnu.node')
|
|
214
|
-
} catch (e) {
|
|
215
|
-
loadErrors.push(e)
|
|
216
|
-
}
|
|
217
|
-
try {
|
|
218
|
-
return require('@oxc-parser/binding-linux-x64-gnu')
|
|
219
|
-
} catch (e) {
|
|
220
|
-
loadErrors.push(e)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
} else if (process.arch === 'arm64') {
|
|
224
|
-
if (isMusl()) {
|
|
225
|
-
try {
|
|
226
|
-
return require('./parser.linux-arm64-musl.node')
|
|
227
|
-
} catch (e) {
|
|
228
|
-
loadErrors.push(e)
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
return require('@oxc-parser/binding-linux-arm64-musl')
|
|
232
|
-
} catch (e) {
|
|
233
|
-
loadErrors.push(e)
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
try {
|
|
237
|
-
return require('./parser.linux-arm64-gnu.node')
|
|
238
|
-
} catch (e) {
|
|
239
|
-
loadErrors.push(e)
|
|
240
|
-
}
|
|
241
|
-
try {
|
|
242
|
-
return require('@oxc-parser/binding-linux-arm64-gnu')
|
|
243
|
-
} catch (e) {
|
|
244
|
-
loadErrors.push(e)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
} else if (process.arch === 'arm') {
|
|
248
|
-
if (isMusl()) {
|
|
249
|
-
try {
|
|
250
|
-
return require('./parser.linux-arm-musleabihf.node')
|
|
251
|
-
} catch (e) {
|
|
252
|
-
loadErrors.push(e)
|
|
253
|
-
}
|
|
254
|
-
try {
|
|
255
|
-
return require('@oxc-parser/binding-linux-arm-musleabihf')
|
|
256
|
-
} catch (e) {
|
|
257
|
-
loadErrors.push(e)
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
try {
|
|
261
|
-
return require('./parser.linux-arm-gnueabihf.node')
|
|
262
|
-
} catch (e) {
|
|
263
|
-
loadErrors.push(e)
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
return require('@oxc-parser/binding-linux-arm-gnueabihf')
|
|
267
|
-
} catch (e) {
|
|
268
|
-
loadErrors.push(e)
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
} else if (process.arch === 'riscv64') {
|
|
272
|
-
if (isMusl()) {
|
|
273
|
-
try {
|
|
274
|
-
return require('./parser.linux-riscv64-musl.node')
|
|
275
|
-
} catch (e) {
|
|
276
|
-
loadErrors.push(e)
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
return require('@oxc-parser/binding-linux-riscv64-musl')
|
|
280
|
-
} catch (e) {
|
|
281
|
-
loadErrors.push(e)
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
try {
|
|
285
|
-
return require('./parser.linux-riscv64-gnu.node')
|
|
286
|
-
} catch (e) {
|
|
287
|
-
loadErrors.push(e)
|
|
288
|
-
}
|
|
289
|
-
try {
|
|
290
|
-
return require('@oxc-parser/binding-linux-riscv64-gnu')
|
|
291
|
-
} catch (e) {
|
|
292
|
-
loadErrors.push(e)
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
} else if (process.arch === 'ppc64') {
|
|
296
|
-
try {
|
|
297
|
-
return require('./parser.linux-ppc64-gnu.node')
|
|
298
|
-
} catch (e) {
|
|
299
|
-
loadErrors.push(e)
|
|
300
|
-
}
|
|
301
|
-
try {
|
|
302
|
-
return require('@oxc-parser/binding-linux-ppc64-gnu')
|
|
303
|
-
} catch (e) {
|
|
304
|
-
loadErrors.push(e)
|
|
305
|
-
}
|
|
306
|
-
} else if (process.arch === 's390x') {
|
|
307
|
-
try {
|
|
308
|
-
return require('./parser.linux-s390x-gnu.node')
|
|
309
|
-
} catch (e) {
|
|
310
|
-
loadErrors.push(e)
|
|
311
|
-
}
|
|
312
|
-
try {
|
|
313
|
-
return require('@oxc-parser/binding-linux-s390x-gnu')
|
|
314
|
-
} catch (e) {
|
|
315
|
-
loadErrors.push(e)
|
|
316
|
-
}
|
|
317
|
-
} else {
|
|
318
|
-
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
319
|
-
}
|
|
320
|
-
} else if (process.platform === 'openharmony') {
|
|
321
|
-
if (process.arch === 'arm64') {
|
|
322
|
-
try {
|
|
323
|
-
return require('./parser.linux-arm64-ohos.node')
|
|
324
|
-
} catch (e) {
|
|
325
|
-
loadErrors.push(e)
|
|
326
|
-
}
|
|
327
|
-
try {
|
|
328
|
-
return require('@oxc-parser/binding-linux-arm64-ohos')
|
|
329
|
-
} catch (e) {
|
|
330
|
-
loadErrors.push(e)
|
|
331
|
-
}
|
|
332
|
-
} else if (process.arch === 'x64') {
|
|
333
|
-
try {
|
|
334
|
-
return require('./parser.linux-x64-ohos.node')
|
|
335
|
-
} catch (e) {
|
|
336
|
-
loadErrors.push(e)
|
|
337
|
-
}
|
|
338
|
-
try {
|
|
339
|
-
return require('@oxc-parser/binding-linux-x64-ohos')
|
|
340
|
-
} catch (e) {
|
|
341
|
-
loadErrors.push(e)
|
|
342
|
-
}
|
|
343
|
-
} else if (process.arch === 'arm') {
|
|
344
|
-
try {
|
|
345
|
-
return require('./parser.linux-arm-ohos.node')
|
|
346
|
-
} catch (e) {
|
|
347
|
-
loadErrors.push(e)
|
|
348
|
-
}
|
|
349
|
-
try {
|
|
350
|
-
return require('@oxc-parser/binding-linux-arm-ohos')
|
|
351
|
-
} catch (e) {
|
|
352
|
-
loadErrors.push(e)
|
|
353
|
-
}
|
|
354
|
-
} else {
|
|
355
|
-
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
356
|
-
}
|
|
357
|
-
} else {
|
|
358
|
-
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
nativeBinding = requireNative()
|
|
363
|
-
|
|
364
|
-
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
365
|
-
try {
|
|
366
|
-
nativeBinding = require('./parser.wasi.cjs')
|
|
367
|
-
} catch (err) {
|
|
368
|
-
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
369
|
-
loadErrors.push(err)
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (!nativeBinding) {
|
|
373
|
-
try {
|
|
374
|
-
nativeBinding = require('@oxc-parser/binding-wasm32-wasi')
|
|
375
|
-
} catch (err) {
|
|
376
|
-
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
377
|
-
loadErrors.push(err)
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
|
384
|
-
try {
|
|
385
|
-
nativeBinding = require('./webcontainer-fallback.js');
|
|
386
|
-
} catch (err) {
|
|
387
|
-
loadErrors.push(err)
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (!nativeBinding) {
|
|
392
|
-
if (loadErrors.length > 0) {
|
|
393
|
-
throw new Error(
|
|
394
|
-
`Cannot find native binding. ` +
|
|
395
|
-
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
396
|
-
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
397
|
-
{ cause: loadErrors }
|
|
398
|
-
)
|
|
399
|
-
}
|
|
400
|
-
throw new Error(`Failed to load native binding`)
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
module.exports = nativeBinding
|
|
404
|
-
module.exports.Severity = nativeBinding.Severity
|
|
405
|
-
module.exports.ParseResult = nativeBinding.ParseResult
|
|
406
|
-
module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind
|
|
407
|
-
module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind
|
|
408
|
-
module.exports.ExportLocalNameKind = nativeBinding.ExportLocalNameKind
|
|
409
|
-
module.exports.ImportNameKind = nativeBinding.ImportNameKind
|
|
410
|
-
module.exports.parseAsync = nativeBinding.parseAsync
|
|
411
|
-
module.exports.parseSync = nativeBinding.parseSync
|
|
412
|
-
module.exports.rawTransferSupported = nativeBinding.rawTransferSupported
|
package/generated/constants.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
|
2
|
-
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.
|
|
3
|
-
|
|
4
|
-
const BUFFER_SIZE = 2147483616,
|
|
5
|
-
BUFFER_ALIGN = 4294967296,
|
|
6
|
-
DATA_POINTER_POS_32 = 536870902,
|
|
7
|
-
IS_TS_FLAG_POS = 2147483612,
|
|
8
|
-
PROGRAM_OFFSET = 0,
|
|
9
|
-
SOURCE_LEN_OFFSET = 16;
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
BUFFER_SIZE,
|
|
13
|
-
BUFFER_ALIGN,
|
|
14
|
-
DATA_POINTER_POS_32,
|
|
15
|
-
IS_TS_FLAG_POS,
|
|
16
|
-
PROGRAM_OFFSET,
|
|
17
|
-
SOURCE_LEN_OFFSET,
|
|
18
|
-
};
|
package/wrap.cjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Note: This code is repeated in `wrap.mjs`.
|
|
2
|
-
// Any changes should be applied in that file too.
|
|
3
|
-
|
|
4
|
-
module.exports.wrap = function wrap(result) {
|
|
5
|
-
let program, module, comments, errors;
|
|
6
|
-
return {
|
|
7
|
-
get program() {
|
|
8
|
-
if (!program) program = jsonParseAst(result.program);
|
|
9
|
-
return program;
|
|
10
|
-
},
|
|
11
|
-
get module() {
|
|
12
|
-
if (!module) module = result.module;
|
|
13
|
-
return module;
|
|
14
|
-
},
|
|
15
|
-
get comments() {
|
|
16
|
-
if (!comments) comments = result.comments;
|
|
17
|
-
return comments;
|
|
18
|
-
},
|
|
19
|
-
get errors() {
|
|
20
|
-
if (!errors) errors = result.errors;
|
|
21
|
-
return errors;
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Set `value` field of `Literal`s which are `BigInt`s or `RegExp`s.
|
|
27
|
-
//
|
|
28
|
-
// Returned JSON contains an array `fixes` with paths to these nodes
|
|
29
|
-
// e.g. for `123n; foo(/xyz/)`, `fixes` will be
|
|
30
|
-
// `[["body", 0, "expression"], ["body", 1, "expression", "arguments", 2]]`.
|
|
31
|
-
//
|
|
32
|
-
// Walk down the AST to these nodes and alter them.
|
|
33
|
-
// Compiling the list of fixes on Rust side avoids having to do a full AST traversal on JS side
|
|
34
|
-
// to locate the likely very few `Literal`s which need fixing.
|
|
35
|
-
function jsonParseAst(programJson) {
|
|
36
|
-
const { node: program, fixes } = JSON.parse(programJson);
|
|
37
|
-
for (const fixPath of fixes) {
|
|
38
|
-
applyFix(program, fixPath);
|
|
39
|
-
}
|
|
40
|
-
return program;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function applyFix(program, fixPath) {
|
|
44
|
-
let node = program;
|
|
45
|
-
for (const key of fixPath) {
|
|
46
|
-
node = node[key];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (node.bigint) {
|
|
50
|
-
node.value = BigInt(node.bigint);
|
|
51
|
-
} else {
|
|
52
|
-
try {
|
|
53
|
-
node.value = RegExp(node.regex.pattern, node.regex.flags);
|
|
54
|
-
} catch (_err) { // oxlint-disable-line no-unused-vars
|
|
55
|
-
// Invalid regexp, or valid regexp using syntax not supported by this version of NodeJS
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|