aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Hewitt <davidmhewitt@users.noreply.github.com> 2023-09-16 05:19:49 +0100
committerGravatar GitHub <noreply@github.com> 2023-09-15 21:19:49 -0700
commit787281ee5e752267f25922b8886700eeadd48c3a (patch)
treef6433751a2b8388ecefcd7855521197747079e20
parentcb057e61ba5cd8ab152aac3872291bf32dbf435b (diff)
downloadbun-787281ee5e752267f25922b8886700eeadd48c3a.tar.gz
bun-787281ee5e752267f25922b8886700eeadd48c3a.tar.zst
bun-787281ee5e752267f25922b8886700eeadd48c3a.zip
fix(bundler): Add a space before minified require (#5521)
Fixes #5501
-rw-r--r--src/js_printer.zig2
-rw-r--r--test/bundler/bundler_minify.test.ts21
2 files changed, 23 insertions, 0 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig
index 709672f29..15f5218ae 100644
--- a/src/js_printer.zig
+++ b/src/js_printer.zig
@@ -2179,6 +2179,7 @@ fn NewPrinter(
}
},
.e_require_call_target => {
+ p.printSpaceBeforeIdentifier();
p.addSourceMapping(expr.loc);
if (p.options.module_type == .cjs or !is_bun_platform) {
@@ -2188,6 +2189,7 @@ fn NewPrinter(
}
},
.e_require_resolve_call_target => {
+ p.printSpaceBeforeIdentifier();
p.addSourceMapping(expr.loc);
if (p.options.module_type == .cjs or !is_bun_platform) {
diff --git a/test/bundler/bundler_minify.test.ts b/test/bundler/bundler_minify.test.ts
index c984bbe67..fb6b8db7a 100644
--- a/test/bundler/bundler_minify.test.ts
+++ b/test/bundler/bundler_minify.test.ts
@@ -286,4 +286,25 @@ describe("bundler", () => {
stdout: "PASS",
},
});
+ // https://github.com/oven-sh/bun/issues/5501
+ itBundled("minify/BunRequireStatement", {
+ files: {
+ "/entry.js": /* js */ `
+ export function test(ident) {
+ return require(ident);
+ }
+
+ test("fs");
+ console.log("PASS");
+ `,
+ },
+ minifyWhitespace: true,
+ minifySyntax: true,
+ minifyIdentifiers: true,
+ target: "bun",
+ backend: "cli",
+ run: {
+ stdout: "PASS",
+ },
+ });
});