Search in sources :

Example 26 with Symbol

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

the class SymbolTableTest method testGlobalThisReferences2.

@Test
public void testGlobalThisReferences2() {
    // Make sure the global this is declared, even if it isn't referenced.
    SymbolTable table = createSymbolTable("");
    Symbol global = getGlobalVar(table, "*global*");
    assertThat(global).isNotNull();
    List<Reference> refs = table.getReferenceList(global);
    assertThat(refs).isEmpty();
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) Test(org.junit.Test)

Example 27 with Symbol

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

the class SymbolTableTest method testLocalThisReferences3.

// No 'this' reference is created for empty functions.
@Test
public void testLocalThisReferences3() {
    SymbolTable table = createSymbolTable("/** @constructor */ function F() {}");
    Symbol baz = getGlobalVar(table, "F");
    assertThat(baz).isNotNull();
    Symbol t = table.getParameterInFunction(baz, "this");
    assertThat(t).isNull();
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Test(org.junit.Test)

Example 28 with Symbol

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

the class SymbolTableTest method testPrototypeSymbolEqualityForTwoPathsToSamePrototype.

@Test
public void testPrototypeSymbolEqualityForTwoPathsToSamePrototype() {
    String input = lines("/**", "* An employer.", "*", "* @param {String} name name of employer.", "* @param {String} address address of employer.", "* @constructor", "*/", "function Employer(name, address) {", "this.name = name;", "this.address = address;", "}", "", "/**", "* @return {String} information about an employer.", "*/", "Employer.prototype.getInfo = function() {", "return this.name + '.' + this.address;", "};");
    SymbolTable table = createSymbolTable(input);
    Symbol employer = getGlobalVar(table, "Employer");
    assertThat(employer).isNotNull();
    SymbolScope propertyScope = employer.getPropertyScope();
    assertThat(propertyScope).isNotNull();
    Symbol prototypeOfEmployer = propertyScope.getQualifiedSlot("prototype");
    assertThat(prototypeOfEmployer).isNotNull();
    Symbol employerPrototype = getGlobalVar(table, "Employer.prototype");
    assertThat(employerPrototype).isNotNull();
    new EqualsTester().addEqualityGroup(employerPrototype, prototypeOfEmployer).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) SymbolScope(com.google.javascript.jscomp.SymbolTable.SymbolScope) Test(org.junit.Test)

Example 29 with Symbol

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

the class SymbolTableTest method testDeclarationDisagreement.

@Test
public void testDeclarationDisagreement() {
    SymbolTable table = createSymbolTable(lines("/** @const */ var goog = goog || {};", "/** @param {!Function} x */", "goog.addSingletonGetter2 = function(x) {};", "/** Wakka wakka wakka */", "goog.addSingletonGetter = goog.addSingletonGetter2;", "/** @param {!Function} x */", "goog.addSingletonGetter = function(x) {};"));
    Symbol method = getGlobalVar(table, "goog.addSingletonGetter");
    List<Reference> refs = table.getReferenceList(method);
    assertThat(refs).hasSize(2);
    // Note that the declaration should show up second.
    assertThat(method.getDeclaration().getNode().getLineno()).isEqualTo(7);
    assertThat(refs.get(1).getNode().getLineno()).isEqualTo(5);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference) Test(org.junit.Test)

Example 30 with Symbol

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

the class SymbolTableTest method testJSDocOnlySymbol.

@Test
public void testJSDocOnlySymbol() {
    SymbolTable table = createSymbolTable(lines("/**", " * @param {number} x", " * @param y", " */", "var a;"));
    Symbol x = getDocVar(table, "x");
    assertThat(x).isNotNull();
    assertThat(x.getType().toString()).isEqualTo("number");
    assertThat(table.getReferenceList(x)).hasSize(1);
    Symbol y = getDocVar(table, "y");
    assertThat(x).isNotNull();
    assertThat(y.getType()).isNull();
    assertThat(table.getReferenceList(y)).hasSize(1);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) 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