diff --git a/src/codegen/bundle-functions.ts b/src/codegen/bundle-functions.ts index fe71cb8912668e..417b910fbc6dff 100644 --- a/src/codegen/bundle-functions.ts +++ b/src/codegen/bundle-functions.ts @@ -172,9 +172,10 @@ async function processFileSplit(filename: string): Promise<{ functions: BundledB // do not allow the bundler to rename a symbol to $ ($); -$$capture_start$$(${fn.async ? "async " : ""}${useThis - ? `function(${fn.params.join(",")})` - : `${fn.params.length === 1 ? fn.params[0] : `(${fn.params.join(",")})`}=>` +$$capture_start$$(${fn.async ? "async " : ""}${ + useThis + ? `function(${fn.params.join(",")})` + : `${fn.params.length === 1 ? fn.params[0] : `(${fn.params.join(",")})`}=>` } {${fn.source}}).$$capture_end$$; `, ); @@ -198,11 +199,11 @@ $$capture_start$$(${fn.async ? "async " : ""}${useThis (fn.directives.sloppy ? captured : captured.replace( - /function\s*\(.*?\)\s*{/, - '$&"use strict";' + - (usesDebug ? createLogClientJS("BUILTINS", fn.name) : "") + - (usesAssert ? createAssertClientJS(fn.name) : ""), - ) + /function\s*\(.*?\)\s*{/, + '$&"use strict";' + + (usesDebug ? createLogClientJS("BUILTINS", fn.name) : "") + + (usesAssert ? createAssertClientJS(fn.name) : ""), + ) ) .replace(/^\((async )?function\(/, "($1function (") .replace(/__intrinsic__/g, "@") @@ -282,8 +283,9 @@ for (const { basename, functions } of files) { const name = `${lowerBasename}${cap(fn.name)}Code`; bundledCPP += `// ${fn.name} const JSC::ConstructAbility s_${name}ConstructAbility = JSC::ConstructAbility::${fn.constructAbility}; -const JSC::InlineAttribute s_${name}InlineAttribute = JSC::InlineAttribute::${fn.directives.alwaysInline ? "Always" : "None" - }; +const JSC::InlineAttribute s_${name}InlineAttribute = JSC::InlineAttribute::${ + fn.directives.alwaysInline ? "Always" : "None" + }; const JSC::ConstructorKind s_${name}ConstructorKind = JSC::ConstructorKind::${fn.constructKind}; const JSC::ImplementationVisibility s_${name}ImplementationVisibility = JSC::ImplementationVisibility::${fn.visibility}; const int s_${name}Length = ${fn.source.length}; diff --git a/src/codegen/bundle-modules.ts b/src/codegen/bundle-modules.ts index 82d85fb461e99d..73d1b4c13e24ff 100644 --- a/src/codegen/bundle-modules.ts +++ b/src/codegen/bundle-modules.ts @@ -44,7 +44,7 @@ const { // work, so i have lot of debug logs that blow up the console because not sure what is going on. // that is also the reason for using `retry` when theoretically writing a file the first time // should actually write the file. -const verbose = Bun.env.VERBOSE ? console.log : () => { }; +const verbose = Bun.env.VERBOSE ? console.log : () => {}; async function retry(n, fn) { var err; while (n > 0) { @@ -87,12 +87,12 @@ for (let i = 0; i < moduleList.length; i++) { const processed = sliceSourceCode( "{" + - input - .replace( - /\bimport(\s*type)?\s*(\{[^}]*\}|(\*\s*as)?\s[a-zA-Z0-9_$]+)\s*from\s*['"][^'"]+['"]/g, - stmt => (importStatements.push(stmt), ""), - ) - .replace(/export\s*{\s*}\s*;/g, ""), + input + .replace( + /\bimport(\s*type)?\s*(\{[^}]*\}|(\*\s*as)?\s[a-zA-Z0-9_$]+)\s*from\s*['"][^'"]+['"]/g, + stmt => (importStatements.push(stmt), ""), + ) + .replace(/export\s*{\s*}\s*;/g, ""), true, x => requireTransformer(x, moduleList[i]), ); @@ -237,13 +237,13 @@ for (const entrypoint of bundledEntryPoints) { captured = captured.replace( /function\s*\(.*?\)\s*{/, '$&"use strict";' + - (usesDebug - ? createLogClientJS( - file_path.replace(".js", ""), - idToPublicSpecifierOrEnumName(file_path).replace(/^node:|^bun:/, ""), - ) - : "") + - (usesAssert ? createAssertClientJS(idToPublicSpecifierOrEnumName(file_path).replace(/^node:|^bun:/, "")) : ""), + (usesDebug + ? createLogClientJS( + file_path.replace(".js", ""), + idToPublicSpecifierOrEnumName(file_path).replace(/^node:|^bun:/, ""), + ) + : "") + + (usesAssert ? createAssertClientJS(idToPublicSpecifierOrEnumName(file_path).replace(/^node:|^bun:/, "")) : ""), ); const outputPath = path.join(JS_DIR, file_path); fs.mkdirSync(path.dirname(outputPath), { recursive: true }); @@ -286,11 +286,12 @@ writeIfNotChanged( // actually use this enum but it's probably a good thing to include. writeIfNotChanged( path.join(CODEGEN_DIR, "InternalModuleRegistry+enum.h"), - `${moduleList - .map((id, n) => { - return `${idToEnumName(id)} = ${n},`; - }) - .join("\n") + "\n" + `${ + moduleList + .map((id, n) => { + return `${idToEnumName(id)} = ${n},`; + }) + .join("\n") + "\n" } `, ); @@ -304,16 +305,16 @@ JSValue InternalModuleRegistry::createInternalModuleById(JSGlobalObject* globalO switch (id) { // JS internal modules ${moduleList - .map((id, n) => { - return `case Field::${idToEnumName(id)}: { + .map((id, n) => { + return `case Field::${idToEnumName(id)}: { INTERNAL_MODULE_REGISTRY_GENERATE(globalObject, vm, "${idToPublicSpecifierOrEnumName(id)}"_s, ${JSON.stringify( id.replace(/\.[mc]?[tj]s$/, ".js"), )}_s, InternalModuleRegistryConstants::${idToEnumName(id)}Code, "builtin://${id .replace(/\.[mc]?[tj]s$/, "") .replace(/[^a-zA-Z0-9]+/g, "/")}"_s); }`; - }) - .join("\n ")} + }) + .join("\n ")} default: { __builtin_unreachable(); } @@ -373,8 +374,8 @@ pub const ResolvedSourceTag = enum(u32) { ${moduleList.map((id, n) => ` @"${idToPublicSpecifierOrEnumName(id)}" = ${(1 << 9) | n},`).join("\n")} // Native modules run through a different system using ESM registry. ${Object.entries(nativeModuleIds) - .map(([id, n]) => ` @"${id}" = ${(1 << 10) | n},`) - .join("\n")} + .map(([id, n]) => ` @"${id}" = ${(1 << 10) | n},`) + .join("\n")} }; `, ); @@ -400,8 +401,8 @@ ${moduleList.map((id, n) => ` ${idToEnumName(id)} = ${(1 << 9) | n},`).join(" // They also have bit 10 set to differentiate them from JS builtins. NativeModuleFlag = (1 << 10) | (1 << 9), ${Object.entries(nativeModuleEnumToId) - .map(([id, n]) => ` ${id} = ${(1 << 10) | n},`) - .join("\n")} + .map(([id, n]) => ` ${id} = ${(1 << 10) | n},`) + .join("\n")} }; `, diff --git a/src/codegen/replacements.ts b/src/codegen/replacements.ts index 8195eecf2535a8..8f8581f5914600 100644 --- a/src/codegen/replacements.ts +++ b/src/codegen/replacements.ts @@ -54,7 +54,10 @@ export const globalsToPrefix = [ "undefined", ]; -replacements.push({ from: new RegExp(`\\bextends\\s+(${globalsToPrefix.join("|")})`, "g"), to: "extends __no_intrinsic__%1" }); +replacements.push({ + from: new RegExp(`\\bextends\\s+(${globalsToPrefix.join("|")})`, "g"), + to: "extends __no_intrinsic__%1", +}); // These enums map to $IdToLabel and $LabelToId // Make sure to define in ./builtins.d.ts @@ -133,7 +136,7 @@ export function applyReplacements(src: string, length: number) { let rest = src.slice(length); slice = slice.replace(/([^a-zA-Z0-9_\$])\$([a-zA-Z0-9_]+\b)/gm, `$1__intrinsic__$2`); for (const replacement of replacements) { - slice = slice.replace(replacement.from, replacement.to.replaceAll("$", "__intrinsic__").replaceAll('%', '$')); + slice = slice.replace(replacement.from, replacement.to.replaceAll("$", "__intrinsic__").replaceAll("%", "$")); } let match; if ((match = slice.match(/__intrinsic__(debug|assert)$/)) && rest.startsWith("(")) { @@ -156,17 +159,17 @@ export function applyReplacements(src: string, length: number) { } return [ slice.slice(0, match.index) + - "(IS_BUN_DEVELOPMENT?$assert(" + - checkSlice.result.slice(1, -1) + - "," + - JSON.stringify( - checkSlice.result - .slice(1, -1) - .replace(/__intrinsic__/g, "$") - .trim(), - ) + - extraArgs + - "):void 0)", + "(IS_BUN_DEVELOPMENT?$assert(" + + checkSlice.result.slice(1, -1) + + "," + + JSON.stringify( + checkSlice.result + .slice(1, -1) + .replace(/__intrinsic__/g, "$") + .trim(), + ) + + extraArgs + + "):void 0)", rest2, true, ]; diff --git a/src/js/private.d.ts b/src/js/private.d.ts index 6a31ffc4ecc174..f79ded7f4565c4 100644 --- a/src/js/private.d.ts +++ b/src/js/private.d.ts @@ -46,8 +46,8 @@ type BunFS = Omit, ): BunFSWatcher;