From 9976e3f528bae74667a2f4742c4b165b7f68c76d Mon Sep 17 00:00:00 2001 From: dave caruso Date: Thu, 14 Sep 2023 00:39:36 -0400 Subject: fix(runtime): make most globals configurable/deletable, allow resuming the console iterator (#5216) * Fix #5177 * Fix #5175 * make most globals deletable/overridable * not done * cool * a * done * fix test * oops * yippee --- src/js/_codegen/build-functions.ts | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src/js/_codegen/build-functions.ts') diff --git a/src/js/_codegen/build-functions.ts b/src/js/_codegen/build-functions.ts index 761682d44..fcce0263a 100644 --- a/src/js/_codegen/build-functions.ts +++ b/src/js/_codegen/build-functions.ts @@ -1,7 +1,7 @@ -import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "fs"; +import { existsSync, mkdirSync, readdirSync, rmSync } from "fs"; import path from "path"; import { sliceSourceCode } from "./builtin-parser"; -import { applyGlobalReplacements, enums, globalsToPrefix } from "./replacements"; +import { applyGlobalReplacements, define } from "./replacements"; import { cap, fmtCPPString, low } from "./helpers"; import { spawn } from "bun"; @@ -48,24 +48,6 @@ const TMP_DIR = path.join(SRC_DIR, "../out/tmp/builtins"); if (existsSync(TMP_DIR)) rmSync(TMP_DIR, { recursive: true }); mkdirSync(TMP_DIR, { recursive: true }); -const define = { - "process.env.NODE_ENV": "production", - "IS_BUN_DEVELOPMENT": "false", -}; - -for (const name in enums) { - const value = enums[name]; - if (typeof value !== "object") throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); - if (typeof value === null) throw new Error("Invalid enum object " + name + " defined in " + import.meta.file); - const keys = Array.isArray(value) ? value : Object.keys(value).filter(k => !k.match(/^[0-9]+$/)); - define[`__intrinsic__${name}IdToLabel`] = "[" + keys.map(k => `"${k}"`).join(", ") + "]"; - define[`__intrinsic__${name}LabelToId`] = "{" + keys.map(k => `"${k}": ${keys.indexOf(k)}`).join(", ") + "}"; -} - -for (const name of globalsToPrefix) { - define[name] = "__intrinsic__" + name; -} - interface ParsedBuiltin { name: string; params: string[]; @@ -218,7 +200,7 @@ $$capture_start$$(${fn.async ? "async " : ""}${ const build = await Bun.build({ entrypoints: [tmpFile], define, - minify: { syntax: true, whitespace: true }, + minify: { syntax: true, whitespace: false }, }); if (!build.success) { throw new AggregateError(build.logs, "Failed bundling builtin function " + fn.name + " from " + basename + ".ts"); @@ -231,7 +213,7 @@ $$capture_start$$(${fn.async ? "async " : ""}${ const finalReplacement = (fn.directives.sloppy ? captured : captured.replace(/function\s*\(.*?\)\s*{/, '$&"use strict";')) .replace(/^\((async )?function\(/, "($1function (") - .replace(/__intrinsic__lazy\(/g, "globalThis[globalThis.Symbol.for('Bun.lazy')](") + // .replace(/__intrinsic__lazy\(/g, "globalThis[globalThis.Symbol.for('Bun.lazy')](") .replace(/__intrinsic__/g, "@") + "\n"; bundledFunctions.push({ -- cgit v1.2.3