use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testIncompleteNamespacedReferences.
@Test
public void testIncompleteNamespacedReferences() {
SymbolTable table = createSymbolTable(lines("/** @constructor */", "my.dom.DomHelper = function(){};", "var y = my.dom.DomHelper;"));
Symbol my = getGlobalVar(table, "my");
assertThat(my).isNotNull();
assertThat(table.getReferenceList(my)).hasSize(2);
Symbol myDom = getGlobalVar(table, "my.dom");
assertThat(myDom).isNotNull();
assertThat(table.getReferenceList(myDom)).hasSize(2);
Symbol myDomHelper = getGlobalVar(table, "my.dom.DomHelper");
assertThat(myDomHelper).isNotNull();
assertThat(table.getReferences(myDomHelper)).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingScope_Global.
@Test
public void testGetEnclosingScope_Global() {
SymbolTable table = createSymbolTable("const baz = 1;");
Symbol baz = getGlobalVar(table, "baz");
SymbolScope bazScope = table.getEnclosingScope(baz.getDeclarationNode());
assertThat(bazScope).isNotNull();
assertThat(bazScope.isGlobalScope()).isTrue();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testSymbolForScopeOfNatives.
@Test
public void testSymbolForScopeOfNatives() {
SymbolTable table = createSymbolTableWithDefaultExterns("");
// From the externs.
Symbol sliceArg = getLocalVar(table, "sliceArg");
assertThat(sliceArg).isNotNull();
Symbol scope = table.getSymbolForScope(table.getScope(sliceArg));
assertThat(scope).isNotNull();
assertThat(getGlobalVar(table, "String.prototype.slice")).isEqualTo(scope);
Symbol proto = getGlobalVar(table, "String.prototype");
assertThat(proto.getDeclaration().getNode().getSourceFileName()).isEqualTo("externs1");
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method assertSymbolTableValid.
/**
* Asserts that the symbol table meets some invariants. Returns the same table for easy chaining.
*/
private SymbolTable assertSymbolTableValid(SymbolTable table) {
Set<Symbol> allSymbols = new HashSet<>();
allSymbols.addAll(table.getAllSymbols());
for (Symbol sym : table.getAllSymbols()) {
// Make sure that grabbing the symbol's scope and looking it up
// again produces the same symbol.
assertThat(table.getScope(sym).getQualifiedSlot(sym.getName())).isEqualTo(sym);
for (Reference ref : table.getReferences(sym)) {
// Make sure that the symbol and reference are mutually linked.
assertThat(ref.getSymbol()).isEqualTo(sym);
}
Symbol symbolForScope = table.getSymbolForScope(table.getScope(sym));
if (symbolForScope != null) {
assertWithMessage("The %s has a scope that shouldn't exist; a zombie scope.", sym).that(allSymbols).contains(symbolForScope);
}
}
// Make sure that the global "this" is declared at the first input root.
Symbol global = getGlobalVar(table, SymbolTable.GLOBAL_THIS);
assertThat(global).isNotNull();
assertThat(global.getDeclaration()).isNotNull();
assertThat(global.getDeclaration().getNode().getToken()).isEqualTo(Token.SCRIPT);
List<Reference> globalRefs = table.getReferenceList(global);
// The main reference list should never contain the synthetic declaration
// for the global root.
assertThat(globalRefs).doesNotContain(global.getDeclaration());
return table;
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testInnerEnum.
@Test
public void testInnerEnum() {
SymbolTable table = createSymbolTable("var goog = {}; goog.ui = {};" + " /** @constructor */" + "goog.ui.Zippy = function() {};" + "/** @enum {string} */" + "goog.ui.Zippy.EventType = { TOGGLE: 'toggle' };");
Symbol eventType = getGlobalVar(table, "goog.ui.Zippy.EventType");
assertThat(eventType).isNotNull();
assertThat(eventType.getType().isEnumType()).isTrue();
Symbol toggle = getGlobalVar(table, "goog.ui.Zippy.EventType.TOGGLE");
assertThat(toggle).isNotNull();
}
Aggregations