use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method exerciseGoogRequireReferenceCorrectly.
private void exerciseGoogRequireReferenceCorrectly(String inputProvidingNamespace) {
SymbolTable table = createSymbolTableFromManySources(inputProvidingNamespace, lines("goog.provide('module.two');", "goog.require('module.one');", "goog.requireType('module.one');", "goog.forwardDeclare('module.one');"), lines("goog.module('module.three');", "const one = goog.require('module.one');", "const oneType = goog.requireType('module.one');", "const oneForward = goog.forwardDeclare('module.one');"), lines("goog.module('module.four');", "goog.module.declareLegacyNamespace();", "const one = goog.require('module.one');", "const oneType = goog.requireType('module.one');", "const oneForward = goog.forwardDeclare('module.one');"));
Symbol namespace = getGlobalVar(table, "ns$module.one");
assertThat(namespace).isNotNull();
// 1 ref from declaration and then 2 refs in each of 3 files.
assertThat(table.getReferences(namespace)).hasSize(10);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testObjectLiteral.
@Test
public void testObjectLiteral() {
SymbolTable table = createSymbolTable("var obj = {foo: 0};");
Symbol foo = getGlobalVar(table, "obj.foo");
assertThat(foo.getName()).isEqualTo("foo");
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testNamespaceReferencesInGoogRequire.
@Test
public void testNamespaceReferencesInGoogRequire() {
SymbolTable table = createSymbolTable(lines("goog.provide('my.dom');", "goog.require('my.dom');"));
Symbol googRequire = getGlobalVar(table, "ns$my.dom");
assertThat(googRequire).isNotNull();
assertThat(table.getReferences(googRequire)).hasSize(2);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testEnumsWithDirectExport.
@Test
public void testEnumsWithDirectExport() {
SymbolTable table = createSymbolTableFromManySources(lines("goog.module('foo');", "/** @enum {number} */", "exports.Color = {RED: 1}; // exports.Color = Color;"), 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();
assertThat(table.getScope(red).getSymbolForScope().getSourceFileName()).isEqualTo("file1.js");
assertThat(table.getReferences(red)).hasSize(3);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testSymbolSuperclassStaticInheritance.
@Test
public void testSymbolSuperclassStaticInheritance() {
// set this option so that typechecking sees untranspiled classes.
// TODO(b/76025401): remove this option after class transpilation is always post-typechecking
options.setSkipUnsupportedPasses(false);
SymbolTable table = createSymbolTable(lines("class Bar { static staticMethod() {} }", "class Foo extends Bar {", " act() { Foo.staticMethod(); }", "}"));
Symbol foo = getGlobalVar(table, "Foo");
Symbol bar = getGlobalVar(table, "Bar");
FunctionType barType = checkNotNull(bar.getType().toMaybeFunctionType());
FunctionType fooType = checkNotNull(foo.getType().toMaybeFunctionType());
FunctionType superclassCtorType = fooType.getSuperClassConstructor();
assertType(superclassCtorType).isEqualTo(barType);
Symbol superSymbol = table.getSymbolDeclaredBy(superclassCtorType);
assertThat(superSymbol).isEqualTo(bar);
Symbol barStaticMethod = getGlobalVar(table, "Bar.staticMethod");
ImmutableList<Reference> barStaticMethodRefs = table.getReferenceList(barStaticMethod);
assertThat(barStaticMethodRefs).hasSize(2);
assertThat(barStaticMethodRefs.get(0)).isEqualTo(barStaticMethod.getDeclaration());
// We recognize that the call to Foo.staticMethod() is actually a call to Bar.staticMethod().
assertNode(barStaticMethodRefs.get(1).getNode()).matchesQualifiedName("Foo.staticMethod");
}
Aggregations