Skip to content

Commit 4ab56a2

Browse files
1 parent 5f55eb1 commit 4ab56a2

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22591,7 +22591,8 @@ const installImprove = (modules) => {
2259122591
// Iterating a hole reads its index through `Array.prototype`.
2259222592
if (!element || A.isExpansionNode(element)) return;
2259322593
if (self.callee.name === "Map") {
22594-
if (!A.isArrayNode(element)) return;
22594+
// An entry reads its key and value at 0 and 1, holes included.
22595+
if (!A.isArrayNode(element) || element.elements.length < 2) return;
2259522596
for (const value of /** @type {(Node | null)[]} */ (element.elements)) {
2259622597
if (!value || A.isExpansionNode(value)) return;
2259722598
values.push(value);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ const IMPROVED_CASES = [
20742074
const KEPT_CASES = [
20752075
["a computed key of a loop head's pattern, which the body writes", 'function f(o) { let k = 1; for ({ [k]: x } of o) { console.log(x); k = 2; } } var x; f([{ 1: "a", 2: "b" }, { 1: "c", 2: "d" }]);'],
20762076
["a `concat` of an array literal with a hole, which reads its index through `Array.prototype`", "console.log([, 1].concat(2).length, 0 in [, 1].concat(2), [1].concat([, 2]).length);"],
2077+
["a `Map` entry missing its value, which reads index 1 through `Array.prototype`", "function a() { console.log(1); return 1; } new Map([[a()]]);"],
20772078
["a `Set` built from an array literal where a direct `eval` may rebind `Set`", 'function f() { eval("var Set = function () { console.log(1); }"); new Set([1]); } f();'],
20782079
["a `Set` built from an array literal where a `with` object may rebind `Set`", "with ({ Set: function () { console.log(1); } }) { new Set([1]); }"],
20792080
["an element of an array literal written through as a property of a destructuring assignment", "var a = 1, value = { x: 5 }; ({ x: [a][0] } = value); console.log(a);"],

0 commit comments

Comments
 (0)