use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testNamespacedReferences.
@Test
public void testNamespacedReferences() {
// Because the type of 'my' is anonymous, we build its properties into
// the global scope.
SymbolTable table = createSymbolTable(lines("var my = {};", "my.dom = {};", "my.dom.DomHelper = function(){};"));
Symbol my = getGlobalVar(table, "my");
assertThat(my).isNotNull();
assertThat(table.getReferences(my)).hasSize(3);
Symbol myDom = getGlobalVar(table, "my.dom");
assertThat(myDom).isNotNull();
assertThat(table.getReferences(myDom)).hasSize(2);
Symbol myDomHelper = getGlobalVar(table, "my.dom.DomHelper");
assertThat(myDomHelper).isNotNull();
assertThat(table.getReferences(myDomHelper)).hasSize(1);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testLocalQualifiedNamesInLocalScopes.
@Test
public void testLocalQualifiedNamesInLocalScopes() {
SymbolTable table = createSymbolTable("function f() { var x = {}; x.number = 3; }");
Symbol xNumber = getLocalVar(table, "x.number");
assertThat(xNumber).isNotNull();
assertThat(table.getScope(xNumber).isGlobalScope()).isFalse();
assertThat(xNumber.getType().toString()).isEqualTo("number");
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testSuperClassMethodReferences.
@Test
public void testSuperClassMethodReferences() {
SymbolTable table = createSymbolTable(lines("var goog = {};", "goog.inherits = function(a, b) {};", "/** @constructor */ var A = function(){};", "/** method */ A.prototype.method = function() {};", "/**", " * @constructor", " * @extends {A}", " */", "var B = function(){};", "goog.inherits(B, A);", "/** method */ B.prototype.method = function() {", " B.superClass_.method();", "};"));
Symbol methodA = getGlobalVar(table, "A.prototype.method");
assertThat(table.getReferences(methodA)).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGoogScopeReferences.
@Test
public void testGoogScopeReferences() {
SymbolTable table = createSymbolTableWithDefaultExterns(// goog.scope is defined in the default externs, among other Closure methods
lines("goog.scope(function() {});"));
Symbol googScope = getGlobalVar(table, "goog.scope");
assertThat(googScope).isNotNull();
assertThat(table.getReferences(googScope)).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testSuperKeywords.
@Test
public void testSuperKeywords() {
SymbolTable table = createSymbolTable(lines("class Parent { doFoo() {} }", "class Child extends Parent {", " constructor() { super(); }", " doFoo() { super.doFoo(); }", "}"));
Symbol parentClass = getGlobalVar(table, "Parent");
long numberOfSuperReferences = table.getReferenceList(parentClass).stream().filter((Reference ref) -> ref.getNode().isSuper()).count();
// TODO(b/112359882): change number of refs to 2 once Es6ConvertSuper pass is moved after type
// checks.
assertThat(numberOfSuperReferences).isEqualTo(1);
}
Aggregations