use of com.google.javascript.jscomp.SymbolTable.SymbolScope in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingFunctionScope_FunctionInsideFunction.
@Test
public void testGetEnclosingFunctionScope_FunctionInsideFunction() {
SymbolTable table = createSymbolTable("function foo() { function baz() {} }");
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 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();
}
use of com.google.javascript.jscomp.SymbolTable.SymbolScope in project closure-compiler by google.
the class SymbolTableTest method testGetEnclosingScope_FunctionNested.
@Test
public void testGetEnclosingScope_FunctionNested() {
SymbolTable table = createSymbolTable("function foo() { { const baz = 1; } }");
Symbol baz = getLocalVar(table, "baz");
SymbolScope bazScope = table.getEnclosingScope(baz.getDeclarationNode());
assertThat(bazScope).isNotNull();
assertThat(bazScope.isBlockScope()).isTrue();
assertThat(bazScope.getParentScope().isBlockScope()).isTrue();
Node foo = getGlobalVar(table, "foo").getDeclarationNode().getParent();
assertThat(bazScope.getParentScope().getParentScope().getRootNode()).isEqualTo(foo);
}
use of com.google.javascript.jscomp.SymbolTable.SymbolScope 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.SymbolScope 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);
}
Aggregations