use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testEnumsProvidedAsMemberOfNamespace.
@Test
public void testEnumsProvidedAsMemberOfNamespace() {
SymbolTable table = createSymbolTableFromManySources(lines("goog.provide('foo.bar');", "/** @enum {number} */", "foo.bar.Color = {RED: 1};", "const /** !foo.bar.Color */ color = ", " foo.bar.Color.RED;"));
Symbol red = table.getAllSymbols().stream().filter((s) -> s.getName().equals("RED")).findFirst().get();
// Make sure that RED belongs to the scope of Color that is defined in the first file and not
// third. Because the third file also has "Color" enum that has the same type.
assertThat(table.getScope(red).getSymbolForScope().getSourceFileName()).isEqualTo("file1.js");
assertThat(table.getReferences(red)).hasSize(2);
Symbol colorEnum = table.getAllSymbols().stream().filter((s) -> s.getName().equals("Color")).findFirst().get();
assertThat(table.getReferences(colorEnum)).hasSize(3);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testReferencesInJSDocName.
@Test
public void testReferencesInJSDocName() {
String code = "/** @param {Object} x */ function f(x) {}";
SymbolTable table = createSymbolTable(code);
Symbol x = getLocalVar(table, "x");
assertThat(x).isNotNull();
List<Reference> refs = table.getReferenceList(x);
assertThat(refs).hasSize(2);
assertThat(refs.get(0).getNode().getCharno()).isEqualTo(code.indexOf("x) {"));
assertThat(refs.get(1).getNode().getCharno()).isEqualTo(code.indexOf("x */"));
assertThat(refs.get(0).getNode().getSourceFileName()).isEqualTo("in1");
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingScope_GlobalNested.
@Test
public void testGetEnclosingScope_GlobalNested() {
SymbolTable table = createSymbolTable("{ const baz = 1; }");
Symbol baz = getLocalVar(table, "baz");
SymbolScope bazScope = table.getEnclosingScope(baz.getDeclarationNode());
assertThat(bazScope).isNotNull();
assertThat(bazScope.isBlockScope()).isTrue();
assertThat(bazScope.getParentScope().isGlobalScope()).isTrue();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testMethodReferences.
@Test
public void testMethodReferences() {
SymbolTable table = createSymbolTable(lines("/** @constructor */ var DomHelper = function(){};", "/** method */ DomHelper.prototype.method = function() {};", "function f() { ", " (new DomHelper()).method(); (new DomHelper()).method(); };"));
Symbol method = getGlobalVar(table, "DomHelper.prototype.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 testGlobalThisReferences3.
@Test
public void testGlobalThisReferences3() {
SymbolTable table = createSymbolTable("this.foo = {}; this.foo.bar = {};");
Symbol global = getGlobalVar(table, "*global*");
assertThat(global).isNotNull();
List<Reference> refs = table.getReferenceList(global);
assertThat(refs).hasSize(2);
}
Aggregations