Skip to content

Commit

Permalink
Simplify var node coalescing in es2015-destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Oct 13, 2016
1 parent 94a6b23 commit 15cb373
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions packages/babel-plugin-transform-es2015-destructuring/src/index.js
Expand Up @@ -492,21 +492,14 @@ export default function ({ types: t }) {
}
}

const nodesOut = [];
// NOTE(motiz88): Here, nodes are all `VariableDeclaration`s with the same `kind`. We make a single node out of them.

const declarations = [];
for (const node of nodes) {
const tail = nodesOut[nodesOut.length - 1];
if (tail && tail.kind === node.kind) {
tail.declarations.push(...node.declarations);
} else {
nodesOut.push(node);
}
declarations.push(...node.declarations);
}

if (nodesOut.length === 1) {
path.replaceWith(nodesOut[0]);
} else {
path.replaceWithMultiple(nodesOut);
}
path.replaceWith(t.variableDeclaration(node.kind, declarations));
}
}
};
Expand Down

0 comments on commit 15cb373

Please sign in to comment.