Code with Finding: |
class Normalize {
@Override
public void process(Node externs, Node root) {
NodeTraversal.traverse(compiler, root,
new NormalizeStatements(compiler, assertOnChange));
if (MAKE_LOCAL_NAMES_UNIQUE) {
MakeDeclaredNamesUnique renamer = new MakeDeclaredNamesUnique();
NodeTraversal t = new NodeTraversal(compiler, renamer);
t.traverseRoots(externs, root);
}
// It is important that removeDuplicateDeclarations runs after
// MakeDeclaredNamesUnique in order for catch block exception names to be
// handled properly. Specifically, catch block exception names are
// only valid within the catch block, but our currect Scope logic
// has no concept of this and includes it in the containing function
// (or global scope). MakeDeclaredNamesUnique makes the catch exception
// names unique so that removeDuplicateDeclarations() will properly handle
// cases where a function scope variable conflict with a exception name:
// function f() {
// try {throw 0;} catch(e) {e; /* catch scope 'e'*/}
// var e = 1; // f scope 'e'
// }
// otherwise 'var e = 1' would be rewritten as 'e = 1'.
// TODO(johnlenz): Introduce a seperate scope for catch nodes.
removeDuplicateDeclarations(externs, root);
new PropagateConstantAnnotationsOverVars(compiler, assertOnChange)
.process(externs, root);
if (!compiler.getLifeCycleStage().isNormalized()) {
compiler.setLifeCycleStage(LifeCycleStage.NORMALIZED);
}
}
}
class Normalize.PropagateConstantAnnotationsOverVars {
@Override
public void process(Node externs, Node root) {
new NodeTraversal(compiler, this).traverseRoots(externs, root);
}
}
class Normalize.VerifyConstants {
@Override
public void process(Node externs, Node root) {
Node externsAndJs = root.getParent();
Preconditions.checkState(externsAndJs != null);
Preconditions.checkState(externsAndJs.hasChild(externs));
NodeTraversal.traverseRoots(
compiler, Lists.newArrayList(externs, root), this);
}
}
|