use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method googModule_containsExports.
@Test
public void googModule_containsExports() {
GlobalNamespace namespace = parseAndGatherModuleData("goog.module('m'); const x = 0;");
ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
Name exports = namespace.getNameFromModule(metadata, "exports");
assertThat(exports.getGlobalSets()).isEqualTo(0);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method logicalAssignment2.
@Test
public void logicalAssignment2() {
GlobalNamespace namespace = parse("var a = a || (a = {});");
Name a = namespace.getSlot("a");
assertThat(a).isNotNull();
assertThat(a.getRefs()).hasSize(4);
assertThat(a.getLocalSets()).isEqualTo(0);
assertThat(a.getGlobalSets()).isEqualTo(2);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method testGoogProvideName.
@Test
public void testGoogProvideName() {
GlobalNamespace namespace = parse("goog.provide('a'); var a = {};");
Name a = namespace.getSlot("a");
assertThat(a).isNotNull();
assertThat(a.getGlobalSets()).isEqualTo(1);
// The VAR, not the goog.provide, is considered the 'declaration' of `a`.
assertNode(a.getDeclaration().getNode().getParent()).hasToken(Token.VAR);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method moduleLevelNamesAreCaptured_esExportFunctionDecl.
@Test
public void moduleLevelNamesAreCaptured_esExportFunctionDecl() {
GlobalNamespace namespace = parseAndGatherModuleData("export function fn() {}");
ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByPath().get("test.js");
Name x = namespace.getNameFromModule(metadata, "fn");
assertThat(x).isNotNull();
assertNode(x.getDeclaration().getNode().getParent()).hasToken(Token.FUNCTION);
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class GlobalNamespaceTest method updateRefNodeRejectsRedundantUpdate.
@Test
public void updateRefNodeRejectsRedundantUpdate() {
GlobalNamespace namespace = parse("const A = 3;");
Name nameA = namespace.getOwnSlot("A");
Ref refA = nameA.getFirstRef();
assertThrows(IllegalArgumentException.class, () -> nameA.updateRefNode(refA, refA.getNode()));
}
Aggregations