mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
fix: strip import options when bundling with applied loader
This commit is contained in:
@@ -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(")");
|
||||
|
||||
@@ -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:");
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user