Skip to content

Commit e6e9f3e

Browse files
fix(minifier): keep two calls apart where the test reads a parameter arguments maps
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 7dd3ffd commit e6e9f3e

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21753,6 +21753,13 @@ const installImprove = (modules) => {
2175321753
return false;
2175421754
}
2175521755
const functionScope = definition.scope.getDefunScope();
21756+
// A sloppy parameter is also its `arguments` slot, which code elsewhere may hold.
21757+
if (
21758+
A.isSymbolFunargNode(definition.identifiers[0]) &&
21759+
A.usesArguments(functionScope.node)
21760+
) {
21761+
return false;
21762+
}
2175621763
return definition.references.every(
2175721764
(/** @type {Node} */ reference) =>
2175821765
reference.scope.getDefunScope() === functionScope

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8669,6 +8669,15 @@ describe("syntax-printer", () => {
86698669
});
86708670
}
86718671

8672+
it("should keep two calls apart where a getter may write the parameter the test reads through `arguments`", async () => {
8673+
const { minify } = await load();
8674+
const input =
8675+
'var x = { m: function (v) { return v; } }; function f(t) { x.args = arguments; return t ? x.m(1) : x.m(2); } Object.defineProperty(x, "m", { get: function () { x.args[0] = 0; return function (v) { return v; }; } }); console.log(f(1), f(0));';
8676+
const { code } = await minify(input, { compress: {}, mangle: false });
8677+
expect(runProgram(/** @type {string} */ (code))).toBe(runProgram(input));
8678+
expect(code).toContain("t?x.m(1):x.m(2)");
8679+
});
8680+
86728681
it("should keep a module's exported `const` while writing its private ones as `let`", async () => {
86738682
const { minify } = await load();
86748683
const { code } = await minify(

0 commit comments

Comments
 (0)