Skip to content

Commit 7b402f3

Browse files
1 parent e308d7f commit 7b402f3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25371,7 +25371,6 @@ const installImprove = (modules) => {
2537125371
if (A.isSymbolRefNode(node)) return node.name;
2537225372
if (
2537325373
!A.isPropAccessNode(node) ||
25374-
node.optional ||
2537525374
!A.isSymbolRefNode(node.object) ||
2537625375
!GLOBAL_OBJECT_NAMES.has(node.object.name)
2537725376
) {
@@ -25394,7 +25393,6 @@ const installImprove = (modules) => {
2539425393
*/
2539525394
const writtenPrototypeOf = (node, walker) => {
2539625395
if (
25397-
node.optional ||
2539825396
(A.isSubNode(node)
2539925397
? constantOf(node.property)
2540025398
: A.terserProperty(node)) !== "prototype"
@@ -25418,6 +25416,11 @@ const installImprove = (modules) => {
2541825416
const writesThrough = (node, walker) => {
2541925417
const parent = walker.parent(0);
2542025418
if (A.isCallNode(parent)) return parent.callee !== node;
25419+
// `f(globalThis?.Array.prototype)` hands the call the chain around it.
25420+
if (A.isChainNode(parent)) {
25421+
const call = walker.parent(1);
25422+
return A.isCallNode(call) && call.callee !== parent;
25423+
}
2542125424
return (
2542225425
A.isPropAccessNode(parent) &&
2542325426
parent.object === node &&

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8981,7 +8981,9 @@ describe("syntax-printer", () => {
89818981
'[globalThis.Number] = [function () { return 7; }]; console.log(Number("3"));',
89828982
'({ n: globalThis.Number } = { n: function () { return 7; } }); console.log(Number("3"));',
89838983
'Object.defineProperty(globalThis, "Number", { value: function () { return 7; } }); console.log(Number("3"));',
8984-
'[globalThis.Array.prototype.slice] = [function () { return "patched"; }]; console.log([1, 2].slice());'
8984+
'[globalThis.Array.prototype.slice] = [function () { return "patched"; }]; console.log([1, 2].slice());',
8985+
'Object.defineProperty(globalThis?.Array.prototype, "slice", { value: function () { return "S"; } }); console.log([1, 2].slice());',
8986+
'Object.defineProperty(Array?.prototype, "slice", { value: function () { return "S"; } }); console.log([1, 2].slice());'
89858987
]) {
89868988
const { code } = await minify(input, { compress: {}, mangle: false });
89878989
expect(runProgram(/** @type {string} */ (code))).toBe(runProgram(input));

0 commit comments

Comments
 (0)