mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
### 🚀 Features -8dd67a6transform-react: Expose TypeScript transform options (Tomas Särnhammar) -deed7dcparser: More friendly error for duplicate import attribute key (#28262) (sapphi-red) ### 🐛 Bug Fixes -eaa8e90ecmascript: Avoid numeric `+` folding when an operand may be a string (#28544) (camc314) -b03c7b8regular_expression: Allow incomplete oversized legacy quantifiers (#28449) (Boshen) -128c67dsemantic: Check strict eval and arguments writes by reference flags (#28445) (Boshen) -c97c43cparser: Reject TypeScript default exports in JavaScript (#28440) (Boshen) -fdd119fspan: Count Unicode characters when filtering typo suggestions (#28452) (Boshen) -cb64638regular_expression: Reject incomplete Unicode atom escapes (#28448) (Boshen) -fc0eed3semantic: Stop let-binding scans at arrow functions (#28444) (Boshen) -3421516parser: Preserve default import names in reexports (#28442) (Boshen) -a1e7e5fparser: Reject optional class members in JavaScript (#28439) (Boshen) -5b9a7bcparser: Parse sloppy let expressions and labels (#28438) (Boshen) -8e61652regex: Reject templates without cooked values (#28345) (Boshen) -3b36543parser: Preserve in-context after TypeScript type arguments (#28300) (Boshen) -2e3126cregex: Decode constructor patterns and flags consistently (#28298) (Boshen) -8a90be2regex: Track capture groups and disjunction identity (#28297) (Boshen) -3dc2cb0regex: Preserve escape values and boundaries (#28296) (Boshen) -fc8acbcparser: Handle leading-zero numeric exponents (#28295) (Boshen) -91a638dparser: Normalize raw template line endings with invalid escapes (#28285) (Boshen) -2ac9a42parser: Allow parenthesized private-in expressions (#28284) (Boshen) -052bca9ast: Prevent greyed out fields in AST types in IDEs (#28335) (overlookmotel) -ed7df7dast/estree: Include comments in TS Program span (#28326) (camc314) ### ⚡ Performance -9b6b7bfregular_expression: Advance validated Unicode escapes directly (#28514) (Boshen) -82e1982regular_expression: Share Unicode property name prefixes (#28513) (Boshen) -5395a40regular_expression: Parse class set character prefixes once (#28512) (Boshen) -3708934regular_expression: Defer literal range dash allocation (#28511) (Boshen) -d85ee3dsemantic: Skip arguments ancestry checks outside classes (#28510) (Boshen) -cf81d07semantic: Reuse private reference resolution (#28509) (Boshen) -a79eebcsemantic: Avoid duplicate maps for public JavaScript members (#28508) (Boshen) -235ca3bsemantic: Skip escape checks for unescaped strings (#28507) (Boshen) -babf44cparser: Reuse shorthand assignment target identifiers (#28504) (Boshen) -444f24aecmascript: Short-circuit simple parameter checks for rest (#28503) (Boshen) -04b20c0semantic: Compute duplicate parameter policy once per list (#28446) (Boshen) -dbf8482parser: Use token lookahead for simple function types (#28489) (Boshen) -bca1275parser: Avoid unused destructuring rest capacity (#28499) (Boshen) -691be5cparser: Compact cover initialized name storage (#28495) (Boshen) -b3b5444parser: Build simple arrow bindings directly (#28493) (Boshen) -e1c9bafparser: Disambiguate single-identifier arrow heads (#28491) (Boshen) -550e98aregular_expression: Avoid rescanning unique capture names (#28450) (Boshen) -10e9fc7parser: Skip duplicate lookup for singleton import attributes (#28441) (Boshen) -5238839parser: Use a stack buffer for float separators (#28435) (Boshen) -6e35e3cparser: Fast-path leaf expressions before delimiters (#28432) (Boshen) -3d7512cparser: Decode Unicode identifiers once (#28414) (Boshen) -30f59f4parser: Factor object type opening brace (#28430) (Boshen) -028a267parser: Always inline postfix update parsing (#28429) (Boshen) -1b5a171parser: Reuse export kind classification (#28424) (Boshen) -179a432parser: Factor return type identifier parsing (#28416) (Boshen) -553dd1dparser: Inline hot paths and fold function dispatch (#28404) (Boshen) -de75d56parser: Combine parenthesized arrow lookahead (#28412) (Boshen) -a768a0cparser: Reuse comment annotations after rewind (#28408) (Boshen) -563d92aparser: Skip redundant source cursor updates (#28409) (Boshen) -7941ca9parser: Factor tuple identifier parsing (#28398) (Boshen) -426c151parser: Construct completed tokens without intermediate writes (#28291) (Boshen) -df42953minifier: Don't request another pass for block unwrapping (#28315) (Dunqing) -c2d663dparser: Avoid vectors for single parenthesized expressions (#28374) (Boshen) -50bd0a9parser: Size delimited lists after the first element (#28373) (Boshen) -bd869b5parser: Bypass redundant operand parsing (#28372) (Boshen) -455fc09parser: Skip keyword checks for plain identifier expressions (#28371) (Boshen) -61303fbparser: Fast-path identifier operands (#28306) (Boshen) -6cf5b1aparser: Guard arrow and conditional parsing (#28305) (Boshen) -3666939parser: Specialize identifier reference parsing (#28303) (Boshen) -0d6641aparser: Skip inapplicable expression parsing paths (#28294) (Boshen) -3be7997parser: Reduce lexer search batch size (#28292) (Boshen) -ab5655aregex: Remove redundant character-class and quantifier checks (#28288) (Boshen) -ec8e8d4parser: Remove redundant grammar and lexer checks (#28287) (Boshen) -c903f5cparser: Specialize known-token parsing (#28286) (Boshen) -2683225str: `static_ident!` and `static_str!` macros guarantee const evaluation (#28340) (overlookmotel) -df90836ast: Reduce compile time of `#[ast]` macro (#28336) (overlookmotel) -8239dacparser: Replace dragonbox_ecma with zmij_ecma (#28282) (Boshen)
788 lines
32 KiB
JavaScript
788 lines
32 KiB
JavaScript
/* eslint-disable */
|
|
// @ts-nocheck
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
import { createRequire } from 'module'
|
|
const require = createRequire(import.meta.url)
|
|
|
|
const { readFileSync } = require('fs')
|
|
let nativeBinding = null
|
|
// Which artifact actually loaded. The WASI fallback chain overwrites it with
|
|
// the flavor it resolved; the late native retry below leaves it alone because
|
|
// it only runs while no WASI candidate has been loaded.
|
|
let __napiLoadedBindingTarget = 'native'
|
|
const loadErrors = []
|
|
|
|
const isMusl = () => {
|
|
let musl = false
|
|
if (process.platform === 'linux') {
|
|
musl = isMuslFromFilesystem()
|
|
if (musl === null) {
|
|
musl = isMuslFromReport()
|
|
}
|
|
if (musl === null) {
|
|
musl = isMuslFromChildProcess()
|
|
}
|
|
}
|
|
return musl
|
|
}
|
|
|
|
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
|
|
const isMuslFromFilesystem = () => {
|
|
try {
|
|
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
const isMuslFromReport = () => {
|
|
let report = null
|
|
if (process.report && typeof process.report.getReport === 'function') {
|
|
process.report.excludeNetwork = true
|
|
report = process.report.getReport()
|
|
}
|
|
if (!report) {
|
|
return null
|
|
}
|
|
if (report.header && report.header.glibcVersionRuntime) {
|
|
return false
|
|
}
|
|
if (Array.isArray(report.sharedObjects)) {
|
|
if (report.sharedObjects.some(isFileMusl)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
const isMuslFromChildProcess = () => {
|
|
try {
|
|
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
} catch (e) {
|
|
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
return false
|
|
}
|
|
}
|
|
|
|
function requireNative() {
|
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
try {
|
|
const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
|
|
// The override may be a generated WASI loader, which already reports its
|
|
// own flavor. Adopt it: `module.exports` aliases this object, so claiming
|
|
// 'native' would both misreport the artifact and overwrite the loader's
|
|
// marker through the alias.
|
|
__napiLoadedBindingTarget =
|
|
overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
|
|
? overrideBinding.__napiBindingTarget
|
|
: 'native'
|
|
return overrideBinding
|
|
} catch (err) {
|
|
loadErrors.push(err)
|
|
}
|
|
} else if (process.platform === 'android') {
|
|
if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./parser.android-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-android-arm64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-android-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
try {
|
|
return require('./parser.android-arm-eabi.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-android-arm-eabi')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-android-arm-eabi/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'win32') {
|
|
if (process.arch === 'x64') {
|
|
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
try {
|
|
return require('./parser.win32-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-win32-x64-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-win32-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./parser.win32-x64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-win32-x64-msvc')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-win32-x64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'ia32') {
|
|
try {
|
|
return require('./parser.win32-ia32-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-win32-ia32-msvc')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-win32-ia32-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./parser.win32-arm64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-win32-arm64-msvc')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-win32-arm64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'darwin') {
|
|
try {
|
|
return require('./parser.darwin-universal.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-darwin-universal')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-darwin-universal/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
if (process.arch === 'x64') {
|
|
try {
|
|
return require('./parser.darwin-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-darwin-x64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-darwin-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./parser.darwin-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-darwin-arm64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-darwin-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'freebsd') {
|
|
if (process.arch === 'x64') {
|
|
try {
|
|
return require('./parser.freebsd-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-freebsd-x64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-freebsd-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./parser.freebsd-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-freebsd-arm64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-freebsd-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'linux') {
|
|
if (process.arch === 'x64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./parser.linux-x64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-x64-musl')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-x64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./parser.linux-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-x64-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./parser.linux-arm64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-arm64-musl')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-arm64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./parser.linux-arm64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-arm64-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-arm64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./parser.linux-arm-musleabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-arm-musleabihf')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-arm-musleabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./parser.linux-arm-gnueabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-arm-gnueabihf')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-arm-gnueabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'loong64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./parser.linux-loong64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-loong64-musl')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-loong64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./parser.linux-loong64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-loong64-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-loong64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'riscv64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./parser.linux-riscv64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-riscv64-musl')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-riscv64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./parser.linux-riscv64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-riscv64-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-riscv64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'ppc64') {
|
|
try {
|
|
return require('./parser.linux-ppc64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-ppc64-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-ppc64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 's390x') {
|
|
try {
|
|
return require('./parser.linux-s390x-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-linux-s390x-gnu')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-linux-s390x-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'openharmony') {
|
|
if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./parser.openharmony-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-openharmony-arm64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-openharmony-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'x64') {
|
|
try {
|
|
return require('./parser.openharmony-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-openharmony-x64')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-openharmony-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
try {
|
|
return require('./parser.openharmony-arm.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@oxc-parser/binding-openharmony-arm')
|
|
const bindingPackageVersion = require('@oxc-parser/binding-openharmony-arm/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
}
|
|
}
|
|
|
|
function createLoadErrorChain(errors) {
|
|
return errors.reduce((previous, current) => {
|
|
let message
|
|
try {
|
|
message =
|
|
current && typeof current.message === 'string'
|
|
? current.message
|
|
: String(current)
|
|
} catch {
|
|
message = 'Unknown error'
|
|
}
|
|
const error = new Error(message)
|
|
error.cause = previous
|
|
return error
|
|
}, null)
|
|
}
|
|
|
|
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
// 'error' → require WASI without initializing a native fallback
|
|
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
//
|
|
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
const __napiWasiFlavors = ['wasm32-wasi', 'wasm32-wasip1']
|
|
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
const __napiWasiFlavorRequested =
|
|
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
if (
|
|
__napiWasiFlavorRequested &&
|
|
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
) {
|
|
throw new Error(
|
|
'Unsupported WASI flavor "' +
|
|
__napiWasiFlavor +
|
|
'". Available flavors: ' +
|
|
__napiWasiFlavors.join(', '),
|
|
)
|
|
}
|
|
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
const forceWasi =
|
|
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
forceWasiError ||
|
|
__napiWasiFlavorRequested
|
|
|
|
if (!forceWasi) {
|
|
nativeBinding = requireNative()
|
|
}
|
|
|
|
if (!nativeBinding || forceWasi) {
|
|
let wasiBinding = null
|
|
let wasiBindingLoaded = false
|
|
const wasiBindingErrors = []
|
|
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
try {
|
|
require.resolve(specifier)
|
|
} catch (resolveError) {
|
|
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
throw resolveError
|
|
}
|
|
if (isPackage) {
|
|
try {
|
|
require.resolve(specifier + '/package.json')
|
|
} catch (packageError) {
|
|
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
return resolveError
|
|
}
|
|
// An exports restriction proves the package exists even when its
|
|
// package.json is not public. Preserve the root resolution failure.
|
|
throw resolveError
|
|
}
|
|
// The package exists but its main/export target is broken.
|
|
throw resolveError
|
|
}
|
|
return resolveError
|
|
}
|
|
if (localArtifacts) {
|
|
let artifactError = null
|
|
for (let i = 0; i < localArtifacts.length; i++) {
|
|
try {
|
|
require.resolve(localArtifacts[i])
|
|
return null
|
|
} catch (resolveError) {
|
|
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
throw resolveError
|
|
}
|
|
artifactError = resolveError
|
|
}
|
|
}
|
|
return artifactError
|
|
}
|
|
return null
|
|
}
|
|
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
let candidateError = null
|
|
let candidateFailed = false
|
|
try {
|
|
candidateError = __napiWasiResolveCandidate('./parser.wasi.cjs', false, ['./parser.wasm32-wasi.debug.wasm', './parser.wasm32-wasi.wasm'])
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
wasiBinding = require('./parser.wasi.cjs')
|
|
nativeBinding = wasiBinding
|
|
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
wasiBindingLoaded = true
|
|
}
|
|
} catch (err) {
|
|
candidateError = err
|
|
candidateFailed = true
|
|
}
|
|
if (candidateFailed) {
|
|
wasiBindingErrors.push(candidateError)
|
|
loadErrors.push(candidateError)
|
|
}
|
|
}
|
|
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasip1')) {
|
|
let candidateError = null
|
|
let candidateFailed = false
|
|
try {
|
|
candidateError = __napiWasiResolveCandidate('./parser.wasip1.cjs', false, ['./parser.wasm32-wasip1.debug.wasm', './parser.wasm32-wasip1.wasm'])
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
wasiBinding = require('./parser.wasip1.cjs')
|
|
nativeBinding = wasiBinding
|
|
__napiLoadedBindingTarget = 'wasm32-wasip1'
|
|
wasiBindingLoaded = true
|
|
}
|
|
} catch (err) {
|
|
candidateError = err
|
|
candidateFailed = true
|
|
}
|
|
if (candidateFailed) {
|
|
wasiBindingErrors.push(candidateError)
|
|
loadErrors.push(candidateError)
|
|
}
|
|
}
|
|
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
|
|
let candidateError = null
|
|
let candidateFailed = false
|
|
try {
|
|
candidateError = __napiWasiResolveCandidate('@oxc-parser/binding-wasm32-wasi', true, undefined)
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
const bindingPackageVersion = require('@oxc-parser/binding-wasm32-wasi/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0') {
|
|
throw new Error(`WASI binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
}
|
|
wasiBinding = require('@oxc-parser/binding-wasm32-wasi')
|
|
nativeBinding = wasiBinding
|
|
__napiLoadedBindingTarget = 'wasm32-wasi'
|
|
wasiBindingLoaded = true
|
|
}
|
|
} catch (err) {
|
|
candidateError = err
|
|
candidateFailed = true
|
|
}
|
|
if (candidateFailed) {
|
|
wasiBindingErrors.push(candidateError)
|
|
loadErrors.push(candidateError)
|
|
}
|
|
}
|
|
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasip1')) {
|
|
let candidateError = null
|
|
let candidateFailed = false
|
|
try {
|
|
candidateError = __napiWasiResolveCandidate('@oxc-parser/binding-wasm32-wasip1', true, undefined)
|
|
candidateFailed = candidateError !== null
|
|
if (!candidateFailed) {
|
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
const bindingPackageVersion = require('@oxc-parser/binding-wasm32-wasip1/package.json').version
|
|
if (bindingPackageVersion !== '0.157.0') {
|
|
throw new Error(`WASI binding package version mismatch, expected 0.157.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
}
|
|
wasiBinding = require('@oxc-parser/binding-wasm32-wasip1')
|
|
nativeBinding = wasiBinding
|
|
__napiLoadedBindingTarget = 'wasm32-wasip1'
|
|
wasiBindingLoaded = true
|
|
}
|
|
} catch (err) {
|
|
candidateError = err
|
|
candidateFailed = true
|
|
}
|
|
if (candidateFailed) {
|
|
wasiBindingErrors.push(candidateError)
|
|
loadErrors.push(candidateError)
|
|
}
|
|
}
|
|
if (
|
|
!wasiBindingLoaded &&
|
|
forceWasi &&
|
|
!forceWasiError &&
|
|
!__napiWasiFlavorRequested
|
|
) {
|
|
nativeBinding = requireNative()
|
|
}
|
|
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
const error = new Error(
|
|
__napiWasiFlavorRequested
|
|
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
)
|
|
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
|
try {
|
|
nativeBinding = require('./webcontainer-fallback.cjs');
|
|
} catch (err) {
|
|
loadErrors.push(err)
|
|
}
|
|
}
|
|
|
|
if (!nativeBinding) {
|
|
if (loadErrors.length > 0) {
|
|
const error = new Error(
|
|
`Cannot find native binding. ` +
|
|
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
)
|
|
// assign instead of the `new Error(message, { cause })` options form,
|
|
// which Node < 16.9 silently ignores
|
|
error.cause = createLoadErrorChain(loadErrors)
|
|
throw error
|
|
}
|
|
throw new Error(`Failed to load native binding`)
|
|
}
|
|
|
|
const { Severity, ParseResult, ExportExportNameKind, ExportImportNameKind, ExportLocalNameKind, ImportNameKind, parse, parseSync, rawTransferSupported } = nativeBinding
|
|
export { Severity }
|
|
export { ParseResult }
|
|
export { ExportExportNameKind }
|
|
export { ExportImportNameKind }
|
|
export { ExportLocalNameKind }
|
|
export { ImportNameKind }
|
|
export { parse }
|
|
export { parseSync }
|
|
export { rawTransferSupported }
|
|
export const __napiBindingTarget = __napiLoadedBindingTarget
|
|
const { getBufferOffset, parseRaw, parseRawSync } = nativeBinding
|
|
export { getBufferOffset, parseRaw, parseRawSync }
|