static class Normalize.NormalizeStatements extends java.lang.Object implements NodeTraversal.Callback
Modifier and Type | Field and Description |
---|---|
private boolean |
assertOnChange |
private AbstractCompiler |
compiler |
Constructor and Description |
---|
NormalizeStatements(AbstractCompiler compiler,
boolean assertOnChange) |
Modifier and Type | Method and Description |
---|---|
private static Node |
addToFront(Node parent,
Node newChild,
Node after) |
private void |
annotateConstantsByConvention(Node n,
Node parent)
Mark names and properties that are constants by convention.
|
private void |
doStatementNormalizations(Node n)
Do normalizations that introduce new siblings or parents.
|
private void |
extractForInitializer(Node n,
Node before,
Node beforeParent)
Bring the initializers out of FOR loops.
|
(package private) static boolean |
maybeNormalizeFunctionDeclaration(Node n)
Rewrite named unhoisted functions declarations to a known
consistent behavior so we don't to different logic paths for the same
code.
|
private void |
moveNamedFunctions(Node functionBody)
Move all the functions that are valid at the execution of the first
statement of the function to the beginning of the function definition.
|
private void |
normalizeLabels(Node n)
Limit the number of special cases where LABELs need to be handled.
|
private void |
reportCodeChange(java.lang.String changeDescription) |
private static void |
rewriteFunctionDeclaration(Node n)
Rewrite the function declaration from:
function x() {}
FUNCTION
NAME
LP
BLOCK
to:
var x = function() {};
VAR
NAME
FUNCTION
NAME (w/ empty string)
LP
BLOCK
|
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed.
|
private void |
splitVarDeclarations(Node n)
Split a var node such as:
var a, b;
into individual statements:
var a;
var b;
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private final AbstractCompiler compiler
private final boolean assertOnChange
NormalizeStatements(AbstractCompiler compiler, boolean assertOnChange)
private void reportCodeChange(java.lang.String changeDescription)
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed. If children are
traversed, they will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)
in postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
private void annotateConstantsByConvention(Node n, Node parent)
static boolean maybeNormalizeFunctionDeclaration(Node n)
https://github.com/google/closure-compiler/pull/429
private static void rewriteFunctionDeclaration(Node n)
private void doStatementNormalizations(Node n)
private void normalizeLabels(Node n)
private void extractForInitializer(Node n, Node before, Node beforeParent)
n
- The node to inspect.before
- The node to insert the initializer before.beforeParent
- The parent of the node before which the initializer
will be inserted.private void splitVarDeclarations(Node n)
n
- The whose children we should inspect.private void moveNamedFunctions(Node functionBody)