diff --git a/src/interchange/json.zig b/src/interchange/json.zig index bec03a2501..c150d78078 100644 --- a/src/interchange/json.zig +++ b/src/interchange/json.zig @@ -170,6 +170,7 @@ fn JSONLikeParser_( try p.lexer.next(); var is_single_line = !p.lexer.has_newline_before; var exprs = std.ArrayList(Expr).init(p.list_allocator); + errdefer exprs.deinit(); while (p.lexer.token != .t_close_bracket) { if (exprs.items.len > 0) { @@ -203,6 +204,7 @@ fn JSONLikeParser_( try p.lexer.next(); var is_single_line = !p.lexer.has_newline_before; var properties = std.ArrayList(G.Property).init(p.list_allocator); + errdefer properties.deinit(); const DuplicateNodeType = comptime if (opts.json_warn_duplicate_keys) *HashMapPool.LinkedList.Node else void; const HashMapType = comptime if (opts.json_warn_duplicate_keys) HashMapPool.HashMap else void; diff --git a/test/bundler/bundler_compile.test.ts b/test/bundler/bundler_compile.test.ts index aabfe30570..766e2a7fed 100644 --- a/test/bundler/bundler_compile.test.ts +++ b/test/bundler/bundler_compile.test.ts @@ -106,6 +106,7 @@ describe("bundler", () => { run: { stdout: "Hello, world!" }, }); itBundled("compile/WorkerRelativePathNoExtension", { + backend: "cli", compile: true, files: { "/entry.ts": /* js */ ` @@ -125,6 +126,7 @@ describe("bundler", () => { run: { stdout: "Hello, world!\nWorker loaded!\n", file: "dist/out", setCwd: true }, }); itBundled("compile/WorkerRelativePathTSExtension", { + backend: "cli", compile: true, files: { "/entry.ts": /* js */ ` @@ -143,6 +145,7 @@ describe("bundler", () => { run: { stdout: "Hello, world!\nWorker loaded!\n", file: "dist/out", setCwd: true }, }); itBundled("compile/WorkerRelativePathTSExtensionBytecode", { + backend: "cli", compile: true, bytecode: true, files: { @@ -558,6 +561,7 @@ describe("bundler", () => { }); itBundled("compile/ImportMetaMain", { compile: true, + backend: "cli", files: { "/entry.ts": /* js */ ` // test toString on function to observe what the inlined value was diff --git a/test/bundler/bundler_edgecase.test.ts b/test/bundler/bundler_edgecase.test.ts index 9cfd6b48cd..c865688719 100644 --- a/test/bundler/bundler_edgecase.test.ts +++ b/test/bundler/bundler_edgecase.test.ts @@ -274,6 +274,7 @@ describe("bundler", () => { "/entry.js": /* js */ `console.log(1)`, }, outdir: "/out", + backend: "cli", loader: { ".cool": "wtf", }, @@ -2071,6 +2072,7 @@ describe("bundler", () => { }); itBundled("edgecase/OutWithTwoFiles", { + backend: "cli", files: { "/entry.ts": ` import index from './index.html' with { type: 'file' } diff --git a/test/bundler/bundler_footer.test.ts b/test/bundler/bundler_footer.test.ts index 3f79d46fe5..aead8c3388 100644 --- a/test/bundler/bundler_footer.test.ts +++ b/test/bundler/bundler_footer.test.ts @@ -4,6 +4,7 @@ import { itBundled } from "./expectBundled"; describe("bundler", () => { itBundled("footer/CommentFooter", { footer: "// developed with love in SF", + backend: "cli", files: { "/a.js": `console.log("Hello, world!")`, }, @@ -16,6 +17,7 @@ describe("bundler", () => { * This is copyright of [...] ${new Date().getFullYear()} * do not redistribute without consent of [...] */`, + backend: "cli", files: { "index.js": `console.log("Hello, world!")`, }, diff --git a/test/bundler/bundler_regressions.test.ts b/test/bundler/bundler_regressions.test.ts index e4efcf36f8..845eceda6e 100644 --- a/test/bundler/bundler_regressions.test.ts +++ b/test/bundler/bundler_regressions.test.ts @@ -216,6 +216,7 @@ describe("bundler", () => { }); itBundled("regression/WindowsBackslashAssertion1#9974", { + backend: "cli", files: { "/test/entry.ts": ` import { loadFonts } from "../base"; diff --git a/test/bundler/compile-argv.test.ts b/test/bundler/compile-argv.test.ts index d81df175fe..6d7ea8d20f 100644 --- a/test/bundler/compile-argv.test.ts +++ b/test/bundler/compile-argv.test.ts @@ -7,6 +7,7 @@ describe("bundler", () => { compile: { execArgv: ["--title=CompileExecArgvDualBehavior", "--smol"], }, + backend: "cli", files: { "/entry.ts": /* js */ ` // Test that --compile-exec-argv both processes flags AND populates execArgv @@ -52,6 +53,7 @@ describe("bundler", () => { compile: { execArgv: ["--user-agent=test-agent", "--smol"], }, + backend: "cli", files: { "/entry.ts": /* js */ ` // Test that compile-exec-argv options don't appear in process.argv @@ -115,6 +117,7 @@ describe("bundler", () => { compile: { execArgv: ["--user-agent=test-agent", "--smol"], }, + backend: "cli", files: { "/entry.ts": /* js */ ` // Test that user arguments are properly included when exec argv is present diff --git a/test/bundler/esbuild/dce.test.ts b/test/bundler/esbuild/dce.test.ts index a435d9f8c2..0e67d3a550 100644 --- a/test/bundler/esbuild/dce.test.ts +++ b/test/bundler/esbuild/dce.test.ts @@ -1241,6 +1241,7 @@ describe("bundler", () => { }, minifyWhitespace: minify, emitDCEAnnotations: emitDCEAnnotations, + backend: "cli", onAfterBundle(api) { const code = api.readFile("/out.js"); expect(code).not.toContain("_yes"); // should not contain any *_yes variables diff --git a/test/bundler/expectBundled.ts b/test/bundler/expectBundled.ts index ee0ff16fc7..3720396e49 100644 --- a/test/bundler/expectBundled.ts +++ b/test/bundler/expectBundled.ts @@ -572,7 +572,22 @@ function expectBundled( return (async () => { if (!backend) { - backend = plugins !== undefined ? "api" : "cli"; + backend = + dotenv || + jsx.factory || + jsx.fragment || + jsx.runtime || + jsx.importSource || + typeof production !== "undefined" || + bundling === false || + (run && target === "node") || + emitDCEAnnotations || + bundleWarnings || + env || + run?.validate || + define + ? "cli" + : "api"; } let root = path.join( @@ -1107,7 +1122,13 @@ for (const [key, blob] of build.outputs) { configRef = buildConfig; let build: BuildOutput; try { - build = await Bun.build(buildConfig); + const cwd = process.cwd(); + process.chdir(root); + try { + build = await Bun.build(buildConfig); + } finally { + process.chdir(cwd); + } } catch (e) { if (e instanceof AggregateError) { build = {