use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testUndeclaredFieldReferences.
@Test
public void testUndeclaredFieldReferences() {
// We do not currently create symbol table entries for undeclared fields,
// but this may change in the future.
SymbolTable table = createSymbolTable(lines("/** @constructor */ var DomHelper = function(){};", "DomHelper.prototype.method = function() { ", " this.field = 3;", " return x.field;", "}"));
Symbol field = getGlobalVar(table, "DomHelper.prototype.field");
assertThat(field).isNull();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testSourceInfoForProvidedSymbol.
@Test
public void testSourceInfoForProvidedSymbol() {
SymbolTable table = createSymbolTable(lines("goog.provide('foo.bar.Baz'); foo.bar.Baz = class {};"));
Symbol foo = getGlobalVar(table, "foo");
assertThat(foo).isNotNull();
// goog.provide doesn't define foo. Instead foo is declared by the firts occurence in actual
// code.
assertNode(table.getReferenceList(foo).get(0).getNode()).hasCharno(29);
Symbol fooBar = getGlobalVar(table, "foo.bar");
assertThat(fooBar).isNotNull();
assertNode(table.getReferenceList(fooBar).get(0).getNode()).hasCharno(33);
Symbol fooBarBaz = getGlobalVar(table, "foo.bar.Baz");
assertThat(fooBarBaz).isNotNull();
assertNode(table.getReferenceList(fooBarBaz).get(0).getNode()).hasCharno(37);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testRemovalOfNamespacedReferencesOfProperties.
@Test
public void testRemovalOfNamespacedReferencesOfProperties() {
SymbolTable table = createSymbolTable(lines("/** @constructor */ var DomHelper = function(){};", "/** method */ DomHelper.method = function() {};"));
Symbol domHelper = getGlobalVar(table, "DomHelper");
assertThat(domHelper).isNotNull();
Symbol domHelperNamespacedMethod = getGlobalVar(table, "DomHelper.method");
assertThat(domHelperNamespacedMethod.getName()).isEqualTo("method");
Symbol domHelperMethod = domHelper.getPropertyScope().getSlot("method");
assertThat(domHelperMethod).isNotNull();
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testDottedReferencesInJSDocType.
@Test
public void testDottedReferencesInJSDocType() {
SymbolTable table = createSymbolTable(lines("var goog = {};", "/** @constructor */ goog.Foo = function() {}", "/** @type {goog.Foo} */ var x;", "/** @param {goog.Foo} x */ function f(x) {}", "/** @return {function(): goog.Foo} */ function g() {}", "/**", " * @constructor", " * @extends {goog.Foo}", " */ function Sub() {}"));
Symbol foo = getGlobalVar(table, "goog.Foo");
assertThat(foo).isNotNull();
List<Reference> refs = table.getReferenceList(foo);
assertThat(refs).hasSize(5);
assertThat(refs.get(0).getNode().getLineno()).isEqualTo(2);
assertThat(refs.get(0).getNode().getCharno()).isEqualTo(25);
assertThat(refs.get(0).getNode().getLength()).isEqualTo(3);
assertThat(refs.get(1).getNode().getLineno()).isEqualTo(3);
assertThat(refs.get(1).getNode().getCharno()).isEqualTo(16);
assertThat(refs.get(2).getNode().getLineno()).isEqualTo(4);
assertThat(refs.get(2).getNode().getCharno()).isEqualTo(17);
assertThat(refs.get(3).getNode().getLineno()).isEqualTo(5);
assertThat(refs.get(3).getNode().getCharno()).isEqualTo(30);
assertThat(refs.get(4).getNode().getLineno()).isEqualTo(8);
assertThat(refs.get(4).getNode().getCharno()).isEqualTo(18);
}
use of com.google.javascript.jscomp.SymbolTable.Symbol in project closure-compiler by google.
the class SymbolTableTest method testPrototypeReferences.
@Test
public void testPrototypeReferences() {
SymbolTable table = createSymbolTable(lines("/** @constructor */ function DomHelper() {}", "DomHelper.prototype.method = function() {};"));
Symbol prototype = getGlobalVar(table, "DomHelper.prototype");
assertThat(prototype).isNotNull();
List<Reference> refs = table.getReferenceList(prototype);
// One of the refs is implicit in the declaration of the function.
assertWithMessage(refs.toString()).that(refs).hasSize(2);
}
Aggregations