Search in sources :

Example 6 with Symbol

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

the class SymbolTableTest method testStaticMethodReferences.

@Test
public void testStaticMethodReferences() {
    SymbolTable table = createSymbolTable(lines("/** @constructor */ var DomHelper = function(){};", "/** method */ DomHelper.method = function() {};", "function f() { var x = DomHelper; x.method() + x.method(); }"));
    Symbol method = getGlobalVar(table, "DomHelper").getPropertyScope().getSlot("method");
    assertThat(table.getReferences(method)).hasSize(3);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 7 with Symbol

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

the class SymbolTableTest method testNaturalSymbolOrdering.

@Test
public void testNaturalSymbolOrdering() {
    SymbolTable table = createSymbolTable(lines("/** @const */ var a = {};", "/** @const */ a.b = {};", "/** @param {number} x */ function f(x) {}"));
    Symbol a = getGlobalVar(table, "a");
    Symbol ab = getGlobalVar(table, "a.b");
    Symbol f = getGlobalVar(table, "f");
    Symbol x = getLocalVar(table, "x");
    Ordering<Symbol> ordering = table.getNaturalSymbolOrdering();
    assertSymmetricOrdering(ordering, a, ab);
    assertSymmetricOrdering(ordering, a, f);
    assertSymmetricOrdering(ordering, f, ab);
    assertSymmetricOrdering(ordering, f, x);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 8 with Symbol

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

the class SymbolTableTest method testReferencesInJSDocType.

@Test
public void testReferencesInJSDocType() {
    SymbolTable table = createSymbolTable(lines("/** @constructor */ function Foo() {}", "/** @type {Foo} */ var x;", "/** @param {Foo} x */ function f(x) {}", "/** @return {function(): Foo} */ function g() {}", "/**", " * @constructor", " * @extends {Foo}", " */ function Sub() {}"));
    Symbol foo = getGlobalVar(table, "Foo");
    assertThat(foo).isNotNull();
    List<Reference> refs = table.getReferenceList(foo);
    assertThat(refs).hasSize(5);
    assertThat(refs.get(0).getNode().getLineno()).isEqualTo(1);
    assertThat(refs.get(0).getNode().getCharno()).isEqualTo(29);
    assertThat(refs.get(0).getNode().getLength()).isEqualTo(3);
    assertThat(refs.get(1).getNode().getLineno()).isEqualTo(2);
    assertThat(refs.get(1).getNode().getCharno()).isEqualTo(11);
    assertThat(refs.get(2).getNode().getLineno()).isEqualTo(3);
    assertThat(refs.get(2).getNode().getCharno()).isEqualTo(12);
    assertThat(refs.get(3).getNode().getLineno()).isEqualTo(4);
    assertThat(refs.get(3).getNode().getCharno()).isEqualTo(25);
    assertThat(refs.get(4).getNode().getLineno()).isEqualTo(7);
    assertThat(refs.get(4).getNode().getCharno()).isEqualTo(13);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) Test(org.junit.Test)

Example 9 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol 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();
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) SymbolScope(com.google.javascript.jscomp.SymbolTable.SymbolScope) Test(org.junit.Test)

Example 10 with Symbol

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

the class SymbolTableTest method testLocalThisReferences.

@Test
public void testLocalThisReferences() {
    SymbolTable table = createSymbolTable("/** @constructor */ function F() { this.foo = 3; this.bar = 5; }");
    Symbol f = getGlobalVar(table, "F");
    assertThat(f).isNotNull();
    Symbol t = table.getParameterInFunction(f, "this");
    assertThat(t).isNotNull();
    List<Reference> refs = table.getReferenceList(t);
    assertThat(refs).hasSize(2);
}
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