oxc-parser 0.21.0 → 0.22.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.
Files changed (3) hide show
  1. package/index.d.ts +48 -40
  2. package/index.js +336 -272
  3. package/package.json +9 -9
package/index.d.ts CHANGED
@@ -1,7 +1,26 @@
1
- /* tslint:disable */
1
+ /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+ export interface Comment {
4
+ type: 'Line' | 'Block'
5
+ value: string
6
+ start: number
7
+ end: number
8
+ }
3
9
 
4
- /* auto-generated by NAPI-RS */
10
+ export interface ExportSpecifier {
11
+ /** Exported name */
12
+ n: string
13
+ /** Local name, or undefined. */
14
+ ln?: string
15
+ /** Start of exported name */
16
+ s: number
17
+ /** End of exported name */
18
+ e: number
19
+ /** Start of local name */
20
+ ls?: number
21
+ /** End of local name */
22
+ le?: number
23
+ }
5
24
 
6
25
  export interface ImportSpecifier {
7
26
  /**
@@ -33,20 +52,7 @@ export interface ImportSpecifier {
33
52
  */
34
53
  a: number
35
54
  }
36
- export interface ExportSpecifier {
37
- /** Exported name */
38
- n: string
39
- /** Local name, or undefined. */
40
- ln?: string
41
- /** Start of exported name */
42
- s: number
43
- /** End of exported name */
44
- e: number
45
- /** Start of local name */
46
- ls?: number
47
- /** End of local name */
48
- le?: number
49
- }
55
+
50
56
  export interface ModuleLexer {
51
57
  imports: Array<ImportSpecifier>
52
58
  exports: Array<ExportSpecifier>
@@ -59,6 +65,14 @@ export interface ModuleLexer {
59
65
  /** Facade modules that only use import / export syntax */
60
66
  facade: boolean
61
67
  }
68
+
69
+ /**
70
+ * # Panics
71
+ *
72
+ * * Tokio crashes
73
+ */
74
+ export declare function moduleLexerAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ModuleLexer>
75
+
62
76
  /**
63
77
  * Outputs the list of exports and locations of import specifiers,
64
78
  * including dynamic import and import meta handling.
@@ -67,13 +81,21 @@ export interface ModuleLexer {
67
81
  *
68
82
  * * File extension is invalid
69
83
  */
70
- export function moduleLexerSync(sourceText: string, options?: ParserOptions | undefined | null): ModuleLexer
84
+ export declare function moduleLexerSync(sourceText: string, options?: ParserOptions | undefined | null): ModuleLexer
85
+
71
86
  /**
72
87
  * # Panics
73
88
  *
74
89
  * * Tokio crashes
75
90
  */
76
- export function moduleLexerAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ModuleLexer>
91
+ export declare function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
92
+
93
+ export interface ParseResult {
94
+ program: string
95
+ comments: Array<Comment>
96
+ errors: Array<string>
97
+ }
98
+
77
99
  /**
78
100
  * Babel Parser Options
79
101
  *
@@ -93,37 +115,23 @@ export interface ParserOptions {
93
115
  */
94
116
  preserveParens?: boolean
95
117
  }
96
- export interface ParseResult {
97
- program: string
98
- comments: Array<Comment>
99
- errors: Array<string>
100
- }
101
- export interface Comment {
102
- type: 'Line' | 'Block'
103
- value: string
104
- start: number
105
- end: number
106
- }
118
+
107
119
  /**
108
- * Parse without returning anything.
109
- * This is for benchmark purposes such as measuring napi communication overhead.
110
- *
111
120
  * # Panics
112
121
  *
113
122
  * * File extension is invalid
114
123
  * * Serde JSON serialization
115
124
  */
116
- export function parseWithoutReturn(sourceText: string, options?: ParserOptions | undefined | null): void
125
+ export declare function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
126
+
117
127
  /**
128
+ * Parse without returning anything.
129
+ * This is for benchmark purposes such as measuring napi communication overhead.
130
+ *
118
131
  * # Panics
119
132
  *
120
133
  * * File extension is invalid
121
134
  * * Serde JSON serialization
122
135
  */
123
- export function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
124
- /**
125
- * # Panics
126
- *
127
- * * Tokio crashes
128
- */
129
- export function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
136
+ export declare function parseWithoutReturn(sourceText: string, options?: ParserOptions | undefined | null): void
137
+
package/index.js CHANGED
@@ -1,304 +1,368 @@
1
- /* tslint:disable */
1
+ // prettier-ignore
2
2
  /* eslint-disable */
