Skip to content

Commit 25125ce

Browse files
authored
Fix acorn-optimizer error when destructuring array with empty elements (emscripten-core#21501)
This fixes cases like this: function ([, a]) { } In such arrays it is possible to have empty elements, which must be skipped.
1 parent aa0079f commit 25125ce

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

test/optimizer/JSDCE-objectPattern-output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let d = 40;
22

33
let z = 50;
44

5-
globalThis.f = function(r) {
5+
globalThis.f = function([, r]) {
66
let {a: a, b: b} = r;
77
let {z: c} = r;
88
let [, i, {foo: p, bar: q}] = r;

test/optimizer/JSDCE-objectPattern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let d = 40;
1010
// z.
1111
let z = 50;
1212

13-
globalThis.f = function(r) {
13+
globalThis.f = function([/*empty*/, r]) {
1414
let { a, b } = r;
1515
let { z: c } = r;
1616
let [/*empty*/, i, {foo : p, bar : q}] = r;

tools/acorn-optimizer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ function runJSDCE(ast, aggressive) {
388388
}
389389
if (param.type === 'ArrayPattern') {
390390
for (var elem of param.elements) {
391-
traverse(elem);
391+
if (elem) traverse(elem);
392392
}
393393
} else if (param.type === 'ObjectPattern') {
394394
for (var prop of param.properties) {

0 commit comments

Comments
 (0)