use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testSymbolsForType.
@Test
public void testSymbolsForType() {
SymbolTable table = createSymbolTableWithDefaultExterns(lines("function random() { return 1; }", "/** @constructor */ function Foo() {}", "/** @constructor */ function Bar() {}", "var x = random() ? new Foo() : new Bar();"));
Symbol x = getGlobalVar(table, "x");
Symbol foo = getGlobalVar(table, "Foo");
Symbol bar = getGlobalVar(table, "Bar");
Symbol fooPrototype = getGlobalVar(table, "Foo.prototype");
Symbol fn = getGlobalVar(table, "Function");
assertThat(table.getAllSymbolsForTypeOf(x)).containsExactly(foo, bar);
assertThat(table.getAllSymbolsForTypeOf(foo)).containsExactly(fn);
assertThat(table.getAllSymbolsForTypeOf(fooPrototype)).containsExactly(foo);
assertThat(table.getSymbolDeclaredBy(foo.getType().toMaybeFunctionType())).isEqualTo(foo);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testNamespaceDefinitionOrder.
@Test
public void testNamespaceDefinitionOrder() {
// Sometimes, weird things can happen where the files appear in
// a strange order. We need to make sure we're robust against this.
SymbolTable table = createSymbolTable(lines("/** @constructor */ goog.dom.Foo = function() {};", "/** @const */ goog.dom = {};", "/** @const */ var goog = {};"));
Symbol goog = getGlobalVar(table, "goog");
Symbol dom = getGlobalVar(table, "goog.dom");
Symbol foo = getGlobalVar(table, "goog.dom.Foo");
assertThat(goog).isNotNull();
assertThat(dom).isNotNull();
assertThat(foo).isNotNull();
assertThat(goog.getPropertyScope().getSlot("dom")).isEqualTo(dom);
assertThat(dom.getPropertyScope().getSlot("Foo")).isEqualTo(foo);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences5.
@Test
public void testPrototypeReferences5() {
SymbolTable table = createSymbolTable("var goog = {}; /** @constructor */ goog.Foo = function() {};");
Symbol fooPrototype = getGlobalVar(table, "goog.Foo.prototype");
assertThat(fooPrototype).isNotNull();
List<Reference> refs = table.getReferenceList(fooPrototype);
assertThat(refs).hasSize(1);
assertThat(refs.get(0).getNode().getToken()).isEqualTo(Token.GETPROP);
// Make sure that the ctor and its prototype are declared at the
// same node.
assertThat(table.getReferenceList(getGlobalVar(table, "goog.Foo")).get(0).getNode()).isEqualTo(refs.get(0).getNode());
}
Aggregations