Search in sources :

Example 26 with Reference

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

the class SymbolTableTest method testPrototypeReferences_es6Class.

@Test
public void testPrototypeReferences_es6Class() {
    SymbolTable table = createSymbolTable(lines("class DomHelper { method() {} }"));
    Symbol prototype = getGlobalVar(table, "DomHelper.prototype");
    assertThat(prototype).isNotNull();
    List<Reference> refs = table.getReferenceList(prototype);
    // The class declaration creates an implicit .prototype reference.
    assertWithMessage(refs.toString()).that(refs).hasSize(1);
    assertNode(refs.get(0).getNode().getParent()).hasToken(Token.CLASS);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) Test(org.junit.Test)

Example 27 with Reference

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

the class SymbolTableTest method testGlobalThisReferences.

@Test
public void testGlobalThisReferences() {
    SymbolTable table = createSymbolTable("var x = this; function f() { return this + this + this; }");
    Symbol global = getGlobalVar(table, "*global*");
    assertThat(global).isNotNull();
    List<Reference> refs = table.getReferenceList(global);
    assertThat(refs).hasSize(1);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) Test(org.junit.Test)

Example 28 with Reference

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

Example 29 with Reference

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

the class SymbolTableTest method testLocalVarInExterns.

@Test
public void testLocalVarInExterns() {
    SymbolTable table = createSymbolTable("", "function customExternFn(customExternArg) {}");
    Symbol arg = getLocalVar(table, "customExternArg");
    List<Reference> refs = table.getReferenceList(arg);
    assertThat(refs).hasSize(1);
    Symbol fn = getGlobalVar(table, "customExternFn");
    SymbolScope scope = table.getEnclosingScope(refs.get(0).getNode());
    assertThat(scope.isGlobalScope()).isFalse();
    assertThat(table.getSymbolForScope(scope)).isEqualTo(fn);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) SymbolScope(com.google.javascript.jscomp.SymbolTable.SymbolScope) Test(org.junit.Test)

Aggregations

Reference (com.google.javascript.jscomp.SymbolTable.Reference)29 Symbol (com.google.javascript.jscomp.SymbolTable.Symbol)27 Test (org.junit.Test)27 SymbolScope (com.google.javascript.jscomp.SymbolTable.SymbolScope)2 HashMap (java.util.HashMap)2 Node (com.google.javascript.rhino.Node)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)1 HashSet (java.util.HashSet)1