use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testReferencesInJSDocName.
public void testReferencesInJSDocName() {
String code = "/** @param {Object} x */ function f(x) {}\n";
SymbolTable table = createSymbolTable(code);
Symbol x = getLocalVar(table, "x");
assertNotNull(x);
List<Reference> refs = table.getReferenceList(x);
assertThat(refs).hasSize(2);
assertEquals(code.indexOf("x) {"), refs.get(0).getNode().getCharno());
assertEquals(code.indexOf("x */"), refs.get(1).getNode().getCharno());
assertEquals("in1", refs.get(0).getNode().getSourceFileName());
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testGlobalThisReferences2.
public void testGlobalThisReferences2() throws Exception {
// Make sure the global this is declared, even if it isn't referenced.
SymbolTable table = createSymbolTable("");
Symbol global = getGlobalVar(table, "*global*");
assertNotNull(global);
List<Reference> refs = table.getReferenceList(global);
assertThat(refs).isEmpty();
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences4.
public void testPrototypeReferences4() throws Exception {
SymbolTable table = createSymbolTable("/** @constructor */ function Foo() {}" + "Foo.prototype = {bar: 3}");
Symbol fooPrototype = getGlobalVar(table, "Foo.prototype");
assertNotNull(fooPrototype);
List<Reference> refs = ImmutableList.copyOf(table.getReferences(fooPrototype));
assertThat(refs).hasSize(1);
assertEquals(Token.GETPROP, refs.get(0).getNode().getToken());
assertEquals("Foo.prototype", refs.get(0).getNode().getQualifiedName());
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testLocalThisReferences.
public void testLocalThisReferences() throws Exception {
SymbolTable table = createSymbolTable("/** @constructor */ function F() { this.foo = 3; this.bar = 5; }");
Symbol f = getGlobalVar(table, "F");
assertNotNull(f);
Symbol t = table.getParameterInFunction(f, "this");
assertNotNull(t);
List<Reference> refs = table.getReferenceList(t);
assertThat(refs).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testSuperClassReference.
public void testSuperClassReference() throws Exception {
SymbolTable table = createSymbolTable(" var a = {b: {}};\n" + "/** @constructor */\n" + "a.b.BaseClass = function() {};\n" + "a.b.BaseClass.prototype.doSomething = function() {\n" + " alert('hi');\n" + "};\n" + "/**\n" + " * @constructor\n" + " * @extends {a.b.BaseClass}\n" + " */\n" + "a.b.DerivedClass = function() {};\n" + "goog.inherits(a.b.DerivedClass, a.b.BaseClass);\n" + "/** @override */\n" + "a.b.DerivedClass.prototype.doSomething = function() {\n" + " a.b.DerivedClass.superClass_.doSomething();\n" + "};\n");
Symbol bad = getGlobalVar(table, "a.b.DerivedClass.superClass_.doSomething");
assertNull(bad);
Symbol good = getGlobalVar(table, "a.b.BaseClass.prototype.doSomething");
assertNotNull(good);
List<Reference> refs = table.getReferenceList(good);
assertThat(refs).hasSize(2);
assertEquals("a.b.DerivedClass.superClass_.doSomething", refs.get(1).getNode().getQualifiedName());
}
Aggregations