Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/js_optimizer/JSDCE-objectPattern-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ let z = 50;
globalThis.f = function([, r]) {
let {a, b} = r;
let {z: c} = r;
let [, i, {foo: p, bar: q}] = r;
return g(a, b, c, d, z);
};

Expand Down
21 changes: 10 additions & 11 deletions tools/acorn-optimizer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,16 @@ function JSDCE(ast, aggressive) {
let removedHere = 0;
node.declarations = node.declarations.filter((node) => {
assert(node.type === 'VariableDeclarator');
const id = node.id;
if (id.type === 'ObjectPattern' || id.type === 'ArrayPattern') {
// TODO: DCE into object patterns, that is, things like
// let { a, b } = ..
// let [ a, b ] = ..
return true;
}
assert(id.type === 'Identifier');
const curr = id.name;
const value = node.init;
const keep = !names.has(curr) || (value && hasSideEffects(value));
let keep = node.init && hasSideEffects(node.init);
walkPattern(
node.id,
(value) => {
keep ||= hasSideEffects(value);
},
(boundName) => {
keep ||= !names.has(boundName);
},
);
if (!keep) removedHere = 1;
return keep;
});
Expand Down