use of com.google.javascript.jscomp.SymbolTable.Symbol 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.Symbol in project closure-compiler by google.
the class SymbolTableTest method testClassPropertiesDisableModuleRewriting.
@Test
public void testClassPropertiesDisableModuleRewriting() {
SymbolTable table = createSymbolTableFromManySources(lines("goog.module('foo');", "class Person {", " constructor() {", " /** @type {string} */", " this.lastName;", " }", "}", "exports = {Person};"), lines("goog.module('bar');", "const {Person} = goog.require('foo');", "let /** !Person */ p;", "p.lastName;"));
Symbol lastName = table.getAllSymbols().stream().filter((s) -> s.getName().equals("lastName")).findFirst().get();
assertThat(table.getReferences(lastName)).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testRestParameter.
@Test
public void testRestParameter() {
String input = "function f(...x) {} f(1, 2, 3);";
SymbolTable table = createSymbolTable(input);
Symbol f = getGlobalVar(table, "f");
assertThat(f).isNotNull();
Symbol x = table.getParameterInFunction(f, "x");
assertThat(x).isNotNull();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testEnums.
@Test
public void testEnums() {
SymbolTable table = createSymbolTableFromManySources(lines("goog.module('foo');", "/** @enum {number} */", "const Color = {RED: 1};", "exports.Color = Color;", "Color.RED;"), lines("goog.module('bar');", "const foo = goog.require('foo');", "foo.Color.RED;"), lines("goog.module('baz');", "const {Color} = goog.require('foo');", "Color.RED;"));
Symbol red = table.getAllSymbols().stream().filter((s) -> s.getName().equals("RED")).findFirst().get();
// Make sure that RED belongs to the scope of Color that is defined in the first file and not
// third. Because the third file also has "Color" enum that has the same type.
assertThat(table.getScope(red).getSymbolForScope().getSourceFileName()).isEqualTo("file1.js");
assertThat(table.getReferences(red)).hasSize(4);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testLocalVarReferences.
@Test
public void testLocalVarReferences() {
SymbolTable table = createSymbolTable("function f(x) { return x; }");
Symbol x = getLocalVar(table, "x");
List<Reference> refs = table.getReferenceList(x);
assertThat(refs).hasSize(2);
assertThat(refs.get(0)).isEqualTo(x.getDeclaration());
assertThat(refs.get(0).getNode().getParent().getToken()).isEqualTo(Token.PARAM_LIST);
assertThat(refs.get(1).getNode().getParent().getToken()).isEqualTo(Token.RETURN);
}
Aggregations