Search in sources :

Example 36 with Symbol

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

the class SymbolTableTest method testJSDocAssociationWithBadNamespace.

@Test
public void testJSDocAssociationWithBadNamespace() {
    SymbolTable table = createSymbolTable(// about goog.Foo.
    "/** @constructor */ goog.Foo = function(){};");
    Symbol foo = getGlobalVar(table, "goog.Foo");
    assertThat(foo).isNotNull();
    JSDocInfo info = foo.getJSDocInfo();
    assertThat(info).isNotNull();
    assertThat(info.isConstructor()).isTrue();
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) JSDocInfo(com.google.javascript.rhino.JSDocInfo) Test(org.junit.Test)

Example 37 with Symbol

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

the class SymbolTableTest method testGetEnclosingFunctionScope_FunctionNoNestedScopes.

@Test
public void testGetEnclosingFunctionScope_FunctionNoNestedScopes() {
    SymbolTable table = createSymbolTable("function foo() { const baz = 1; }");
    Symbol baz = getLocalVar(table, "baz");
    SymbolScope bazFunctionScope = table.getEnclosingFunctionScope(baz.getDeclarationNode());
    assertThat(bazFunctionScope).isNotNull();
    Node foo = getGlobalVar(table, "foo").getDeclarationNode().getParent();
    assertThat(bazFunctionScope.getRootNode()).isEqualTo(foo);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) SymbolScope(com.google.javascript.jscomp.SymbolTable.SymbolScope) Test(org.junit.Test)

Example 38 with Symbol

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

the class SymbolTableTest method testObjectLiteralWithNewlineInKey.

public void testObjectLiteralWithNewlineInKey() throws Exception {
    SymbolTable table = createSymbolTable("var obj = {'foo\\nbar': 0};");
    Symbol foo = getGlobalVar(table, "obj.foo\\nbar");
    assertThat(foo.getName()).isEqualTo("obj.foo\\nbar");
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol)

Example 39 with Symbol

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

the class SymbolTableTest method testObjectLiteralQuoted.

public void testObjectLiteralQuoted() throws Exception {
    SymbolTable table = createSymbolTable("var obj = {'foo': 0};");
    Symbol foo = getGlobalVar(table, "obj.foo");
    assertThat(foo.getName()).isEqualTo("foo");
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol)

Example 40 with Symbol

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

the class SymbolTableTest method testGlobalThisPropertyReferences.

@Test
public void testGlobalThisPropertyReferences() {
    SymbolTable table = createSymbolTable("/** @constructor */ function Foo() {} this.Foo;");
    Symbol foo = getGlobalVar(table, "Foo");
    assertThat(foo).isNotNull();
    List<Reference> refs = table.getReferenceList(foo);
    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