Search in sources :

Example 46 with Symbol

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

the class SymbolTableTest method testFieldReferencesMissingTypeInfo.

@Test
public void testFieldReferencesMissingTypeInfo() {
    SymbolTable table = createSymbolTable(lines("/**", " * @constructor", " * @extends {Missing}", " */ var DomHelper = function(){ this.prop = 1; };", "/** @type {number} */ DomHelper.prototype.prop = 2;", "function f() {", "  return (new DomHelper()).prop;", "};"));
    Symbol prop = getGlobalVar(table, "DomHelper.prototype.prop");
    assertThat(table.getReferenceList(prop)).hasSize(3);
    assertThat(getLocalVar(table, "this.prop")).isNull();
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 47 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol 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 48 with Symbol

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

the class SymbolTableTest method testMethodInAnonObject2.

@Test
public void testMethodInAnonObject2() {
    SymbolTable table = createSymbolTable("var a = {b: {c: function() {}}};");
    Symbol a = getGlobalVar(table, "a");
    Symbol ab = getGlobalVar(table, "a.b");
    Symbol abc = getGlobalVar(table, "a.b.c");
    assertThat(abc).isNotNull();
    assertThat(table.getReferenceList(abc)).hasSize(1);
    assertThat(a.getType().toString()).isEqualTo("{b: {c: function(): undefined}}");
    assertThat(ab.getType().toString()).isEqualTo("{c: function(): undefined}");
    assertThat(abc.getType().toString()).isEqualTo("function(): undefined");
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 49 with Symbol

use of com.google.javascript.jscomp.SymbolTable.Symbol 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 50 with Symbol

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

the class SymbolTableTest method testGetEnclosingFunctionScope_GlobalScopeNoNesting.

@Test
public void testGetEnclosingFunctionScope_GlobalScopeNoNesting() {
    SymbolTable table = createSymbolTable("const baz = 1;");
    Symbol baz = getGlobalVar(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)

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