Open sbc100 opened 1 year ago
The code where I was planning on using this no longer needs it .. so this is not urgent.
This likely needs an upgrade of the Acorn parser.
Actually it seems all destructuring assignments are completely removed during optimization. I have the following code in one of my --pre-js
files:
const comparators = sortInfos.map((sortInfo) => {
const { property, direction } = sortInfo;
const sorter = this.comparators[property];
...
which just becomes:
const comparators = sortInfos.map((sortInfo) => {
const sorter = this.comparators[property];
....
after optimization.
I don't think this problem is related to the Acorn parser version. In arcorn-optimizer.js
there is the following code:
function cleanUp(ast, names) {
recursiveWalk(ast, {
VariableDeclaration(node, c) {
const old = node.declarations;
let removedHere = 0;
node.declarations = node.declarations.filter(function (node) {
const curr = node.id.name;
const value = node.init;
const keep = !(curr in names) || (value && hasSideEffects(value));
if (!keep) removedHere = 1;
return keep;
});
This code only works if node.id
is of type Identifier
. If node.id
is e.g. ObjectPattern
the variable curr
will be undefined and keep
becomes false
. So the destructuring assignment is removed.
After the JSDCE pass this seems to be become
for (; of Object.entries)