use of com.google.javascript.jscomp.SymbolTable.Symbol 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.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeSymbolEqualityForTwoPathsToSamePrototype.
public void testPrototypeSymbolEqualityForTwoPathsToSamePrototype() {
String input = lines("/**\n", "* An employer.\n", "*\n", "* @param {String} name name of employer.\n", "* @param {String} address address of employer.\n", "* @constructor\n", "*/\n", "function Employer(name, address) {\n", "this.name = name;\n", "this.address = address;\n", "}\n", "\n", "/**\n", "* @return {String} information about an employer.\n", "*/\n", "Employer.prototype.getInfo = function() {\n", "return this.name + '.' + this.address;\n", "};");
SymbolTable table = createSymbolTable(input);
Symbol employer = getGlobalVar(table, "Employer");
assertNotNull(employer);
SymbolScope propertyScope = employer.getPropertyScope();
assertNotNull(propertyScope);
Symbol prototypeOfEmployer = propertyScope.getQualifiedSlot("prototype");
assertNotNull(prototypeOfEmployer);
Symbol employerPrototype = getGlobalVar(table, "Employer.prototype");
assertNotNull(employerPrototype);
new EqualsTester().addEqualityGroup(employerPrototype, prototypeOfEmployer).testEquals();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol 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.Symbol in project closure-compiler by google.
the class SymbolTableTest method testJSDocOnlySymbol.
public void testJSDocOnlySymbol() throws Exception {
SymbolTable table = createSymbolTable("/**\n" + " * @param {number} x\n" + " * @param y\n" + " */\n" + "var a;");
Symbol x = getDocVar(table, "x");
assertNotNull(x);
assertEquals("number", x.getType().toString());
assertThat(table.getReferenceList(x)).hasSize(1);
Symbol y = getDocVar(table, "y");
assertNotNull(x);
assertNull(y.getType());
assertThat(table.getReferenceList(y)).hasSize(1);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol 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());
}
Aggregations