From c0cc12b92685a54c5def768c86003d2a04191058 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 10 Mar 2024 22:50:45 +0900 Subject: [PATCH] Fix acorn-optimizer error when destructuring array including empty element in function parameters It will fix a problem similar to #20843. #20843 fixed this case: ```javascript [, a] = x; ``` This commit will fix this case: ```javascript function ([, a]) { } ``` --- test/optimizer/JSDCE-objectPattern-output.js | 2 +- test/optimizer/JSDCE-objectPattern.js | 2 +- tools/acorn-optimizer.mjs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/optimizer/JSDCE-objectPattern-output.js b/test/optimizer/JSDCE-objectPattern-output.js index 7aa8f6136f2fb..a797a6a24bc89 100644 --- a/test/optimizer/JSDCE-objectPattern-output.js +++ b/test/optimizer/JSDCE-objectPattern-output.js @@ -2,7 +2,7 @@ let d = 40; let z = 50; -globalThis.f = function(r) { +globalThis.f = function([, r]) { let {a: a, b: b} = r; let {z: c} = r; let [, i, {foo: p, bar: q}] = r; diff --git a/test/optimizer/JSDCE-objectPattern.js b/test/optimizer/JSDCE-objectPattern.js index 934791538ab69..4d26827f47ada 100644 --- a/test/optimizer/JSDCE-objectPattern.js +++ b/test/optimizer/JSDCE-objectPattern.js @@ -10,7 +10,7 @@ let d = 40; // z. let z = 50; -globalThis.f = function(r) { +globalThis.f = function([/*empty*/, r]) { let { a, b } = r; let { z: c } = r; let [/*empty*/, i, {foo : p, bar : q}] = r; diff --git a/tools/acorn-optimizer.mjs b/tools/acorn-optimizer.mjs index f877761d636eb..e808a0058ac89 100755 --- a/tools/acorn-optimizer.mjs +++ b/tools/acorn-optimizer.mjs @@ -388,7 +388,7 @@ function runJSDCE(ast, aggressive) { } if (param.type === 'ArrayPattern') { for (var elem of param.elements) { - traverse(elem); + if (elem) traverse(elem); } } else if (param.type === 'ObjectPattern') { for (var prop of param.properties) {