@@ -138,18 +138,24 @@ public void process(Node externs, Node root) {
138
138
NodeTraversal .traverseRoots (
139
139
compiler , new NormalizeStatements (compiler , assertOnChange ), externs , root );
140
140
141
- removeDuplicateDeclarations (externs , root );
142
-
143
- new PropagateConstantPropertyOverVars (compiler , assertOnChange ).process (externs , root );
141
+ NodeTraversal .builder ()
142
+ .setCompiler (compiler )
143
+ .setCallback (new PropagateConstantPropertyOverVars (compiler , assertOnChange ))
144
+ .setScopeCreator (new SyntacticScopeCreator (compiler , new DuplicateDeclarationHandler ()))
145
+ .traverseRoots (externs , root );
144
146
145
147
if (!compiler .getLifeCycleStage ().isNormalized ()) {
146
148
compiler .setLifeCycleStage (LifeCycleStage .NORMALIZED );
147
149
}
148
150
}
149
151
150
- /** Propagate constant annotations and IS_CONSTANT_NAME property over the Var graph. */
151
- static class PropagateConstantPropertyOverVars extends AbstractPostOrderCallback
152
- implements CompilerPass {
152
+ /**
153
+ * Propagate constant annotations and IS_CONSTANT_NAME property over the Var graph.
154
+ *
155
+ * <p>Also invokes t.getScope() on every scope, for use with the {@link
156
+ * DuplicateDeclarationHandler}.
157
+ */
158
+ private static class PropagateConstantPropertyOverVars implements NodeTraversal .ScopedCallback {
153
159
private final AbstractCompiler compiler ;
154
160
private final boolean assertOnChange ;
155
161
@@ -159,8 +165,20 @@ static class PropagateConstantPropertyOverVars extends AbstractPostOrderCallback
159
165
}
160
166
161
167
@ Override
162
- public void process (Node externs , Node root ) {
163
- NodeTraversal .traverseRoots (compiler , this , externs , root );
168
+ public void enterScope (NodeTraversal t ) {
169
+ // Cause the scope to be created, which will cause duplicate
170
+ // to be found.
171
+ t .getScope ();
172
+ }
173
+
174
+ @ Override
175
+ public void exitScope (NodeTraversal t ) {
176
+ // Nothing to do.
177
+ }
178
+
179
+ @ Override
180
+ public boolean shouldTraverse (NodeTraversal t , Node n , Node parent ) {
181
+ return true ;
164
182
}
165
183
166
184
@ Override
@@ -670,15 +688,6 @@ private static Node addToFront(Node parent, Node newChild, Node after) {
670
688
}
671
689
}
672
690
673
- /** Remove duplicate VAR declarations. */
674
- private void removeDuplicateDeclarations (Node externs , Node root ) {
675
- NodeTraversal .builder ()
676
- .setCompiler (compiler )
677
- .setCallback (new ScopeTicklingCallback ())
678
- .setScopeCreator (new SyntacticScopeCreator (compiler , new DuplicateDeclarationHandler ()))
679
- .traverseRoots (externs , root );
680
- }
681
-
682
691
/** ScopeCreator duplicate declaration handler. */
683
692
private final class DuplicateDeclarationHandler
684
693
implements SyntacticScopeCreator .RedeclarationHandler {
@@ -752,29 +761,4 @@ private void replaceVarWithAssignment(Node n, Node parent, Node grandparent) {
752
761
}
753
762
}
754
763
}
755
-
756
- /** A simple class that causes scope to be created. */
757
- private static final class ScopeTicklingCallback implements NodeTraversal .ScopedCallback {
758
- @ Override
759
- public void enterScope (NodeTraversal t ) {
760
- // Cause the scope to be created, which will cause duplicate
761
- // to be found.
762
- t .getScope ();
763
- }
764
-
765
- @ Override
766
- public void exitScope (NodeTraversal t ) {
767
- // Nothing to do.
768
- }
769
-
770
- @ Override
771
- public boolean shouldTraverse (NodeTraversal nodeTraversal , Node n , Node parent ) {
772
- return true ;
773
- }
774
-
775
- @ Override
776
- public void visit (NodeTraversal t , Node n , Node parent ) {
777
- // Nothing to do.
778
- }
779
- }
780
764
}
0 commit comments