New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate contiguous var declarations in destructuring transform #4690
Conversation
Current coverage is 88.82% (diff: 100%)@@ master #4690 diff @@
==========================================
Files 195 195
Lines 13794 13812 +18
Methods 1427 1427
Messages 0 0
Branches 3176 3181 +5
==========================================
+ Hits 12254 12269 +15
- Misses 1540 1543 +3
Partials 0 0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, looks good!
should we early return on !nodes.length
?
I don't think that would ever be hit. Actually, I think the |
I'm not sure yet either - we can do a fix in another PR as followup though? |
const nodesOut = []; | ||
for (const node of nodes) { | ||
const tail = nodesOut[nodesOut.length - 1]; | ||
if (tail && tail.kind === node.kind) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't tail.kind === node.kind
always true. Which then also leads to nodesOut.length
always having one element as already mentioned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right I think that's what @motiz88 was getting at in the comment ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should clean it up before merging, so we don't forget it later :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of my recent findings when trying to simplify this - I've had to make this even more verbose in 46087c6 as it is actually not correct to assume that either tail
or node
are VariableDeclarations, nor that they have the same kind
.
On it. On Oct 12, 2016 11:33, "Daniel Tschinder" notifications@github.com wrote:
|
Okay, seems like my assumption that So at this point, I think optimizing beyond what we had in 94a6b23 would require some serious (painful) digging around in |
…abel#4690) * Consolidate contiguous var declarations in destructuring transform Fixes babel#3081. * Simplify var node coalescing in es2015-destructuring * Revert "Simplify var node coalescing in es2015-destructuring" This reverts commit 15cb373. * More careful condition for var coalescing in es2015-destructuring
…abel#4690) * Consolidate contiguous var declarations in destructuring transform Fixes babel#3081. * Simplify var node coalescing in es2015-destructuring * Revert "Simplify var node coalescing in es2015-destructuring" This reverts commit 15cb373. * More careful condition for var coalescing in es2015-destructuring
Fixes #3081 by never trying to inject multiple VariableDeclaration nodes into a
for
loop's init clause - we now always deduplicate them to a single node because they will all have the samekind
. The order is maintained so execution order of any init expressions is the same.This solution has the stylistic side effect of reducing the number of
var
s in the output, and neatly mapping each input declaration to one grouped output declaration.I purposely didn't touch the core destructuring logic in any way and implemented this as a second pass over the generated
nodes
array. If anyone prefers a different implementation, let me know!