use of com.google.javascript.jscomp.SymbolTable.SymbolScope in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingFunctionScope_FunctionNoNestedScopes.
@Test
public void testGetEnclosingFunctionScope_FunctionNoNestedScopes() {
SymbolTable table = createSymbolTable("function foo() { const baz = 1; }");
Symbol baz = getLocalVar(table, "baz");
SymbolScope bazFunctionScope = table.getEnclosingFunctionScope(baz.getDeclarationNode());
assertThat(bazFunctionScope).isNotNull();
Node foo = getGlobalVar(table, "foo").getDeclarationNode().getParent();
assertThat(bazFunctionScope.getRootNode()).isEqualTo(foo);
}
use of com.google.javascript.jscomp.SymbolTable.SymbolScope 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.SymbolScope in project closure-compiler by google.
the class SymbolTableTest method testPrototypeSymbolEqualityForTwoPathsToSamePrototype.
@Test
public void testPrototypeSymbolEqualityForTwoPathsToSamePrototype() {
String input = lines("/**", "* An employer.", "*", "* @param {String} name name of employer.", "* @param {String} address address of employer.", "* @constructor", "*/", "function Employer(name, address) {", "this.name = name;", "this.address = address;", "}", "", "/**", "* @return {String} information about an employer.", "*/", "Employer.prototype.getInfo = function() {", "return this.name + '.' + this.address;", "};");
SymbolTable table = createSymbolTable(input);
Symbol employer = getGlobalVar(table, "Employer");
assertThat(employer).isNotNull();
SymbolScope propertyScope = employer.getPropertyScope();
assertThat(propertyScope).isNotNull();
Symbol prototypeOfEmployer = propertyScope.getQualifiedSlot("prototype");
assertThat(prototypeOfEmployer).isNotNull();
Symbol employerPrototype = getGlobalVar(table, "Employer.prototype");
assertThat(employerPrototype).isNotNull();
new EqualsTester().addEqualityGroup(employerPrototype, prototypeOfEmployer).testEquals();
}
use of com.google.javascript.jscomp.SymbolTable.SymbolScope 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.SymbolScope in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingFunctionScope_FunctionNested.
@Test
public void testGetEnclosingFunctionScope_FunctionNested() {
SymbolTable table = createSymbolTable("function foo() { { { const baz = 1; } } }");
Symbol baz = getLocalVar(table, "baz");
SymbolScope bazFunctionScope = table.getEnclosingFunctionScope(baz.getDeclarationNode());
assertThat(bazFunctionScope).isNotNull();
Node foo = getGlobalVar(table, "foo").getDeclarationNode().getParent();
assertThat(bazFunctionScope.getRootNode()).isEqualTo(foo);
}
Aggregations