Search in sources :

Example 16 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata in project closure-compiler by google.

the class GatherModuleMetadataTest method testGoogProvideWithGoogDeclaredInOtherFile.

@Test
public void testGoogProvideWithGoogDeclaredInOtherFile() {
    // Closure's base.js declare the global goog. It should be ignored when scanning the provide'd
    // file. Only local variables named goog should cause the pass to back off.
    testSame(srcs("var goog;", "goog.provide('my.provide');"));
    assertThat(metadataMap().getModulesByGoogNamespace().keySet()).containsExactly("my.provide");
    ModuleMetadata m = metadataMap().getModulesByGoogNamespace().get("my.provide");
    assertThat(m.googNamespaces()).containsExactly("my.provide");
    assertThat(m.isGoogProvide()).isTrue();
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Test(org.junit.Test)

Example 17 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata in project closure-compiler by google.

the class GatherModuleMetadataTest method testRequiredClosureNamespaces.

@Test
public void testRequiredClosureNamespaces() {
    testSame("goog.require('my.Type');");
    ModuleMetadata m = metadataMap().getModulesByPath().get("testcode");
    assertThat(m.stronglyRequiredGoogNamespaces()).containsExactly("my.Type");
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Test(org.junit.Test)

Example 18 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata in project closure-compiler by google.

the class GatherModuleMetadataTest method testBundleGoogLoadModuleAndProvides.

@Test
public void testBundleGoogLoadModuleAndProvides() {
    testSame(lines("goog.provide('some.provide');", "", "goog.provide('some.other.provide');", "", "goog.loadModule(function(exports) {", "  goog.module('multiple.calls.c0');", "  return exports;", "});", "", "goog.loadModule(function(exports) {", "  goog.module('multiple.calls.c1');", "  return exports;", "});"));
    assertThat(metadataMap().getModulesByGoogNamespace().keySet()).containsExactly("some.provide", "some.other.provide", "multiple.calls.c0", "multiple.calls.c1");
    ModuleMetadata m = metadataMap().getModulesByGoogNamespace().get("multiple.calls.c0");
    assertThat(m.googNamespaces()).containsExactly("multiple.calls.c0");
    assertThat(m.isNonLegacyGoogModule()).isTrue();
    assertThat(m.path()).isNull();
    assertThat(m.usesClosure()).isTrue();
    m = metadataMap().getModulesByGoogNamespace().get("multiple.calls.c1");
    assertThat(m.googNamespaces()).containsExactly("multiple.calls.c1");
    assertThat(m.isNonLegacyGoogModule()).isTrue();
    assertThat(m.path()).isNull();
    assertThat(m.usesClosure()).isTrue();
    m = metadataMap().getModulesByPath().get("testcode");
    assertThat(m.googNamespaces()).containsExactly("some.provide", "some.other.provide");
    assertThat(m.isGoogProvide()).isTrue();
    assertThat(m.usesClosure()).isTrue();
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Test(org.junit.Test)

Example 19 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata in project closure-compiler by google.

the class ModuleMapCreator method create.

private ModuleMap create() {
    unresolvedModules.clear();
    unresolvedModulesByClosureNamespace.clear();
    // goog.loadModule calls.
    for (ModuleMetadata moduleMetadata : moduleMetadataMap.getAllModuleMetadata()) {
        process(moduleMetadata);
    }
    return resolve();
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata)

Example 20 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata in project closure-compiler by google.

the class GlobalNamespaceTest method googModuleLevelNamesAreCaptured.

@Test
public void googModuleLevelNamesAreCaptured() {
    GlobalNamespace namespace = parseAndGatherModuleData("goog.module('m'); const x = 0;");
    ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
    Name x = namespace.getNameFromModule(metadata, "x");
    assertThat(x).isNotNull();
    assertThat(x.getDeclaration()).isNotNull();
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Aggregations

ModuleMetadata (com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata)61 Test (org.junit.Test)47 Name (com.google.javascript.jscomp.GlobalNamespace.Name)12 Node (com.google.javascript.rhino.Node)5 GatherModuleMetadata (com.google.javascript.jscomp.GatherModuleMetadata)2 Module (com.google.javascript.jscomp.modules.Module)2 BasicErrorManager (com.google.javascript.jscomp.BasicErrorManager)1 CheckLevel (com.google.javascript.jscomp.CheckLevel)1 Compiler (com.google.javascript.jscomp.Compiler)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 JSError (com.google.javascript.jscomp.JSError)1 GlobalizedModuleName (com.google.javascript.jscomp.ModuleRenaming.GlobalizedModuleName)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 ModuleLoader (com.google.javascript.jscomp.deps.ModuleLoader)1 Binding (com.google.javascript.jscomp.modules.Binding)1 ModuleMetadataMap (com.google.javascript.jscomp.modules.ModuleMetadataMap)1 Config (com.google.javascript.jscomp.parsing.Config)1 ParserRunner (com.google.javascript.jscomp.parsing.ParserRunner)1 Comment (com.google.javascript.jscomp.parsing.parser.trees.Comment)1 InputId (com.google.javascript.rhino.InputId)1