emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.83k stars 3.31k forks source link

`for (const [x, y] of Object.entries)` syntex not supported by acorn-optimizer.js #18373

Open sbc100 opened 1 year ago

sbc100 commented 1 year ago

After the JSDCE pass this seems to be become for (; of Object.entries)

sbc100 commented 1 year ago

The code where I was planning on using this no longer needs it .. so this is not urgent.

kripken commented 1 year ago

This likely needs an upgrade of the Acorn parser.

staticfinal commented 1 year ago

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.

staticfinal commented 1 year ago

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.