Skip to content

Commit b73a20e

Browse files
fix(javascript): group a dropped console call where a unary cannot stand
`console.log()**2` and `console.log().a` printed `void 0**2` and `void 0.a`, which do not parse. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent 74bbfb5 commit b73a20e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13783,7 +13783,12 @@ const createNodePrinter = (modules) => {
1378313783
for (let i = 0; i < count; i++) {
1378413784
skipNode(itemOf(i, Field.arguments, node));
1378513785
}
13786-
output.print("void 0");
13786+
// A call `new` constructs is already parenthesized.
13787+
output.print(
13788+
takesUnary(node) || typeOf(parentAt(0)) === NodeType.NewExpression
13789+
? "void 0"
13790+
: "(void 0)"
13791+
);
1378713792
return;
1378813793
}
1378913794
const joined =

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,13 @@ describe("JavaScript minifier printing a SyntaxTree", () => {
17021702
drop_console: true
17031703
})
17041704
).toBe("if(a);for(;;);x=void 0;");
1705+
// Where a unary cannot stand, it is grouped.
1706+
expect(
1707+
print(
1708+
"x=console.log()**2;y=console.log().a;z=console.log()();w=new(console.log());",
1709+
{ drop_console: true }
1710+
)
1711+
).toBe("x=(void 0)**2;y=(void 0).a;z=(void 0)();w=new(void 0);");
17051712
// So is one called through `call` or `apply`.
17061713
expect(
17071714
print("console.log.call(console,a);console.log.apply(console,b);g();", {

0 commit comments

Comments
 (0)