use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences_es6Class.
@Test
public void testPrototypeReferences_es6Class() {
SymbolTable table = createSymbolTable(lines("class DomHelper { method() {} }"));
Symbol prototype = getGlobalVar(table, "DomHelper.prototype");
assertThat(prototype).isNotNull();
List<Reference> refs = table.getReferenceList(prototype);
// The class declaration creates an implicit .prototype reference.
assertWithMessage(refs.toString()).that(refs).hasSize(1);
assertNode(refs.get(0).getNode().getParent()).hasToken(Token.CLASS);
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testGlobalThisReferences.
@Test
public void testGlobalThisReferences() {
SymbolTable table = createSymbolTable("var x = this; function f() { return this + this + this; }");
Symbol global = getGlobalVar(table, "*global*");
assertThat(global).isNotNull();
List<Reference> refs = table.getReferenceList(global);
assertThat(refs).hasSize(1);
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testGlobalVarInExterns.
@Test
public void testGlobalVarInExterns() {
SymbolTable table = createSymbolTable("customExternFn(1);", "function customExternFn(customExternArg) {}");
Symbol fn = getGlobalVar(table, "customExternFn");
List<Reference> refs = table.getReferenceList(fn);
assertThat(refs).hasSize(3);
SymbolScope scope = table.getEnclosingScope(refs.get(0).getNode());
assertThat(scope.isGlobalScope()).isTrue();
assertThat(table.getSymbolForScope(scope).getName()).isEqualTo(SymbolTable.GLOBAL_THIS);
}
use of com.google.javascript.jscomp.SymbolTable.Reference in project closure-compiler by google.
the class SymbolTableTest method testLocalVarInExterns.
@Test
public void testLocalVarInExterns() {
SymbolTable table = createSymbolTable("", "function customExternFn(customExternArg) {}");
Symbol arg = getLocalVar(table, "customExternArg");
List<Reference> refs = table.getReferenceList(arg);
assertThat(refs).hasSize(1);
Symbol fn = getGlobalVar(table, "customExternFn");
SymbolScope scope = table.getEnclosingScope(refs.get(0).getNode());
assertThat(scope.isGlobalScope()).isFalse();
assertThat(table.getSymbolForScope(scope)).isEqualTo(fn);
}
Aggregations