| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class IgnoreCajaPropertiesTest extends CompilerTestCase { |
| 25 |
|
| 26 |
private static final String EXTERNS = |
| 27 |
"var z = {}, " + |
| 28 |
"f = function(y) { z[y] = z[y] ? (z[y]+1) : 1; }, " + |
| 29 |
"x, i;"; |
| 30 |
|
| 31 |
public IgnoreCajaPropertiesTest() { |
| 32 |
super(EXTERNS); |
| 33 |
} |
| 34 |
|
| 35 |
@Override |
| 36 |
public void setUp() { |
| 37 |
super.enableLineNumberCheck(false); |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
public int getNumRepetitions() { |
| 42 |
return 1; |
| 43 |
} |
| 44 |
|
| 45 |
public void testSimpleKey() { |
| 46 |
|
| 47 |
test("for (i in x) f(i);", |
| 48 |
"for (var JSCompiler_IgnoreCajaProperties_0 in x)" + |
| 49 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 50 |
" i = JSCompiler_IgnoreCajaProperties_0;" + |
| 51 |
" { f(i); }" + |
| 52 |
" }"); |
| 53 |
|
| 54 |
test("for (i in x) { f(i); f(i); }", |
| 55 |
"for (var JSCompiler_IgnoreCajaProperties_0 in x)" + |
| 56 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 57 |
" i = JSCompiler_IgnoreCajaProperties_0;" + |
| 58 |
" { f(i); f(i); }" + |
| 59 |
" }"); |
| 60 |
|
| 61 |
|
| 62 |
test("for (i in x) for (j in y) f(i,j);", |
| 63 |
"for (var JSCompiler_IgnoreCajaProperties_1 in x)" + |
| 64 |
" if (!JSCompiler_IgnoreCajaProperties_1.match(/___$/)) {" + |
| 65 |
" i = JSCompiler_IgnoreCajaProperties_1;" + |
| 66 |
" {" + |
| 67 |
" for (var JSCompiler_IgnoreCajaProperties_0 in y)" + |
| 68 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 69 |
" j = JSCompiler_IgnoreCajaProperties_0;" + |
| 70 |
" { f(i,j); }" + |
| 71 |
" }" + |
| 72 |
" }" + |
| 73 |
" }"); |
| 74 |
} |
| 75 |
|
| 76 |
public void testPropertyKey() { |
| 77 |
test("for (z.i in x) { f(z.i); f(z.i); }", |
| 78 |
"for (var JSCompiler_IgnoreCajaProperties_0 in x) {" + |
| 79 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 80 |
" z.i = JSCompiler_IgnoreCajaProperties_0;" + |
| 81 |
" { f(z.i); f(z.i); }" + |
| 82 |
" }" + |
| 83 |
"}"); |
| 84 |
} |
| 85 |
|
| 86 |
public void testFunctionPropertyKey() { |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
test("for (z.j().i in x) { f(z.j().i); f(z.j().i); }", |
| 91 |
"for (var JSCompiler_IgnoreCajaProperties_0 in x) {" + |
| 92 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 93 |
" z.j().i = JSCompiler_IgnoreCajaProperties_0;" + |
| 94 |
" { f(z.j().i); f(z.j().i); }" + |
| 95 |
" }" + |
| 96 |
"}"); |
| 97 |
} |
| 98 |
|
| 99 |
public void testVarKey() { |
| 100 |
|
| 101 |
test("for (var j in x) { f(j); }", |
| 102 |
"for (var JSCompiler_IgnoreCajaProperties_0 in x) {" + |
| 103 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 104 |
" var j;" + |
| 105 |
" j = JSCompiler_IgnoreCajaProperties_0;" + |
| 106 |
" { f(j); }" + |
| 107 |
" }" + |
| 108 |
"}"); |
| 109 |
|
| 110 |
test("for (var j in x) { f(j); f(j); }", |
| 111 |
"for (var JSCompiler_IgnoreCajaProperties_0 in x) {" + |
| 112 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 113 |
" var j;" + |
| 114 |
" j = JSCompiler_IgnoreCajaProperties_0;" + |
| 115 |
" { f(j); f(j); }" + |
| 116 |
" }" + |
| 117 |
"}"); |
| 118 |
|
| 119 |
test("for (var i in x) for (var j in y) f(i,j);", |
| 120 |
"for (var JSCompiler_IgnoreCajaProperties_1 in x)" + |
| 121 |
" if (!JSCompiler_IgnoreCajaProperties_1.match(/___$/)) {" + |
| 122 |
" var i;" + |
| 123 |
" i = JSCompiler_IgnoreCajaProperties_1;" + |
| 124 |
" {" + |
| 125 |
" for (var JSCompiler_IgnoreCajaProperties_0 in y)" + |
| 126 |
" if (!JSCompiler_IgnoreCajaProperties_0.match(/___$/)) {" + |
| 127 |
" var j;" + |
| 128 |
" j = JSCompiler_IgnoreCajaProperties_0;" + |
| 129 |
" { f(i,j); }" + |
| 130 |
" }" + |
| 131 |
" }" + |
| 132 |
" }"); |
| 133 |
} |
| 134 |
|
| 135 |
public void testFourChildFor() { |
| 136 |
test("for (i = 0; i < 10; ++i) { f(i); }", |
| 137 |
"for (i = 0; i < 10; ++i) { f(i); }"); |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public CompilerPass getProcessor(Compiler compiler) { |
| 142 |
return new IgnoreCajaProperties(compiler); |
| 143 |
} |
| 144 |
} |