use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences2.
@Test
public void testPrototypeReferences2() {
SymbolTable table = createSymbolTable("/** @constructor */" + "function Snork() {}" + "Snork.prototype.baz = 3;");
Symbol prototype = getGlobalVar(table, "Snork.prototype");
assertThat(prototype).isNotNull();
List<Reference> refs = table.getReferenceList(prototype);
assertThat(refs).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences3.
@Test
public void testPrototypeReferences3() {
SymbolTable table = createSymbolTable("/** @constructor */ function Foo() {}");
Symbol fooPrototype = getGlobalVar(table, "Foo.prototype");
assertThat(fooPrototype).isNotNull();
List<Reference> refs = table.getReferenceList(fooPrototype);
assertThat(refs).hasSize(1);
assertThat(refs.get(0).getNode().getToken()).isEqualTo(Token.NAME);
// Make sure that the ctor and its prototype are declared at the
// same node.
assertThat(table.getReferenceList(getGlobalVar(table, "Foo")).get(0).getNode()).isEqualTo(refs.get(0).getNode());
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences_es6Class.
@Test
public void testPrototypeReferences_es6Class() {
SymbolTable table = createSymbolTable(lines("class DomHelper { method() {} }"));
Symbol prototype = getGlobalVar(table, "DomHelper.prototype");
assertThat(prototype).isNotNull();
List<Reference> refs = table.getReferenceList(prototype);
// The class declaration creates an implicit .prototype reference.
assertWithMessage(refs.toString()).that(refs).hasSize(1);
assertNode(refs.get(0).getNode().getParent()).hasToken(Token.CLASS);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testMethodReferencesMissingTypeInfo.
@Test
public void testMethodReferencesMissingTypeInfo() {
SymbolTable table = createSymbolTable(lines("/**", " * @constructor", " * @extends {Missing}", " */ var DomHelper = function(){};", "/** method */ DomHelper.prototype.method = function() {", " this.method();", "};", "function f() { ", " (new DomHelper()).method();", "};"));
Symbol method = getGlobalVar(table, "DomHelper.prototype.method");
assertThat(table.getReferences(method)).hasSize(3);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testReferencesInJSDocType2.
@Test
public void testReferencesInJSDocType2() {
SymbolTable table = createSymbolTableWithDefaultExterns("/** @param {string} x */ function f(x) {}");
Symbol str = getGlobalVar(table, "String");
assertThat(str).isNotNull();
List<Reference> refs = table.getReferenceList(str);
// We're going to pick up a lot of references from the externs,
// so it's not meaningful to check the number of references.
// We really want to make sure that all the references are in the externs,
// except the last one.
assertThat(refs.size()).isGreaterThan(1);
int last = refs.size() - 1;
for (int i = 0; i < refs.size(); i++) {
Reference ref = refs.get(i);
assertThat(ref.getNode().isFromExterns()).isEqualTo(i != last);
if (!ref.getNode().isFromExterns()) {
assertThat(ref.getNode().getSourceFileName()).isEqualTo("in1");
}
}
}
Aggregations