Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions src/js_printer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,12 @@ pub mod __gated_printer {
v.left_level = Level::Call;
}
}
ExprData::EImportIdentifier(_) => {
// When minifying, a missing import prints as "void 0"
if self.options.minify_syntax {
v.left_level = Level::Call;
}
}
_ => {}
}
}
Expand Down
28 changes: 27 additions & 1 deletion test/bundler/esbuild/importstar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe } from "bun:test";
import { describe, expect } from "bun:test";
import { itBundled } from "../expectBundled";

// Tests ported from:
Expand Down Expand Up @@ -862,6 +862,32 @@ describe("bundler", () => {
"/entry.js": [`Import "foo" will always be undefined because there is no matching export in "foo.js"`],
},
});
itBundled("importstar/NamespaceImportMissingES6ExponentiationLHS", {
files: {
"/entry.js": /* js */ `
import * as ns from './foo'
// A missing import prints as "void 0" under minify_syntax, which is not
// a valid left operand of ** unless parenthesized.
console.log(ns.nope ** 2, 2 ** ns.nope, ns.x ** 2)
`,
"/foo.js": `export const x = 3`,
},
minifySyntax: true,
run: {
stdout: "NaN NaN 9",
},
bundleWarnings: {
"/entry.js": [`Import "nope" will always be undefined because there is no matching export in "foo.js"`],
},
onAfterBundle(api) {
const out = api.readFile("/out.js");
expect(out).toContain("(void 0) ** 2");
expect(out).toContain("2 ** void 0");
// The existing export and the right operand stay unwrapped.
expect(out).not.toContain("(2 ** void 0)");
expect(out).not.toMatch(/\(\w+\) \*\* 2/);
},
});
itBundled("importstar/ExportOtherCommonJS", {
files: {
"/entry.js": `export {bar} from './foo'`,
Expand Down
Loading