diff --git a/src/bundler/linker_context/OutputFileListBuilder.zig b/src/bundler/linker_context/OutputFileListBuilder.zig index f38725ef56..57add5ba66 100644 --- a/src/bundler/linker_context/OutputFileListBuilder.zig +++ b/src/bundler/linker_context/OutputFileListBuilder.zig @@ -60,6 +60,8 @@ pub fn init( pub fn take(this: *@This()) std.ArrayList(options.OutputFile) { // TODO: should this return an error bun.assertf(this.total_insertions == this.output_files.items.len, "total_insertions ({d}) != output_files.items.len ({d})", .{ this.total_insertions, this.output_files.items.len }); + // Set the length just in case so the list doesn't have undefined memory + this.output_files.items.len = this.total_insertions; const list = this.output_files; this.output_files = std.ArrayList(options.OutputFile).init(bun.default_allocator); return list; @@ -78,21 +80,14 @@ pub fn calculateOutputFileListCapacity(c: *const bun.bundle_v2.LinkerContext, ch const bytecode_count = if (c.options.generate_bytecode_cache) bytecode_count: { var bytecode_count: usize = 0; for (chunks) |*chunk| { - // TODO: this was the original logic, but it seems like it is - // incorrect / does unnecessary work? Leaving it here just in-case, - // as it moved from a different file and is not git blame-able. - // - // const loader: Loader = if (chunk.entry_point.is_entry_point) - // c.parse_graph.input_files.items(.loader)[ - // chunk.entry_point.source_index - // ] - // else - // .js; - // if (loader.isJavaScriptLike()) { - // bytecode_count += 1; - // } + const loader: bun.options.Loader = if (chunk.entry_point.is_entry_point) + c.parse_graph.input_files.items(.loader)[ + chunk.entry_point.source_index + ] + else + .js; - if (chunk.content == .javascript) { + if (chunk.content == .javascript and loader.isJavaScriptLike()) { bytecode_count += 1; } } diff --git a/src/bundler/linker_context/generateChunksInParallel.zig b/src/bundler/linker_context/generateChunksInParallel.zig index 183b25e007..1cc1a05bf1 100644 --- a/src/bundler/linker_context/generateChunksInParallel.zig +++ b/src/bundler/linker_context/generateChunksInParallel.zig @@ -427,7 +427,7 @@ pub fn generateChunksInParallel( else .js; - if (loader.isJavaScriptLike()) { + if (chunk.content == .javascript and loader.isJavaScriptLike()) { jsc.VirtualMachine.is_bundler_thread_for_bytecode_cache = true; jsc.initialize(false); var fdpath: bun.PathBuffer = undefined; diff --git a/test/bundler/bundler_compile.test.ts b/test/bundler/bundler_compile.test.ts index b07a37c313..aabfe30570 100644 --- a/test/bundler/bundler_compile.test.ts +++ b/test/bundler/bundler_compile.test.ts @@ -1,7 +1,7 @@ import { Database } from "bun:sqlite"; -import { describe, expect } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { rmSync } from "fs"; -import { isWindows } from "harness"; +import { bunEnv, bunExe, isWindows, tempDirWithFiles } from "harness"; import { itBundled } from "./expectBundled"; describe("bundler", () => { @@ -665,4 +665,70 @@ error: Hello World`, }, ], }); + + test("does not crash", async () => { + const dir = tempDirWithFiles("bundler-compile-shadcn", { + "frontend.tsx": `console.log("Hello, world!");`, + "index.html": ` + +
+ + +