fix(scripts/build): syntax error

This commit is contained in:
PalmDevs 2025-09-10 00:54:55 +07:00
parent e389a6b61b
commit 790f1f9ee3
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 8 additions and 5 deletions

View file

@ -42,8 +42,9 @@ export default async function build(dev = Dev, log = true) {
input: 'src/index.ts',
platform: 'neutral',
optimization: {
// ! BROKEN, DO NOT USE!
// inlineConst: true,
inlineConst: {
mode: 'smart',
},
// @ts-expect-error: Option not documented, but added in 1.0.0-beta.30
pifeForModuleWrappers: true,
},
@ -91,8 +92,8 @@ export default async function build(dev = Dev, log = true) {
asRequire(),
shimAliases(ShimsDir),
importGlobPlugin(),
importDefer(),
hermesSwcPlugin(),
importDefer(),
hermesCPlugin({
flags: [
dev ? '-Og' : '-O',

View file

@ -8,6 +8,8 @@ const DEFER_NAMESPACE_IMPORT_REGEX =
/**
* Really wacky support for `import defer` statements by transforming them to `require()`.
*
* Only supports JavaScript files. TypeScript files with conflicting type names may cause issues.
*
* `import defer` statements are transformed to provide on-demand/lazy loading.
*
* This is achieved by creating a scoped closure to cache the module.
@ -41,7 +43,7 @@ export default function importDefer() {
hasReplacements = true
// Find all usages of the imported identifier
const usageRegex = new RegExp(`\\b${localName}\\b`, 'g');
const usageRegex = new RegExp(`\\b${localName}\\b`, 'g')
for (const usageMatch of code.matchAll(usageRegex)) {
// Original import declaration
@ -123,5 +125,5 @@ function generateDeferReplacement(bindings: Bindings, modulePath: string) {
const [{ local: localName }] = bindings
const cacheVar = `_cache_${modulePath.replace(/[^a-zA-Z0-9]/g, '_')}`
return `var ${cacheVar};const ${localName}=()=>${cacheVar}??=require('${modulePath}')`
return `var ${cacheVar};const ${localName}=()=>${cacheVar}??=require('${modulePath}');`
}