Debian Codegraph @

test/com/google/javascript/jscomp/RenameVarsTest.java

raw symbols SCIP
1 /*
2 * Copyright 2005 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 import com.google.common.base.Preconditions;
20 import com.google.common.collect.ImmutableMap;
21 import com.google.javascript.rhino.Node;
22
23 import java.util.*;
24
25
26 /**
27 * Tests for {@link RenameVars}.
28 */
29 public class RenameVarsTest extends CompilerTestCase {
30 private static final String DEFAULT_PREFIX = "";
31 private String prefix = DEFAULT_PREFIX;
32
33 private VariableMap previouslyUsedMap =
34 new VariableMap(ImmutableMap.<String, String>of());
35 private RenameVars renameVars;
36 private boolean withClosurePass = false;
37 private boolean localRenamingOnly = false;
38 private boolean preserveFunctionExpressionNames = false;
39 private boolean useGoogleCodingConvention = true;
40 private boolean generatePseudoNames = false;
41 private boolean shouldShadow = false;
42 private boolean withNormalize = false;
43
44 @Override
45 protected CodingConvention getCodingConvention() {
46 if (useGoogleCodingConvention) {
47 return new GoogleCodingConvention();
48 } else {
49 return CodingConventions.getDefault();
50 }
51 }
52
53 @Override
54 protected CompilerPass getProcessor(Compiler compiler) {
55 CompilerPass pass;
56 if (withClosurePass) {
57 pass = new ClosurePassAndRenameVars(compiler);
58 } else {
59 pass = renameVars = new RenameVars(compiler, prefix,
60 localRenamingOnly, preserveFunctionExpressionNames,
61 generatePseudoNames, shouldShadow,
62 previouslyUsedMap, null, null);
63 }
64
65 if (withNormalize) {
66 // Don't use the standard CompilerTestCase normalization options
67 // as renaming is a post denormalization operation, but we do still
68 // want to run the normal normalizations on the input in some cases.
69 pass = new NormalizePassWrapper(compiler, pass);
70 }
71
72 return pass;
73 }
74
75 @Override
76 protected int getNumRepetitions() {
77 return 1;
78 }
79
80 @Override
81 protected void setUp() throws Exception {
82 super.setUp();
83 previouslyUsedMap = new VariableMap(ImmutableMap.<String, String>of());
84 prefix = DEFAULT_PREFIX;
85 withClosurePass = false;
86 withNormalize = false;
87 localRenamingOnly = false;
88 preserveFunctionExpressionNames = false;
89 generatePseudoNames = false;
90 shouldShadow = false;
91
92 // TODO(johnlenz): Enable Normalize during these tests.
93 }
94
95 public void testRenameSimple() {
96 test("function Foo(v1, v2) {return v1;} Foo();",
97 "function a(b, c) {return b;} a();");
98 }
99
100 public void testRenameGlobals() {
101 test("var Foo; var Bar, y; function x() { Bar++; }",
102 "var a; var b, c; function d() { b++; }");
103 }
104
105 public void testRenameLocals() {
106 test("(function (v1, v2) {}); (function (v3, v4) {});",
107 "(function (a, b) {}); (function (a, b) {});");
108 test("function f1(v1, v2) {}; function f2(v3, v4) {};",
109 "function c(a, b) {}; function d(a, b) {};");
110 }
111
112 public void testRenameRedeclaredGlobals() {
113 test("function f1(v1, v2) {f1()};" +
114 "/** @suppress {duplicate} */" +
115 "function f1(v3, v4) {f1()};",
116 "function a(b, c) {a()};" +
117 "function a(b, c) {a()};");
118
119 localRenamingOnly = true;
120
121 test("function f1(v1, v2) {f1()};" +
122 "/** @suppress {duplicate} */" +
123 "function f1(v3, v4) {f1()};",
124 "function f1(a, b) {f1()};" +
125 "function f1(a, b) {f1()};");
126 }
127
128 public void testRecursiveFunctions1() {
129 test("var walk = function walk(node, aFunction) {" +
130 " walk(node, aFunction);" +
131 "};",
132 "var a = function a(b, c) {" +
133 " a(b, c);" +
134 "};");
135
136 localRenamingOnly = true;
137
138 test("var walk = function walk(node, aFunction) {" +
139 " walk(node, aFunction);" +
140 "};",
141 "var walk = function walk(a, b) {" +
142 " walk(a, b);" +
143 "};");
144 }
145
146 public void testRecursiveFunctions2() {
147 preserveFunctionExpressionNames = true;
148
149 test("var walk = function walk(node, aFunction) {" +
150 " walk(node, aFunction);" +
151 "};",
152 "var c = function walk(a, b) {" +
153 " walk(a, b);" +
154 "};");
155
156 localRenamingOnly = true;
157
158 test("var walk = function walk(node, aFunction) {" +
159 " walk(node, aFunction);" +
160 "};",
161 "var walk = function walk(a, b) {" +
162 " walk(a, b);" +
163 "};");
164 }
165
166 public void testRenameLocalsClashingWithGlobals() {
167 test("function a(v1, v2) {return v1;} a();",
168 "function a(b, c) {return b;} a();");
169 }
170
171 public void testRenameNested() {
172 test("function f1(v1, v2) { (function(v3, v4) {}) }",
173 "function a(b, c) { (function(d, e) {}) }");
174 test("function f1(v1, v2) { function f2(v3, v4) {} }",
175 "function a(b, c) { function d(e, f) {} }");
176 }
177
178 public void testBleedingRecursiveFunctions1() {
179 // On IE, bleeding functions will interfere with each other if
180 // they are in the same scope. In the below example, we want to be
181 // sure that a and b get separate names.
182 test("var x = function a(x) { return x ? 1 : a(1); };" +
183 "var y = function b(x) { return x ? 2 : b(2); };",
184 "var c = function b(a) { return a ? 1 : b(1); };" +
185 "var e = function d(a) { return a ? 2 : d(2); };");
186 }
187
188 public void testBleedingRecursiveFunctions2() {
189 test("function f() {" +
190 " var x = function a(x) { return x ? 1 : a(1); };" +
191 " var y = function b(x) { return x ? 2 : b(2); };" +
192 "}",
193 "function d() {" +
194 " var e = function b(a) { return a ? 1 : b(1); };" +
195 " var f = function a(c) { return c ? 2 : a(2); };" +
196 "}");
197 }
198
199 public void testBleedingRecursiveFunctions3() {
200 test("function f() {" +
201 " var x = function a(x) { return x ? 1 : a(1); };" +
202 " var y = function b(x) { return x ? 2 : b(2); };" +
203 " var z = function c(x) { return x ? y : c(2); };" +
204 "}",
205 "function f() {" +
206 " var g = function c(a) { return a ? 1 : c(1); };" +
207 " var d = function a(b) { return b ? 2 : a(2); };" +
208 " var h = function b(e) { return e ? d : b(2); };" +
209 "}");
210 }
211
212 public void testRenameWithExterns1() {
213 String externs = "var foo;";
214 test(externs, "var bar; foo(bar);", "var a; foo(a);", null, null);
215 }
216
217 public void testRenameWithExterns2() {
218 String externs = "var a;";
219 test(externs, "var b = 5", "var b = 5", null, null);
220 }
221
222 public void testDoNotRenameExportedName() {
223 test("_foo()", "_foo()");
224 }
225
226 public void testRenameWithNameOverlap() {
227 test("var a = 1; var b = 2; b + b;",
228 "var a = 1; var b = 2; b + b;");
229 }
230
231 public void testRenameWithPrefix1() {
232 prefix = "PRE_";
233 test("function Foo(v1, v2) {return v1} Foo();",
234 "function PRE_(a, b) {return a} PRE_();");
235 prefix = DEFAULT_PREFIX;
236
237 }
238
239 public void testRenameWithPrefix2() {
240 prefix = "PRE_";
241 test("function Foo(v1, v2) {var v3 = v1 + v2; return v3;} Foo();",
242 "function PRE_(a, b) {var c = a + b; return c;} PRE_();");
243 prefix = DEFAULT_PREFIX;
244 }
245
246 public void testRenameWithPrefix3() {
247 prefix = "a";
248 test("function Foo() {return 1;}" +
249 "function Bar() {" +
250 " var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," +
251 " A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ab;" +
252 " Foo();" +
253 "} Bar();",
254
255 "function a() {return 1;}" +
256 "function aa() {" +
257 " var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A," +
258 " B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,ba,ca;" +
259 " a();" +
260 "} aa();");
261 prefix = DEFAULT_PREFIX;
262 }
263
264 public void testNamingBasedOnOrderOfOccurrence() {
265 test("var q,p,m,n,l,k; " +
266 "(function (r) {}); try { } catch(s) {}; var t = q + q;",
267 "var a,b,c,d,e,f; " +
268 "(function(g) {}); try { } catch(h) {}; var i = a + a;"
269 );
270 test("(function(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," +
271 "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,$){});" +
272 "var a4,a3,a2,a1,b4,b3,b2,b1,ab,ac,ad,fg;function foo(){};",
273 "(function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," +
274 "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$){});" +
275 "var aa,ba,ca,da,ea,fa,ga,ha,ia,ja,ka,la;function ma(){};");
276 }
277
278 public void testStableRenameSimple() {
279 VariableMap expectedVariableMap = makeVariableMap(
280 "Foo", "a", "L 0", "b", "L 1", "c");
281 testRenameMap("function Foo(v1, v2) {return v1;} Foo();",
282 "function a(b, c) {return b;} a();", expectedVariableMap);
283
284 expectedVariableMap = makeVariableMap(
285 "Foo", "a", "L 0", "b", "L 1", "c", "L 2", "d");
286 testRenameMapUsingOldMap("function Foo(v1, v2, v3) {return v1;} Foo();",
287 "function a(b, c, d) {return b;} a();", expectedVariableMap);
288 }
289
290 public void testStableRenameGlobals() {
291 VariableMap expectedVariableMap = makeVariableMap(
292 "Foo", "a", "Bar", "b", "y", "c", "x", "d");
293 testRenameMap("var Foo; var Bar, y; function x() { Bar++; }",
294 "var a; var b, c; function d() { b++; }",
295 expectedVariableMap);
296
297 expectedVariableMap = makeVariableMap(
298 "Foo", "a", "Bar", "b", "y", "c", "x", "d", "Baz", "f", "L 0" , "e");
299 testRenameMapUsingOldMap(
300 "var Foo, Baz; var Bar, y; function x(R) { return R + Bar++; }",
301 "var a, f; var b, c; function d(e) { return e + b++; }",
302 expectedVariableMap);
303 }
304
305 public void testStableRenameWithPointlesslyAnonymousFunctions() {
306 VariableMap expectedVariableMap = makeVariableMap("L 0", "a", "L 1", "b");
307 testRenameMap("(function (v1, v2) {}); (function (v3, v4) {});",
308 "(function (a, b) {}); (function (a, b) {});",
309 expectedVariableMap);
310
311 expectedVariableMap = makeVariableMap("L 0", "a", "L 1", "b", "L 2", "c");
312 testRenameMapUsingOldMap("(function (v0, v1, v2) {});" +
313 "(function (v3, v4) {});",
314 "(function (a, b, c) {});" +
315 "(function (a, b) {});",
316 expectedVariableMap);
317 }
318
319 public void testStableRenameLocalsClashingWithGlobals() {
320 test("function a(v1, v2) {return v1;} a();",
321 "function a(b, c) {return b;} a();");
322 previouslyUsedMap = renameVars.getVariableMap();
323 test("function bar(){return;}function a(v1, v2) {return v1;} a();",
324 "function d(){return;}function a(b, c) {return b;} a();");
325 }
326
327 public void testStableRenameNested() {
328 VariableMap expectedVariableMap = makeVariableMap(
329 "f1", "a", "L 0", "b", "L 1", "c", "L 2", "d", "L 3", "e");
330 testRenameMap("function f1(v1, v2) { (function(v3, v4) {}) }",
331 "function a(b, c) { (function(d, e) {}) }",
332 expectedVariableMap);
333
334 expectedVariableMap = makeVariableMap(
335 "f1", "a", "L 0", "b", "L 1", "c", "L 2", "d", "L 3", "e", "L 4", "f");
336 testRenameMapUsingOldMap(
337 "function f1(v1, v2) { (function(v3, v4, v5) {}) }",
338 "function a(b, c) { (function(d, e, f) {}) }",
339 expectedVariableMap);
340 }
341
342 public void testStableRenameWithExterns1() {
343 String externs = "var foo;";
344 test(externs, "var bar; foo(bar);", "var a; foo(a);", null, null);
345 previouslyUsedMap = renameVars.getVariableMap();
346 test(externs, "var bar, baz; foo(bar, baz);",
347 "var a, b; foo(a, b);", null, null);
348 }
349
350 public void testStableRenameWithExterns2() {
351 String externs = "var a;";
352 test(externs, "var b = 5", "var b = 5", null, null);
353 previouslyUsedMap = renameVars.getVariableMap();
354 test(externs, "var b = 5, catty = 9;", "var b = 5, c=9;", null, null);
355 }
356
357 public void testStableRenameWithNameOverlap() {
358 test("var a = 1; var b = 2; b + b;",
359 "var a = 1; var b = 2; b + b;");
360 previouslyUsedMap = renameVars.getVariableMap();
361 test("var a = 1; var c, b = 2; b + b;",
362 "var a = 1; var c, b = 2; b + b;");
363 }
364
365 public void testStableRenameWithAnonymousFunctions() {
366 VariableMap expectedVariableMap = makeVariableMap("L 0", "a", "foo", "b");
367 testRenameMap("function foo(bar){return bar;}foo(function(h){return h;});",
368 "function b(a){return a}b(function(a){return a;})",
369 expectedVariableMap);
370
371 expectedVariableMap = makeVariableMap("foo", "b", "L 0", "a", "L 1", "c");
372 testRenameMapUsingOldMap(
373 "function foo(bar) {return bar;}foo(function(g,h) {return g+h;});",
374 "function b(a){return a}b(function(a,c){return a+c;})",
375 expectedVariableMap);
376 }
377
378 public void testStableRenameSimpleExternsChanges() {
379 VariableMap expectedVariableMap = makeVariableMap(
380 "Foo", "a", "L 0", "b", "L 1", "c");
381 testRenameMap("function Foo(v1, v2) {return v1;} Foo();",
382 "function a(b, c) {return b;} a();", expectedVariableMap);
383
384 expectedVariableMap = makeVariableMap("L 0", "b", "L 1", "c", "L 2", "a");
385 String externs = "var Foo;";
386 testRenameMapUsingOldMap(externs,
387 "function Foo(v1, v2, v0) {return v1;} Foo();",
388 "function Foo(b, c, a) {return b;} Foo();",
389 expectedVariableMap);
390 }
391
392 public void testStableRenameSimpleLocalNameExterned() {
393 test("function Foo(v1, v2) {return v1;} Foo();",
394 "function a(b, c) {return b;} a();");
395
396 previouslyUsedMap = renameVars.getVariableMap();
397
398 String externs = "var b;";
399 test(externs, "function Foo(v1, v2) {return v1;} Foo(b);",
400 "function a(d, c) {return d;} a(b);", null, null);
401 }
402
403 public void testStableRenameSimpleGlobalNameExterned() {
404 test("function Foo(v1, v2) {return v1;} Foo();",
405 "function a(b, c) {return b;} a();");
406
407 previouslyUsedMap = renameVars.getVariableMap();
408
409 String externs = "var Foo;";
410 test(externs, "function Foo(v1, v2, v0) {return v1;} Foo();",
411 "function Foo(b, c, a) {return b;} Foo();", null, null);
412 }
413
414 public void testStableRenameWithPrefix1AndUnstableLocalNames() {
415 prefix = "PRE_";
416 test("function Foo(v1, v2) {return v1} Foo();",
417 "function PRE_(a, b) {return a} PRE_();");
418
419 previouslyUsedMap = renameVars.getVariableMap();
420
421 prefix = "PRE_";
422 test("function Foo(v0, v1, v2) {return v1} Foo();",
423 "function PRE_(a, b, c) {return b} PRE_();");
424 }
425
426 public void testStableRenameWithPrefix2() {
427 prefix = "a";
428 test("function Foo() {return 1;}" +
429 "function Bar() {" +
430 " var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," +
431 " A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ab;" +
432 " Foo();" +
433 "} Bar();",
434
435 "function a() {return 1;}" +
436 "function aa() {" +
437 " var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A," +
438 " B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,ba,ca;" +
439 " a();" +
440 "} aa();");
441
442 previouslyUsedMap = renameVars.getVariableMap();
443
444 prefix = "a";
445 test("function Foo() {return 1;}" +
446 "function Baz() {return 1;}" +
447 "function Bar() {" +
448 " var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," +
449 " A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ab;" +
450 " Foo();" +
451 "} Bar();",
452
453 "function a() {return 1;}" +
454 "function ab() {return 1;}" +
455 "function aa() {" +
456 " var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A," +
457 " B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,ba,ca;" +
458 " a();" +
459 "} aa();");
460 }
461
462 public void testContrivedExampleWhereConsistentRenamingIsWorse() {
463 previouslyUsedMap = makeVariableMap(
464 "Foo", "LongString", "L 0", "b", "L 1", "c");
465
466 test("function Foo(v1, v2) {return v1;} Foo();",
467 "function LongString(b, c) {return b;} LongString();");
468
469 previouslyUsedMap = renameVars.getVariableMap();
470 VariableMap expectedVariableMap = makeVariableMap(
471 "Foo", "LongString", "L 0", "b", "L 1", "c");
472 assertVariableMapsEqual(expectedVariableMap, previouslyUsedMap);
473 }
474
475 public void testPrevUsedMapWithDuplicates() {
476 previouslyUsedMap = makeVariableMap("Foo", "z", "Bar", "z");
477 try {
478 testSame("");
479 fail();
480 } catch (java.lang.IllegalArgumentException expected) {
481 }
482 }
483
484 public void testExportSimpleSymbolReservesName() {
485 test("var goog, x; goog.exportSymbol('a', x);",
486 "var a, b; a.exportSymbol('a', b);");
487 withClosurePass = true;
488 test("var goog, x; goog.exportSymbol('a', x);",
489 "var b, c; b.exportSymbol('a', c);");
490 }
491
492 public void testExportComplexSymbolReservesName() {
493 test("var goog, x; goog.exportSymbol('a.b', x);",
494 "var a, b; a.exportSymbol('a.b', b);");
495 withClosurePass = true;
496 test("var goog, x; goog.exportSymbol('a.b', x);",
497 "var b, c; b.exportSymbol('a.b', c);");
498 }
499
500 public void testExportToNonStringDoesntExplode() {
501 withClosurePass = true;
502 test("var goog, a, b; goog.exportSymbol(a, b);",
503 "var a, b, c; a.exportSymbol(b, c);");
504 }
505
506 public void testDollarSignSuperExport1() {
507 useGoogleCodingConvention = false;
508 // See http://code.google.com/p/closure-compiler/issues/detail?id=32
509 test("var x = function($super,duper,$fantastic){}",
510 "var c = function($super, a, b){}");
511
512 localRenamingOnly = false;
513 test("var $super = 1", "var a = 1");
514
515 useGoogleCodingConvention = true;
516 test("var x = function($super,duper,$fantastic){}",
517 "var c = function($super,a,b){}");
518 }
519
520 public void testDollarSignSuperExport2() {
521 withNormalize = true;
522
523 useGoogleCodingConvention = false;
524 // See http://code.google.com/p/closure-compiler/issues/detail?id=32
525 test("var x = function($super,duper,$fantastic){};" +
526 "var y = function($super,duper){};",
527 "var c = function($super, a, b){};" +
528 "var d = function($super, a){};");
529
530 localRenamingOnly = false;
531 test("var $super = 1", "var a = 1");
532
533 useGoogleCodingConvention = true;
534 test("var x = function($super,duper,$fantastic){};" +
535 "var y = function($super,duper){};",
536 "var c = function($super, a, b ){};" +
537 "var d = function($super,a){};");
538 }
539
540 public void testPseudoNames() {
541 generatePseudoNames = false;
542 // See http://code.google.com/p/closure-compiler/issues/detail?id=32
543 test("var foo = function(a, b, c){}",
544 "var d = function(a, b, c){}");
545
546 generatePseudoNames = true;
547 test("var foo = function(a, b, c){}",
548 "var $foo$$ = function($a$$, $b$$, $c$$){}");
549
550 test("var a = function(a, b, c){}",
551 "var $a$$ = function($a$$, $b$$, $c$$){}");
552 }
553
554 private void testRenameMapUsingOldMap(String input, String expected,
555 VariableMap expectedMap) {
556 previouslyUsedMap = renameVars.getVariableMap();
557 testRenameMap("", input, expected, expectedMap);
558 }
559
560 private void testRenameMapUsingOldMap(String externs, String input,
561 String expected,
562 VariableMap expectedMap) {
563 previouslyUsedMap = renameVars.getVariableMap();
564 testRenameMap(externs, input, expected, expectedMap);
565 }
566
567 private void testRenameMap(String input, String expected,
568 VariableMap expectedRenameMap) {
569 testRenameMap("", input, expected, expectedRenameMap);
570 }
571
572 private void testRenameMap(String externs, String input, String expected,
573 VariableMap expectedRenameMap) {
574 test(externs, input, expected, null, null);
575 VariableMap renameMap = renameVars.getVariableMap();
576 assertVariableMapsEqual(expectedRenameMap, renameMap);
577 }
578
579 private VariableMap makeVariableMap(String... keyValPairs) {
580 Preconditions.checkArgument(keyValPairs.length % 2 == 0);
581
582 ImmutableMap.Builder<String, String> renameMap = ImmutableMap.builder();
583 for (int i = 0; i < keyValPairs.length; i += 2) {
584 renameMap.put(keyValPairs[i], keyValPairs[i + 1]);
585 }
586
587 return new VariableMap(renameMap.build());
588 }
589
590 private static void assertVariableMapsEqual(VariableMap a, VariableMap b) {
591 Map<String, String> ma = a.getOriginalNameToNewNameMap();
592 Map<String, String> mb = b.getOriginalNameToNewNameMap();
593 assertEquals("VariableMaps not equal", ma, mb);
594 }
595
596 private class ClosurePassAndRenameVars implements CompilerPass {
597 private final Compiler compiler;
598
599 private ClosurePassAndRenameVars(Compiler compiler) {
600 this.compiler = compiler;
601 }
602
603 @Override
604 public void process(Node externs, Node root) {
605 ProcessClosurePrimitives closurePass =
606 new ProcessClosurePrimitives(
607 compiler, null, CheckLevel.WARNING);
608 closurePass.process(externs, root);
609 renameVars = new RenameVars(compiler, prefix,
610 false, false, false, false, previouslyUsedMap, null,
611 closurePass.getExportedVariableNames());
612 renameVars.process(externs, root);
613 }
614 }
615
616 private class NormalizePassWrapper implements CompilerPass {
617 private final Compiler compiler;
618 private CompilerPass wrappedPass;
619
620 private NormalizePassWrapper(Compiler compiler,
621 CompilerPass wrappedPass) {
622 this.compiler = compiler;
623 this.wrappedPass = wrappedPass;
624 }
625
626 @Override
627 public void process(Node externs, Node root) {
628 Normalize normalize = new Normalize(compiler, false);
629 normalize.process(externs, root);
630
631 wrappedPass.process(externs, root);
632 }
633 }
634 }