class CollapseVariableDeclarations extends java.lang.Object implements CompilerPass
var a; var b = 1; var c = 2;becomes:
var a, b = 1, c = 2;This reduces the generated code size. More optimizations are possible:
a = true; b = true; var c = true;becomes:
var c = b = a = true;
Modifier and Type | Class and Description |
---|---|
private static class |
CollapseVariableDeclarations.Collapse
Encapsulation of information about a variable declaration collapse
|
private class |
CollapseVariableDeclarations.GatherCollapses
Gathers all of the variable declarations / assignments that should be
collapsed into one.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<CollapseVariableDeclarations.Collapse> |
collapses
Collapses to do in this pass.
|
private AbstractCompiler |
compiler
Reference to JS Compiler
|
private java.util.Set<Node> |
nodesToCollapse
Nodes we've already looked at for collapsing, so that we don't look at them
again (we look ahead when examining what nodes can be collapsed, and the
node traversal may give them to us again)
|
Constructor and Description |
---|
CollapseVariableDeclarations(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private void |
applyCollapses() |
private static boolean |
isNamedParameter(Var v) |
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private final AbstractCompiler compiler
private final java.util.List<CollapseVariableDeclarations.Collapse> collapses
private final java.util.Set<Node> nodesToCollapse
CollapseVariableDeclarations(AbstractCompiler compiler)
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treeprivate static boolean isNamedParameter(Var v)
private void applyCollapses()