use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testStaticMethodReferences.
@Test
public void testStaticMethodReferences() {
SymbolTable table = createSymbolTable(lines("/** @constructor */ var DomHelper = function(){};", "/** method */ DomHelper.method = function() {};", "function f() { var x = DomHelper; x.method() + x.method(); }"));
Symbol method = getGlobalVar(table, "DomHelper").getPropertyScope().getSlot("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 testNaturalSymbolOrdering.
@Test
public void testNaturalSymbolOrdering() {
SymbolTable table = createSymbolTable(lines("/** @const */ var a = {};", "/** @const */ a.b = {};", "/** @param {number} x */ function f(x) {}"));
Symbol a = getGlobalVar(table, "a");
Symbol ab = getGlobalVar(table, "a.b");
Symbol f = getGlobalVar(table, "f");
Symbol x = getLocalVar(table, "x");
Ordering<Symbol> ordering = table.getNaturalSymbolOrdering();
assertSymmetricOrdering(ordering, a, ab);
assertSymmetricOrdering(ordering, a, f);
assertSymmetricOrdering(ordering, f, ab);
assertSymmetricOrdering(ordering, f, x);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testReferencesInJSDocType.
@Test
public void testReferencesInJSDocType() {
SymbolTable table = createSymbolTable(lines("/** @constructor */ function Foo() {}", "/** @type {Foo} */ var x;", "/** @param {Foo} x */ function f(x) {}", "/** @return {function(): Foo} */ function g() {}", "/**", " * @constructor", " * @extends {Foo}", " */ function Sub() {}"));
Symbol foo = getGlobalVar(table, "Foo");
assertThat(foo).isNotNull();
List<Reference> refs = table.getReferenceList(foo);
assertThat(refs).hasSize(5);
assertThat(refs.get(0).getNode().getLineno()).isEqualTo(1);
assertThat(refs.get(0).getNode().getCharno()).isEqualTo(29);
assertThat(refs.get(0).getNode().getLength()).isEqualTo(3);
assertThat(refs.get(1).getNode().getLineno()).isEqualTo(2);
assertThat(refs.get(1).getNode().getCharno()).isEqualTo(11);
assertThat(refs.get(2).getNode().getLineno()).isEqualTo(3);
assertThat(refs.get(2).getNode().getCharno()).isEqualTo(12);
assertThat(refs.get(3).getNode().getLineno()).isEqualTo(4);
assertThat(refs.get(3).getNode().getCharno()).isEqualTo(25);
assertThat(refs.get(4).getNode().getLineno()).isEqualTo(7);
assertThat(refs.get(4).getNode().getCharno()).isEqualTo(13);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingFunctionScope_GlobalScopeNested.
@Test
public void testGetEnclosingFunctionScope_GlobalScopeNested() {
SymbolTable table = createSymbolTable("{ const baz = 1; }");
Symbol baz = getLocalVar(table, "baz");
SymbolScope bazFunctionScope = table.getEnclosingFunctionScope(baz.getDeclarationNode());
assertThat(bazFunctionScope).isNotNull();
assertThat(bazFunctionScope.isGlobalScope()).isTrue();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testLocalThisReferences.
@Test
public void testLocalThisReferences() {
SymbolTable table = createSymbolTable("/** @constructor */ function F() { this.foo = 3; this.bar = 5; }");
Symbol f = getGlobalVar(table, "F");
assertThat(f).isNotNull();
Symbol t = table.getParameterInFunction(f, "this");
assertThat(t).isNotNull();
List<Reference> refs = table.getReferenceList(t);
assertThat(refs).hasSize(2);
}
Aggregations