3
- /* prettier-ignore */
4
-
5
3
  /* auto-generated by NAPI-RS */
6
4
 
7
- const { existsSync, readFileSync } = require('fs')
8
- const { join } = require('path')
9
-
10
- const { platform, arch } = process
5
+ const { readFileSync } = require('fs')
11
6
 
12
7
  let nativeBinding = null
13
- let localFileExisted = false
14
- let loadError = null
8
+ const loadErrors = []
15
9
 
16
- function isMusl() {
17
- // For Node 10
18
- if (!process.report || typeof process.report.getReport !== 'function') {
19
- try {
20
- const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
- return readFileSync(lddPath, 'utf8').includes('musl')
22
- } catch (e) {
10
+ const isMusl = () => {
11
+ let musl = false
12
+ if (process.platform === 'linux') {
13
+ musl = isMuslFromFilesystem()
14
+ if (musl === null) {
15
+ musl = isMuslFromReport()
16
+ }
17
+ if (musl === null) {
18
+ musl = isMuslFromChildProcess()
19
+ }
20
+ }
21
+ return musl
22
+ }
23
+
24
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
25
+
26
+ const isMuslFromFilesystem = () => {
27
+ try {
28
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
+
34
+ const isMuslFromReport = () => {
35
+ const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
36
+ if (!report) {
37
+ return null
38
+ }
39
+ if (report.header && report.header.glibcVersionRuntime) {
40
+ return false
41
+ }
42
+ if (Array.isArray(report.sharedObjects)) {
43
+ if (report.sharedObjects.some(isFileMusl)) {
23
44
  return true
24
45
  }
25
- } else {
26
- const { glibcVersionRuntime } = process.report.getReport().header
27
- return !glibcVersionRuntime
46
+ }
47
+ return false
48
+ }
49
+
50
+ const isMuslFromChildProcess = () => {
51
+ try {
52
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
53
+ } catch (e) {
54
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
55
+ return false
28
56
  }
29
57
  }
30
58
 
31
- switch (platform) {
32
- case 'android':
33
- switch (arch) {
34
- case 'arm64':
35
- localFileExisted = existsSync(join(__dirname, 'parser.android-arm64.node'))
59
+ function requireNative() {
60
+ if (process.platform === 'android') {
61
+ if (process.arch === 'arm64') {
62
+ try {
63
+ return require('./parser.android-arm64.node')
64
+ } catch (e) {
65
+ loadErrors.push(e)
66
+ }
67
+ try {
68
+ return require('@oxc-parser/binding-android-arm64')
69
+ } catch (e) {
70
+ loadErrors.push(e)
71
+ }
72
+
73
+ } else if (process.arch === 'arm') {
74
+ try {
75
+ return require('./parser.android-arm-eabi.node')
76
+ } catch (e) {
77
+ loadErrors.push(e)
78
+ }
79
+ try {
80
+ return require('@oxc-parser/binding-android-arm-eabi')
81
+ } catch (e) {
82
+ loadErrors.push(e)
83
+ }
84
+
85
+ } else {
86
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
87
+ }
88
+ } else if (process.platform === 'win32') {
89
+ if (process.arch === 'x64') {
90
+ try {
91
+ return require('./parser.win32-x64-msvc.node')
92
+ } catch (e) {
93
+ loadErrors.push(e)
94
+ }
95
+ try {
96
+ return require('@oxc-parser/binding-win32-x64-msvc')
97
+ } catch (e) {
98
+ loadErrors.push(e)
99
+ }
100
+
101
+ } else if (process.arch === 'ia32') {
102
+ try {
103
+ return require('./parser.win32-ia32-msvc.node')
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ try {
108
+ return require('@oxc-parser/binding-win32-ia32-msvc')
109
+ } catch (e) {
110
+ loadErrors.push(e)
111
+ }
112
+
113
+ } else if (process.arch === 'arm64') {
114
+ try {
115
+ return require('./parser.win32-arm64-msvc.node')
116
+ } catch (e) {
117
+ loadErrors.push(e)
118
+ }
119
+ try {
120
+ return require('@oxc-parser/binding-win32-arm64-msvc')
121
+ } catch (e) {
122
+ loadErrors.push(e)
123
+ }
124
+
125
+ } else {
126
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
127
+ }
128
+ } else if (process.platform === 'darwin') {
129
+ try {
130
+ return require('./parser.darwin-universal.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ return require('@oxc-parser/binding-darwin-universal')
136
+ } catch (e) {
137
+ loadErrors.push(e)
138
+ }
139
+
140
+ if (process.arch === 'x64') {
141
+ try {
142
+ return require('./parser.darwin-x64.node')
143
+ } catch (e) {
144
+ loadErrors.push(e)
145
+ }
146
+ try {
147
+ return require('@oxc-parser/binding-darwin-x64')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+
152
+ } else if (process.arch === 'arm64') {
153
+ try {
154
+ return require('./parser.darwin-arm64.node')
155
+ } catch (e) {
156
+ loadErrors.push(e)
157
+ }
158
+ try {
159
+ return require('@oxc-parser/binding-darwin-arm64')
160
+ } catch (e) {
161
+ loadErrors.push(e)
162
+ }
163
+
164
+ } else {
165
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
166
+ }
167
+ } else if (process.platform === 'freebsd') {
168
+ if (process.arch === 'x64') {
169
+ try {
170
+ return require('./parser.freebsd-x64.node')
171
+ } catch (e) {
172
+ loadErrors.push(e)
173
+ }
174
+ try {
175
+ return require('@oxc-parser/binding-freebsd-x64')
176
+ } catch (e) {
177
+ loadErrors.push(e)
178
+ }
179
+
180
+ } else if (process.arch === 'arm64') {
181
+ try {
182
+ return require('./parser.freebsd-arm64.node')
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ try {
187
+ return require('@oxc-parser/binding-freebsd-arm64')
188
+ } catch (e) {
189
+ loadErrors.push(e)
190
+ }
191
+
192
+ } else {
193
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
194
+ }
195
+ } else if (process.platform === 'linux') {
196
+ if (process.arch === 'x64') {
197
+ if (isMusl()) {
36
198
  try {
37
- if (localFileExisted) {
38
- nativeBinding = require('./parser.android-arm64.node')
39
- } else {
40
- nativeBinding = require('@oxc-parser/binding-android-arm64')
41
- }
42
- } catch (e) {
43
- loadError = e
44
- }
45
- break
46
- case 'arm':
47
- localFileExisted = existsSync(join(__dirname, 'parser.android-arm-eabi.node'))
199
+ return require('./parser.linux-x64-musl.node')
200
+ } catch (e) {
201
+ loadErrors.push(e)
202
+ }
203
+ try {
204
+ return require('@oxc-parser/binding-linux-x64-musl')
205
+ } catch (e) {
206
+ loadErrors.push(e)
207
+ }
208
+
209
+ } else {
48
210
  try {
49
- if (localFileExisted) {
50
- nativeBinding = require('./parser.android-arm-eabi.node')
51
- } else {
52
- nativeBinding = require('@oxc-parser/binding-android-arm-eabi')
53
- }
54
- } catch (e) {
55
- loadError = e
56
- }
57
- break
58
- default:
59
- throw new Error(`Unsupported architecture on Android ${arch}`)
60
- }
61
- break
62
- case 'win32':
63
- switch (arch) {
64
- case 'x64':
65
- localFileExisted = existsSync(
66
- join(__dirname, 'parser.win32-x64-msvc.node')
67
- )
211
+ return require('./parser.linux-x64-gnu.node')
212
+ } catch (e) {
213
+ loadErrors.push(e)
214
+ }
215
+ try {
216
+ return require('@oxc-parser/binding-linux-x64-gnu')
217
+ } catch (e) {
218
+ loadErrors.push(e)
219
+ }
220
+
221
+ }
222
+ } else if (process.arch === 'arm64') {
223
+ if (isMusl()) {
68
224
  try {
69
- if (localFileExisted) {
70
- nativeBinding = require('./parser.win32-x64-msvc.node')
71
- } else {
72
- nativeBinding = require('@oxc-parser/binding-win32-x64-msvc')
73
- }
74
- } catch (e) {
75
- loadError = e
76
- }
77
- break
78
- case 'ia32':
79
- localFileExisted = existsSync(
80
- join(__dirname, 'parser.win32-ia32-msvc.node')
81
- )
225
+ return require('./parser.linux-arm64-musl.node')
226
+ } catch (e) {
227
+ loadErrors.push(e)
228
+ }
229
+ try {
230
+ return require('@oxc-parser/binding-linux-arm64-musl')
231
+ } catch (e) {
232
+ loadErrors.push(e)
233
+ }
234
+
235
+ } else {
82
236
  try {
83
- if (localFileExisted) {
84
- nativeBinding = require('./parser.win32-ia32-msvc.node')
85
- } else {
86
- nativeBinding = require('@oxc-parser/binding-win32-ia32-msvc')
87
- }
88
- } catch (e) {
89
- loadError = e
90
- }
91
- break
92
- case 'arm64':
93
- localFileExisted = existsSync(
94
- join(__dirname, 'parser.win32-arm64-msvc.node')
95
- )
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
+ }
248
+ } else if (process.arch === 'arm') {
249
+ if (isMusl()) {
96
250
  try {
97
- if (localFileExisted) {
98
- nativeBinding = require('./parser.win32-arm64-msvc.node')
99
- } else {
100
- nativeBinding = require('@oxc-parser/binding-win32-arm64-msvc')
101
- }
102
- } catch (e) {
103
- loadError = e
104
- }
105
- break
106
- default:
107
- throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
- }
109
- break
110
- case 'darwin':
111
- localFileExisted = existsSync(join(__dirname, 'parser.darwin-universal.node'))
112
- try {
113
- if (localFileExisted) {
114
- nativeBinding = require('./parser.darwin-universal.node')
251
+ return require('./parser.linux-arm-musleabihf.node')
252
+ } catch (e) {
253
+ loadErrors.push(e)
254
+ }
255
+ try {
256
+ return require('@oxc-parser/binding-linux-arm-musleabihf')
257
+ } catch (e) {
258
+ loadErrors.push(e)
259
+ }
260
+
115
261
  } else {
116
- nativeBinding = require('@oxc-parser/binding-darwin-universal')
262
+ try {
263
+ return require('./parser.linux-arm-gnueabihf.node')
264
+ } catch (e) {
265
+ loadErrors.push(e)
266
+ }
267
+ try {
268
+ return require('@oxc-parser/binding-linux-arm-gnueabihf')
269
+ } catch (e) {
270
+ loadErrors.push(e)
271
+ }
272
+
117
273
  }
118
- break
119
- } catch {}
120
- switch (arch) {
121
- case 'x64':
122
- localFileExisted = existsSync(join(__dirname, 'parser.darwin-x64.node'))
274
+ } else if (process.arch === 'riscv64') {
275
+ if (isMusl()) {
123
276
  try {
124
- if (localFileExisted) {
125
- nativeBinding = require('./parser.darwin-x64.node')
126
- } else {
127
- nativeBinding = require('@oxc-parser/binding-darwin-x64')
128
- }
129
- } catch (e) {
130
- loadError = e
131
- }
132
- break
133
- case 'arm64':
134
- localFileExisted = existsSync(
135
- join(__dirname, 'parser.darwin-arm64.node')
136
- )
277
+ return require('./parser.linux-riscv64-musl.node')
278
+ } catch (e) {
279
+ loadErrors.push(e)
280
+ }
281
+ try {
282
+ return require('@oxc-parser/binding-linux-riscv64-musl')
283
+ } catch (e) {
284
+ loadErrors.push(e)
285
+ }
286
+
287
+ } else {
137
288
  try {
138
- if (localFileExisted) {
139
- nativeBinding = require('./parser.darwin-arm64.node')
140
- } else {
141
- nativeBinding = require('@oxc-parser/binding-darwin-arm64')
142
- }
143
- } catch (e) {
144
- loadError = e
145
- }
146
- break
147
- default:
148
- throw new Error(`Unsupported architecture on macOS: ${arch}`)
289
+ return require('./parser.linux-riscv64-gnu.node')
290
+ } catch (e) {
291
+ loadErrors.push(e)
292
+ }
293
+ try {
294
+ return require('@oxc-parser/binding-linux-riscv64-gnu')
295
+ } catch (e) {
296
+ loadErrors.push(e)
297
+ }
298
+
299
+ }
300
+ } else if (process.arch === 'ppc64') {
301
+ try {
302
+ return require('./parser.linux-ppc64-gnu.node')
303
+ } catch (e) {
304
+ loadErrors.push(e)
305
+ }
306
+ try {
307
+ return require('@oxc-parser/binding-linux-ppc64-gnu')
308
+ } catch (e) {
309
+ loadErrors.push(e)
310
+ }
311
+
312
+ } else if (process.arch === 's390x') {
313
+ try {
314
+ return require('./parser.linux-s390x-gnu.node')
315
+ } catch (e) {
316
+ loadErrors.push(e)
317
+ }
318
+ try {
319
+ return require('@oxc-parser/binding-linux-s390x-gnu')
320
+ } catch (e) {
321
+ loadErrors.push(e)
322
+ }
323
+
324
+ } else {
325
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
149
326
  }
150
- break
151
- case 'freebsd':
152
- if (arch !== 'x64') {
153
- throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
327
+ } else {
328
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
329
+ }
330
+ }
331
+
332
+ nativeBinding = requireNative()
333
+
334
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
335
+ try {
336
+ nativeBinding = require('./parser.wasi.cjs')
337
+ } catch (err) {
338
+ if (process.env.NAPI_RS_FORCE_WASI) {
339
+ console.error(err)
154
340
  }
155
- localFileExisted = existsSync(join(__dirname, 'parser.freebsd-x64.node'))
341
+ }
342
+ if (!nativeBinding) {
156
343
  try {
157
- if (localFileExisted) {
158
- nativeBinding = require('./parser.freebsd-x64.node')
159
- } else {
160
- nativeBinding = require('@oxc-parser/binding-freebsd-x64')
344
+ nativeBinding = require('@oxc-parser/binding-wasm32-wasi')
345
+ } catch (err) {
346
+ if (process.env.NAPI_RS_FORCE_WASI) {
347
+ console.error(err)
161
348
  }
162
- } catch (e) {
163
- loadError = e
164
- }
165
- break
166
- case 'linux':
167
- switch (arch) {
168
- case 'x64':
169
- if (isMusl()) {
170
- localFileExisted = existsSync(
171
- join(__dirname, 'parser.linux-x64-musl.node')
172
- )
173
- try {
174
- if (localFileExisted) {
175
- nativeBinding = require('./parser.linux-x64-musl.node')
176
- } else {
177
- nativeBinding = require('@oxc-parser/binding-linux-x64-musl')
178
- }
179
- } catch (e) {
180
- loadError = e
181
- }
182
- } else {
183
- localFileExisted = existsSync(
184
- join(__dirname, 'parser.linux-x64-gnu.node')
185
- )
186
- try {
187
- if (localFileExisted) {
188
- nativeBinding = require('./parser.linux-x64-gnu.node')
189
- } else {
190
- nativeBinding = require('@oxc-parser/binding-linux-x64-gnu')
191
- }
192
- } catch (e) {
193
- loadError = e
194
- }
195
- }
196
- break
197
- case 'arm64':
198
- if (isMusl()) {
199
- localFileExisted = existsSync(
200
- join(__dirname, 'parser.linux-arm64-musl.node')
201
- )
202
- try {
203
- if (localFileExisted) {
204
- nativeBinding = require('./parser.linux-arm64-musl.node')
205
- } else {
206
- nativeBinding = require('@oxc-parser/binding-linux-arm64-musl')
207
- }
208
- } catch (e) {
209
- loadError = e
210
- }
211
- } else {
212
- localFileExisted = existsSync(
213
- join(__dirname, 'parser.linux-arm64-gnu.node')
214
- )
215
- try {
216
- if (localFileExisted) {
217
- nativeBinding = require('./parser.linux-arm64-gnu.node')
218
- } else {
219
- nativeBinding = require('@oxc-parser/binding-linux-arm64-gnu')
220
- }
221
- } catch (e) {
222
- loadError = e
223
- }
224
- }
225
- break
226
- case 'arm':
227
- localFileExisted = existsSync(
228
- join(__dirname, 'parser.linux-arm-gnueabihf.node')
229
- )
230
- try {
231
- if (localFileExisted) {
232
- nativeBinding = require('./parser.linux-arm-gnueabihf.node')
233
- } else {
234
- nativeBinding = require('@oxc-parser/binding-linux-arm-gnueabihf')
235
- }
236
- } catch (e) {
237
- loadError = e
238
- }
239
- break
240
- case 'riscv64':
241
- if (isMusl()) {
242
- localFileExisted = existsSync(
243
- join(__dirname, 'parser.linux-riscv64-musl.node')
244
- )
245
- try {
246
- if (localFileExisted) {
247
- nativeBinding = require('./parser.linux-riscv64-musl.node')
248
- } else {
249
- nativeBinding = require('@oxc-parser/binding-linux-riscv64-musl')
250
- }
251
- } catch (e) {
252
- loadError = e
253
- }
254
- } else {
255
- localFileExisted = existsSync(
256
- join(__dirname, 'parser.linux-riscv64-gnu.node')
257
- )
258
- try {
259
- if (localFileExisted) {
260
- nativeBinding = require('./parser.linux-riscv64-gnu.node')
261
- } else {
262
- nativeBinding = require('@oxc-parser/binding-linux-riscv64-gnu')
263
- }
264
- } catch (e) {
265
- loadError = e
266
- }
267
- }
268
- break
269
- case 's390x':
270
- localFileExisted = existsSync(
271
- join(__dirname, 'parser.linux-s390x-gnu.node')
272
- )
273
- try {
274
- if (localFileExisted) {
275
- nativeBinding = require('./parser.linux-s390x-gnu.node')
276
- } else {
277
- nativeBinding = require('@oxc-parser/binding-linux-s390x-gnu')
278
- }
279
- } catch (e) {
280
- loadError = e
281
- }
282
- break
283
- default:
284
- throw new Error(`Unsupported architecture on Linux: ${arch}`)
285
349
  }
286
- break
287
- default:
288
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
350
+ }
289
351
  }
290
352
 
291
353
  if (!nativeBinding) {
292
- if (loadError) {
293
- throw loadError
354
+ if (loadErrors.length > 0) {
355
+ // TODO Link to documentation with potential fixes
356
+ // - The package owner could build/publish bindings for this arch
357
+ // - The user may need to bundle the correct files
358
+ // - The user may need to re-install node_modules to get new packages
359
+ throw new Error('Failed to load native binding', { cause: loadErrors })
294
360
  }
295
361
  throw new Error(`Failed to load native binding`)
296
362
  }
297
363
 
298
- const { moduleLexerSync, moduleLexerAsync, parseWithoutReturn, parseSync, parseAsync } = nativeBinding
299
-
300
- module.exports.moduleLexerSync = moduleLexerSync
301
- module.exports.moduleLexerAsync = moduleLexerAsync
302
- module.exports.parseWithoutReturn = parseWithoutReturn
303
- module.exports.parseSync = parseSync
304
- module.exports.parseAsync = parseAsync
364
+ module.exports.moduleLexerAsync = nativeBinding.moduleLexerAsync
365
+ module.exports.moduleLexerSync = nativeBinding.moduleLexerSync
366
+ module.exports.parseAsync = nativeBinding.parseAsync
367
+ module.exports.parseSync = nativeBinding.parseSync
368
+ module.exports.parseWithoutReturn = nativeBinding.parseWithoutReturn
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxc-parser",
3
- "version": "0.21.0",
3
+ "version": "0.22.1",
4
4
  "description": "Oxc Parser Node API",
5
5
  "keywords": [
6
6
  "Parser"
@@ -23,13 +23,13 @@
23
23
  "index.js"
24
24
  ],
25
25
  "optionalDependencies": {
26
- "@oxc-parser/binding-win32-x64-msvc": "0.21.0",
27
- "@oxc-parser/binding-win32-arm64-msvc": "0.21.0",
28
- "@oxc-parser/binding-linux-x64-gnu": "0.21.0",
29
- "@oxc-parser/binding-linux-arm64-gnu": "0.21.0",
30
- "@oxc-parser/binding-linux-x64-musl": "0.21.0",
31
- "@oxc-parser/binding-linux-arm64-musl": "0.21.0",
32
- "@oxc-parser/binding-darwin-x64": "0.21.0",
33
- "@oxc-parser/binding-darwin-arm64": "0.21.0"
26
+ "@oxc-parser/binding-win32-x64-msvc": "0.22.1",
27
+ "@oxc-parser/binding-win32-arm64-msvc": "0.22.1",
28
+ "@oxc-parser/binding-linux-x64-gnu": "0.22.1",
29
+ "@oxc-parser/binding-linux-arm64-gnu": "0.22.1",
30
+ "@oxc-parser/binding-linux-x64-musl": "0.22.1",
31
+ "@oxc-parser/binding-linux-arm64-musl": "0.22.1",
32
+ "@oxc-parser/binding-darwin-x64": "0.22.1",
33
+ "@oxc-parser/binding-darwin-arm64": "0.22.1"
34
34
  }
35
35
  }