| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
import com.google.javascript.jscomp.CheckLevel; |
| 20 |
import com.google.javascript.jscomp.type.SemanticReverseAbstractInterpreter; |
| 21 |
import com.google.javascript.rhino.Node; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class RemoveUnusedNamesTest extends CompilerTestCase { |
| 29 |
private static final String EXTERNS = |
| 30 |
"/** @constructor */\n " + |
| 31 |
"function IFoo() { } \n" + |
| 32 |
"IFoo.prototype.bar; \n" + |
| 33 |
|
| 34 |
"/** @constructor */\n " + |
| 35 |
"var mExtern; \n" + |
| 36 |
"mExtern.bExtern; \n" + |
| 37 |
"mExtern['cExtern']; \n"; |
| 38 |
|
| 39 |
public RemoveUnusedNamesTest() { |
| 40 |
super(EXTERNS); |
| 41 |
} |
| 42 |
|
| 43 |
private boolean canRemoveExterns = false; |
| 44 |
|
| 45 |
@Override |
| 46 |
protected int getNumRepetitions() { |
| 47 |
return 1; |
| 48 |
} |
| 49 |
|
| 50 |
@Override |
| 51 |
protected CompilerPass getProcessor(final Compiler compiler) { |
| 52 |
return new CompilerPass() { |
| 53 |
|
| 54 |
@Override |
| 55 |
public void process(Node externs, Node root) { |
| 56 |
new TypeCheck(compiler, |
| 57 |
new SemanticReverseAbstractInterpreter( |
| 58 |
compiler.getCodingConvention(), |
| 59 |
compiler.getTypeRegistry()), |
| 60 |
compiler.getTypeRegistry(), |
| 61 |
CheckLevel.ERROR, |
| 62 |
CheckLevel.ERROR).processForTesting(externs, root); |
| 63 |
|
| 64 |
new RemoveUnusedNames( |
| 65 |
compiler, canRemoveExterns).process(externs, root); |
| 66 |
|
| 67 |
|
| 68 |
new UnreachableCodeElimination(compiler, true).process(externs, root); |
| 69 |
} |
| 70 |
}; |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public void setUp() { |
| 75 |
canRemoveExterns = false; |
| 76 |
} |
| 77 |
|
| 78 |
public void testAnalyzeUnusedPrototypeProperties() { |
| 79 |
|
| 80 |
test("/** @constructor */ \n" + |
| 81 |
"function e(){} \n" + |
| 82 |
"e.prototype.a = function(){};" + |
| 83 |
"e.prototype.b = function(){};" + |
| 84 |
"var x = new e; x.a()", |
| 85 |
|
| 86 |
"function e(){}" + |
| 87 |
" e.prototype.a = function(){};" + |
| 88 |
"var x = new e; x.a()"); |
| 89 |
} |
| 90 |
|
| 91 |
public void testAnalyzeUnusedPrototypeProperties2() { |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
public void testAnalyzeUnusedPrototypeProperties3() { |
| 105 |
|
| 106 |
|
| 107 |
test("/** @constructor */ \n" + |
| 108 |
"function e(){} \n" + |
| 109 |
"e.prototype.a = function(){};" + |
| 110 |
"e.prototype.bExtern = function(){};" + |
| 111 |
"var x = new e;x.a()", |
| 112 |
"function e(){}" + |
| 113 |
"e.prototype.a = function(){};" + |
| 114 |
|
| 115 |
"var x = new e; x.a()"); |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
public void testAliasing() { |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
public void testStatement() { |
| 132 |
test("/**\n" + |
| 133 |
" * @fileoverview\n" + |
| 134 |
" * @notypecheck\n" + |
| 135 |
" */ \n" + |
| 136 |
"/** @constructor */" + |
| 137 |
"function e(){}" + |
| 138 |
"var x = e.prototype.method1 = function(){};" + |
| 139 |
"var y = new e; x()", |
| 140 |
"function e(){}" + |
| 141 |
"var x = function(){};" + |
| 142 |
"var y = new e; x()"); |
| 143 |
} |
| 144 |
|
| 145 |
public void testExportedMethodsByNamingConvention() { |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
public void testExportedMethodsByNamingConventionAlwaysExported() { |
| 150 |
|
| 151 |
} |
| 152 |
} |