use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGlobalVarReferences.
@Test
public void testGlobalVarReferences() {
SymbolTable table = createSymbolTable("/** @type {number} */ var x = 5; x = 6;");
Symbol x = getGlobalVar(table, "x");
List<Reference> refs = table.getReferenceList(x);
assertThat(refs).hasSize(2);
assertThat(refs.get(0)).isEqualTo(x.getDeclaration());
assertThat(refs.get(0).getNode().getParent().getToken()).isEqualTo(Token.VAR);
assertThat(refs.get(1).getNode().getParent().getToken()).isEqualTo(Token.ASSIGN);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGoogRequireReferences.
@Test
public void testGoogRequireReferences() {
SymbolTable table = createSymbolTableWithDefaultExterns(lines(// goog.require is defined in the default externs, among other Closure methods
"goog.provide('goog.dom');", "goog.require('goog.dom');"));
Symbol googRequire = getGlobalVar(table, "goog.require");
assertThat(googRequire).isNotNull();
assertThat(table.getReferences(googRequire)).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method verifySymbolReferencedInSecondFile.
private void verifySymbolReferencedInSecondFile(String firstFile, String secondFile, String symbolName) {
SymbolTable table = createSymbolTableFromManySources(firstFile, secondFile);
Symbol symbol = table.getAllSymbols().stream().filter((s) -> s.getSourceFileName().equals("file1.js") && s.getName().equals(symbolName)).findFirst().get();
for (SymbolTable.Reference ref : table.getReferences(symbol)) {
if (ref.getNode().getSourceFileName().equals("file2.js")) {
return;
}
}
Assert.fail("Did not find references in file2.js of symbol " + symbol);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testMissingConstructorTag.
@Test
public void testMissingConstructorTag() {
SymbolTable table = createSymbolTable(lines("function F() {", " this.field1 = 3;", "}", "F.prototype.method1 = function() {", " this.field1 = 5;", "};", "(new F()).method1();"));
// Because the constructor tag is missing, this is going
// to be missing a lot of inference.
assertThat(getGlobalVar(table, "F.prototype.field1")).isNull();
Symbol sym = getGlobalVar(table, "F.prototype.method1");
assertThat(table.getReferenceList(sym)).hasSize(1);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGlobalRichObjectReference.
@Test
public void testGlobalRichObjectReference() {
SymbolTable table = createSymbolTable(lines("/** @constructor */", "function A(){};", "/** @type {?A} */ A.prototype.b;", "/** @type {A} */ var a = new A();", "function g() {", " return a.b ? 'x' : 'y';", "}", "(function() {", " var x; if (x) { x = a.b.b; } else { x = a.b.c; }", " return x;", "})();"));
Symbol ab = getGlobalVar(table, "a.b");
assertThat(ab).isNull();
Symbol propB = getGlobalVar(table, "A.prototype.b");
assertThat(propB).isNotNull();
assertThat(table.getReferenceList(propB)).hasSize(5);
}
Aggregations