Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ pub struct Transpiler<'a> {
}

impl<'a> Transpiler<'a> {
/// Takes `*mut Log` (not `&'a mut`) because the same
/// `*Log` is aliased into `linker.log` / `resolver.log`; the struct
/// field is a raw pointer for that reason.
/// Takes `*mut Log` (not `&'a mut`) because the same `*Log` is aliased
/// into `options.log` / `linker.log` / `resolver.log`; the struct field
/// is a raw pointer for that reason. All four are re-pointed here: a
/// caller that moved its `Log` must not leave any of them on the old slot.
Comment thread
robobun marked this conversation as resolved.
Resolved
pub fn set_log(&mut self, log: *mut bun_ast::Log) {
self.log = log;
self.options.log = log;
self.linker.log = log;
// SAFETY: caller (`ThreadPool::Worker::create`) passes the per-worker
// arena-allocated `Log`, which outlives this `Transpiler<'a>`.
Expand Down
46 changes: 46 additions & 0 deletions test/bundler/transpiler/transpiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,52 @@ export default <>hi</>
expect(exitCode).toBe(0);
});

it("define errors after an earlier config error do not corrupt the log", async () => {
// An `external` with two `*` logs one error and construction continues.
// The four define-key errors that follow make the buffer of the log grow.
// In a child process: on a build without the fix this is a crash.
await using proc = Bun.spawn({
cmd: [
bunExe(),
"-e",
`
const define = { "0x": "1", "1x": "1", "2x": "1", "3x": "1" };
for (let i = 0; i < 20; i++) {
const t = new Bun.Transpiler({ external: ["a*b*c"], define });
if (i % 10 === 0) t.transformSync("export const a = 1;");
if (i % 10 === 9) Bun.gc(true);
}
Bun.gc(true);
console.log("constructed");
`,
],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout, stderr, exitCode, signalCode: proc.signalCode }).toEqual({
stdout: "constructed\n",
stderr: "",
exitCode: 0,
signalCode: null,
});
});

it("a define value that is not JSON throws the parser's error", () => {
let thrown;
try {
new Bun.Transpiler({ define: { a: "{" } });
} catch (e) {
thrown = e;
}
expect([thrown?.name, thrown?.level, thrown?.message]).toEqual([
"BuildMessage",
"error",
'Expected "}" but found end of file',
]);
});

it("JSX keys", () => {
var bun = new Bun.Transpiler({
loader: "jsx",
Expand Down
Loading