diff options
author | 2023-09-14 00:39:36 -0400 | |
---|---|---|
committer | 2023-09-13 21:39:36 -0700 | |
commit | 9976e3f528bae74667a2f4742c4b165b7f68c76d (patch) | |
tree | eb4a123f5c533f73559f894bff77d5db65906a56 /src/js/_codegen/build-functions.ts | |
parent | fbafbd3394a2c1a1112df148fa2b151ee0955cc5 (diff) | |
download | bun-9976e3f528bae74667a2f4742c4b165b7f68c76d.tar.gz bun-9976e3f528bae74667a2f4742c4b165b7f68c76d.tar.zst bun-9976e3f528bae74667a2f4742c4b165b7f68c76d.zip |
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
Diffstat (limited to 'src/js/_codegen/build-functions.ts')
-rw-r--r-- | src/js/_codegen/build-functions.ts | 26 |
1 files changed, 4 insertions, 22 deletions
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({ |