Search in sources :

Example 1 with Symbol

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

the class SymbolTableTest method testReferencesInJSDocName.

public void testReferencesInJSDocName() {
    String code = "/** @param {Object} x */ function f(x) {}\n";
    SymbolTable table = createSymbolTable(code);
    Symbol x = getLocalVar(table, "x");
    assertNotNull(x);
    List<Reference> refs = table.getReferenceList(x);
    assertThat(refs).hasSize(2);
    assertEquals(code.indexOf("x) {"), refs.get(0).getNode().getCharno());
    assertEquals(code.indexOf("x */"), refs.get(1).getNode().getCharno());
    assertEquals("in1", refs.get(0).getNode().getSourceFileName());
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference)

Example 2 with Symbol

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

the class SymbolTableTest method testPrototypeSymbolEqualityForTwoPathsToSamePrototype.

public void testPrototypeSymbolEqualityForTwoPathsToSamePrototype() {
    String input = lines("/**\n", "* An employer.\n", "*\n", "* @param {String} name name of employer.\n", "* @param {String} address address of employer.\n", "* @constructor\n", "*/\n", "function Employer(name, address) {\n", "this.name = name;\n", "this.address = address;\n", "}\n", "\n", "/**\n", "* @return {String} information about an employer.\n", "*/\n", "Employer.prototype.getInfo = function() {\n", "return this.name + '.' + this.address;\n", "};");
    SymbolTable table = createSymbolTable(input);
    Symbol employer = getGlobalVar(table, "Employer");
    assertNotNull(employer);
    SymbolScope propertyScope = employer.getPropertyScope();
    assertNotNull(propertyScope);
    Symbol prototypeOfEmployer = propertyScope.getQualifiedSlot("prototype");
    assertNotNull(prototypeOfEmployer);
    Symbol employerPrototype = getGlobalVar(table, "Employer.prototype");
    assertNotNull(employerPrototype);
    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)

Example 3 with Symbol

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

the class SymbolTableTest method testGlobalThisReferences2.

public void testGlobalThisReferences2() throws Exception {
    // Make sure the global this is declared, even if it isn't referenced.
    SymbolTable table = createSymbolTable("");
    Symbol global = getGlobalVar(table, "*global*");
    assertNotNull(global);
    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)

Example 4 with Symbol

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

the class SymbolTableTest method testJSDocOnlySymbol.

public void testJSDocOnlySymbol() throws Exception {
    SymbolTable table = createSymbolTable("/**\n" + " * @param {number} x\n" + " * @param y\n" + " */\n" + "var a;");
    Symbol x = getDocVar(table, "x");
    assertNotNull(x);
    assertEquals("number", x.getType().toString());
    assertThat(table.getReferenceList(x)).hasSize(1);
    Symbol y = getDocVar(table, "y");
    assertNotNull(x);
    assertNull(y.getType());
    assertThat(table.getReferenceList(y)).hasSize(1);
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol)

Example 5 with Symbol

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

the class SymbolTableTest method testPrototypeReferences4.

public void testPrototypeReferences4() throws Exception {
    SymbolTable table = createSymbolTable("/** @constructor */ function Foo() {}" + "Foo.prototype = {bar: 3}");
    Symbol fooPrototype = getGlobalVar(table, "Foo.prototype");
    assertNotNull(fooPrototype);
    List<Reference> refs = ImmutableList.copyOf(table.getReferences(fooPrototype));
    assertThat(refs).hasSize(1);
    assertEquals(Token.GETPROP, refs.get(0).getNode().getToken());
    assertEquals("Foo.prototype", refs.get(0).getNode().getQualifiedName());
}
Also used : Symbol(com.google.javascript.jscomp.SymbolTable.Symbol) Reference(com.google.javascript.jscomp.SymbolTable.Reference)

Aggregations

Symbol (com.google.javascript.jscomp.SymbolTable.Symbol)55 Reference (com.google.javascript.jscomp.SymbolTable.Reference)23 SymbolScope (com.google.javascript.jscomp.SymbolTable.SymbolScope)3 EqualsTester (com.google.common.testing.EqualsTester)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1 HashSet (java.util.HashSet)1