diff --git a/src/js_printer.zig b/src/js_printer.zig index bd662a990e..63b2203364 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -1835,9 +1835,15 @@ fn NewPrinter( p.printStringLiteralUTF8(path.pretty, false); } + // Only print import options if the loader hasn't already been applied + // When bundling with a loader applied, the transformation has already happened + // so we don't need the import options anymore if (!import_options.isMissing()) { - p.printWhitespacer(ws(", ")); - p.printExpr(import_options, .comma, .{}); + const loader_was_applied = p.options.bundling and record.loader != null; + if (!loader_was_applied) { + p.printWhitespacer(ws(", ")); + p.printExpr(import_options, .comma, .{}); + } } p.print(")"); diff --git a/test/bundler/bundler_loader.test.ts b/test/bundler/bundler_loader.test.ts index 617f95920f..c691b704e2 100644 --- a/test/bundler/bundler_loader.test.ts +++ b/test/bundler/bundler_loader.test.ts @@ -93,6 +93,25 @@ export const data = "test";`, }, run: { stdout: "executed" }, }); + + itBundled("bun/loader-text-splitting-strips-options", { + target, + splitting: true, + outdir: "/out", + files: { + "/entry.ts": /* js */ ` + const mod = await import('./data.js', { with: { type: 'text' } }); + console.write(mod.default); + `, + "/data.js": `export default "test data";`, + }, + run: { stdout: `export default "test data";` }, + onAfterBundle(api) { + const entryFile = api.readFile("/out/entry.js"); + expect(entryFile).not.toContain("with:"); + expect(entryFile).not.toContain("{ type:"); + }, + }); }); } diff --git a/test/js/bun/glob/import-meta-glob.test.ts b/test/js/bun/glob/import-meta-glob.test.ts index d40f20a732..ed58aeb9b2 100644 --- a/test/js/bun/glob/import-meta-glob.test.ts +++ b/test/js/bun/glob/import-meta-glob.test.ts @@ -580,13 +580,12 @@ describe("import.meta.glob", () => { runProc.exited, ]); - expect(exitCode).toBe(0); - expect(stderr).toBe(""); expect(exitCode).toBe(0); expect(stderr).toBe(""); expect(stdout).toContain("COUNT: 3"); expect(stdout).toContain("SCRIPT_TEXT:"); - expect(stdout).toContain('var script_default = \'console.log("This should be text, not executed!");'); + expect(stdout).toContain('console.log("This should be text, not executed!");'); + expect(stdout).toContain('export default "js-module";'); const lines = stdout.split("\n"); const shouldNotExecuteLine = lines.findIndex(line => line === "This should be text, not executed!"); expect(shouldNotExecuteLine).toBe(-1);