use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGlobalThisReferences2.
@Test
public void testGlobalThisReferences2() {
// Make sure the global this is declared, even if it isn't referenced.
SymbolTable table = createSymbolTable("");
Symbol global = getGlobalVar(table, "*global*");
assertThat(global).isNotNull();
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 testLocalThisReferences3.
// No 'this' reference is created for empty functions.
@Test
public void testLocalThisReferences3() {
SymbolTable table = createSymbolTable("/** @constructor */ function F() {}");
Symbol baz = getGlobalVar(table, "F");
assertThat(baz).isNotNull();
Symbol t = table.getParameterInFunction(baz, "this");
assertThat(t).isNull();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeSymbolEqualityForTwoPathsToSamePrototype.
@Test
public void testPrototypeSymbolEqualityForTwoPathsToSamePrototype() {
String input = lines("/**", "* An employer.", "*", "* @param {String} name name of employer.", "* @param {String} address address of employer.", "* @constructor", "*/", "function Employer(name, address) {", "this.name = name;", "this.address = address;", "}", "", "/**", "* @return {String} information about an employer.", "*/", "Employer.prototype.getInfo = function() {", "return this.name + '.' + this.address;", "};");
SymbolTable table = createSymbolTable(input);
Symbol employer = getGlobalVar(table, "Employer");
assertThat(employer).isNotNull();
SymbolScope propertyScope = employer.getPropertyScope();
assertThat(propertyScope).isNotNull();
Symbol prototypeOfEmployer = propertyScope.getQualifiedSlot("prototype");
assertThat(prototypeOfEmployer).isNotNull();
Symbol employerPrototype = getGlobalVar(table, "Employer.prototype");
assertThat(employerPrototype).isNotNull();
new EqualsTester().addEqualityGroup(employerPrototype, prototypeOfEmployer).testEquals();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testDeclarationDisagreement.
@Test
public void testDeclarationDisagreement() {
SymbolTable table = createSymbolTable(lines("/** @const */ var goog = goog || {};", "/** @param {!Function} x */", "goog.addSingletonGetter2 = function(x) {};", "/** Wakka wakka wakka */", "goog.addSingletonGetter = goog.addSingletonGetter2;", "/** @param {!Function} x */", "goog.addSingletonGetter = function(x) {};"));
Symbol method = getGlobalVar(table, "goog.addSingletonGetter");
List<Reference> refs = table.getReferenceList(method);
assertThat(refs).hasSize(2);
// Note that the declaration should show up second.
assertThat(method.getDeclaration().getNode().getLineno()).isEqualTo(7);
assertThat(refs.get(1).getNode().getLineno()).isEqualTo(5);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testJSDocOnlySymbol.
@Test
public void testJSDocOnlySymbol() {
SymbolTable table = createSymbolTable(lines("/**", " * @param {number} x", " * @param y", " */", "var a;"));
Symbol x = getDocVar(table, "x");
assertThat(x).isNotNull();
assertThat(x.getType().toString()).isEqualTo("number");
assertThat(table.getReferenceList(x)).hasSize(1);
Symbol y = getDocVar(table, "y");
assertThat(x).isNotNull();
assertThat(y.getType()).isNull();
assertThat(table.getReferenceList(y)).hasSize(1);
}
Aggregations