Skip to content

Commit 2ea5a1f

Browse files
fix(javascript): keep a reduced call a value where typeof, delete or a call reads a reference
A call printed as the name or member it returns stays a value in the one pass, so `typeof` still throws on an undeclared name, `delete` removes nothing and a returned method is called without its object. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent 0da03bd commit 2ea5a1f

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65256,11 +65256,14 @@ const createNodePrinter = (modules) => {
6525665256
const fn = reducedCalls.size === 0 ? undefined : reducedCalls.get(node);
6525765257
if (fn !== undefined) {
6525865258
// The function called prints as the value it returns.
65259-
const parens = reducedParens(
65260-
node,
65261-
/** @type {number} */ (reducing.get(fn))
65262-
);
65259+
const value = /** @type {number} */ (reducing.get(fn));
65260+
// A name or member read where `typeof`, `delete` or a call reads a
65261+
// reference stays a value, as the call's result was.
65262+
const reference =
65263+
fn === childOf(Field.callee, node) && readsReference(value, node);
65264+
const parens = reference || reducedParens(node, value);
6526365265
if (parens) output.print("(");
65266+
if (reference) output.print("0,");
6526465267
printNode(childOf(Field.callee, node));
6526565268
if (parens) output.print(")");
6526665269
const count = tree.fieldCount(Field.arguments, node);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15244,6 +15244,11 @@ describe("JavaScript minifier printing a SyntaxTree", () => {
1524415244
{},
1524515245
"function f(n,t){n=2;return[(n=>n+1)(n),(n=>()=>n)(t),function(){return this}(),function n(){return n}(),(async()=>1)(),(n=>n)(t,t),(()=>1)?.()]}"
1524615246
],
15247+
[
15248+
"function f(o) { return [typeof (function () { return undeclaredX })(), delete (() => o.p)(), ((x) => x.m)(o)()] }",
15249+
{},
15250+
"function f(e){return[typeof(0,undeclaredX),delete(0,e.p),(0,e.m)()]}"
15251+
],
1524715252
[
1524815253
"function f(a){ if (0) x(); Math.PI }",
1524915254
{ compress: {toplevel: false,builtins_ecma: 2020},format: {comments: false} },

0 commit comments

Comments
 (0)