Search in sources :

Example 41 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.

the class SymbolTableTest method testNamespacedReferences.

@Test
public void testNamespacedReferences() {
    // Because the type of 'my' is anonymous, we build its properties into
    // the global scope.
    SymbolTable table = createSymbolTable(lines("var my = {};", "my.dom = {};", "my.dom.DomHelper = function(){};"));
    Symbol my = getGlobalVar(table, "my");
    assertThat(my).isNotNull();
    assertThat(table.getReferences(my)).hasSize(3);
    Symbol myDom = getGlobalVar(table, "my.dom");
    assertThat(myDom).isNotNull();
    assertThat(table.getReferences(myDom)).hasSize(2);
    Symbol myDomHelper = getGlobalVar(table, "my.dom.DomHelper");
    assertThat(myDomHelper).isNotNull();
    assertThat(table.getReferences(myDomHelper)).hasSize(1);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 42 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.

the class SymbolTableTest method testLocalQualifiedNamesInLocalScopes.

@Test
public void testLocalQualifiedNamesInLocalScopes() {
    SymbolTable table = createSymbolTable("function f() { var x = {}; x.number = 3; }");
    Symbol xNumber = getLocalVar(table, "x.number");
    assertThat(xNumber).isNotNull();
    assertThat(table.getScope(xNumber).isGlobalScope()).isFalse();
    assertThat(xNumber.getType().toString()).isEqualTo("number");
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 43 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.

the class SymbolTableTest method testSuperClassMethodReferences.

@Test
public void testSuperClassMethodReferences() {
    SymbolTable table = createSymbolTable(lines("var goog = {};", "goog.inherits = function(a, b) {};", "/** @constructor */ var A = function(){};", "/** method */ A.prototype.method = function() {};", "/**", " * @constructor", " * @extends {A}", " */", "var B = function(){};", "goog.inherits(B, A);", "/** method */ B.prototype.method = function() {", "  B.superClass_.method();", "};"));
    Symbol methodA = getGlobalVar(table, "A.prototype.method");
    assertThat(table.getReferences(methodA)).hasSize(2);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 44 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.

the class SymbolTableTest method testGoogScopeReferences.

@Test
public void testGoogScopeReferences() {
    SymbolTable table = createSymbolTableWithDefaultExterns(// goog.scope is defined in the default externs, among other Closure methods
    lines("goog.scope(function() {});"));
    Symbol googScope = getGlobalVar(table, "goog.scope");
    assertThat(googScope).isNotNull();
    assertThat(table.getReferences(googScope)).hasSize(2);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 45 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.

the class SymbolTableTest method testSuperKeywords.

@Test
public void testSuperKeywords() {
    SymbolTable table = createSymbolTable(lines("class Parent { doFoo() {} }", "class Child extends Parent {", "  constructor() { super(); }", "  doFoo() { super.doFoo(); }", "}"));
    Symbol parentClass = getGlobalVar(table, "Parent");
    long numberOfSuperReferences = table.getReferenceList(parentClass).stream().filter((Reference ref) -> ref.getNode().isSuper()).count();
    // TODO(b/112359882): change number of refs to 2 once Es6ConvertSuper pass is moved after type
    // checks.
    assertThat(numberOfSuperReferences).isEqualTo(1);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) Test(org.junit.Test)

Aggregations

Symbol (com.google.javascript.jscomp.SymbolTable.Symbol)78 Test (org.junit.Test)71 Reference (com.google.javascript.jscomp.SymbolTable.Reference)29 SymbolScope (com.google.javascript.jscomp.SymbolTable.SymbolScope)11 Node (com.google.javascript.rhino.Node)5 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)5 EqualsTester (com.google.common.testing.EqualsTester)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 HashSet (java.util.HashSet)1