use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testFieldReferencesMissingTypeInfo.
@Test
public void testFieldReferencesMissingTypeInfo() {
SymbolTable table = createSymbolTable(lines("/**", " * @constructor", " * @extends {Missing}", " */ var DomHelper = function(){ this.prop = 1; };", "/** @type {number} */ DomHelper.prototype.prop = 2;", "function f() {", " return (new DomHelper()).prop;", "};"));
Symbol prop = getGlobalVar(table, "DomHelper.prototype.prop");
assertThat(table.getReferenceList(prop)).hasSize(3);
assertThat(getLocalVar(table, "this.prop")).isNull();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol 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.Symbol in project closure-compiler by google.
the class SymbolTableTest method testMethodInAnonObject2.
@Test
public void testMethodInAnonObject2() {
SymbolTable table = createSymbolTable("var a = {b: {c: function() {}}};");
Symbol a = getGlobalVar(table, "a");
Symbol ab = getGlobalVar(table, "a.b");
Symbol abc = getGlobalVar(table, "a.b.c");
assertThat(abc).isNotNull();
assertThat(table.getReferenceList(abc)).hasSize(1);
assertThat(a.getType().toString()).isEqualTo("{b: {c: function(): undefined}}");
assertThat(ab.getType().toString()).isEqualTo("{c: function(): undefined}");
assertThat(abc.getType().toString()).isEqualTo("function(): undefined");
}
use of com.google.javascript.jscomp.SymbolTable.Symbol 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.Symbol in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingFunctionScope_GlobalScopeNoNesting.
@Test
public void testGetEnclosingFunctionScope_GlobalScopeNoNesting() {
SymbolTable table = createSymbolTable("const baz = 1;");
Symbol baz = getGlobalVar(table, "baz");
SymbolScope bazFunctionScope = table.getEnclosingFunctionScope(baz.getDeclarationNode());
assertThat(bazFunctionScope).isNotNull();
assertThat(bazFunctionScope.isGlobalScope()).isTrue();
}
Aggregations