Search in sources :

Example 21 with ModuleMetadata

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

the class GlobalNamespaceTest method googModuleLevelQualifiedNamesAreCaptured.

@Test
public void googModuleLevelQualifiedNamesAreCaptured() {
    GlobalNamespace namespace = parseAndGatherModuleData("goog.module('m'); class Foo {} Foo.Bar = 0;");
    ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
    Name x = namespace.getNameFromModule(metadata, "Foo.Bar");
    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)

Example 22 with ModuleMetadata

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

the class GlobalNamespaceTest method googLoadModule_containsExportsPropertyAssignments.

@Test
public void googLoadModule_containsExportsPropertyAssignments() {
    GlobalNamespace namespace = parseAndGatherModuleData(lines("goog.loadModule(function(exports) {", "  goog.module('m');", "  exports.Foo = class {};", "  return exports;", "});"));
    ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
    Name exportsFoo = namespace.getNameFromModule(metadata, "exports.Foo");
    assertThat(exportsFoo.getGlobalSets()).isEqualTo(1);
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 23 with ModuleMetadata

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

the class GlobalNamespaceTest method googLoadModule_containsExports.

@Test
public void googLoadModule_containsExports() {
    GlobalNamespace namespace = parseAndGatherModuleData(lines("goog.loadModule(function(exports) {", "  goog.module('m');", "  const x = 0;", "  return exports;", "});"));
    ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByGoogNamespace().get("m");
    Name exports = namespace.getNameFromModule(metadata, "exports");
    assertThat(exports.getGlobalSets()).isEqualTo(0);
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 24 with ModuleMetadata

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

the class TypedScopeCreator method containingGoogModuleIdOf.

@Nullable
static String containingGoogModuleIdOf(TypedScope scope) {
    Module module = scope.getModule();
    if (module == null) {
        TypedScope parent = scope.getParent();
        return (parent != null) ? containingGoogModuleIdOf(parent) : null;
    }
    // Stop recursing once we've hit a module scope.
    ModuleMetadata metadata = module.metadata();
    checkState(metadata.isModule(), metadata);
    /**
     * This module may not have a goog.module/goog.declareModuleId. Also don't crash if it's
     * malformed with multiple module IDs.
     */
    return Iterables.getFirst(metadata.googNamespaces(), null);
}
Also used : StaticTypedScope(com.google.javascript.rhino.jstype.StaticTypedScope) ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Module(com.google.javascript.jscomp.modules.Module) Nullable(javax.annotation.Nullable)

Example 25 with ModuleMetadata

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

the class PolymerBehaviorExtractor method resolveGoogModuleGet.

private ResolveBehaviorNameResult resolveGoogModuleGet(String moduleNamespace) {
    ModuleMetadata closureModule = moduleMetadataMap.getModulesByGoogNamespace().get(moduleNamespace);
    if (closureModule == null) {
        // Invalid goog.module.get() call.
        return FAILED_RESOLVE_RESULT;
    } else if (closureModule.isGoogProvide()) {
        return resolveBehaviorName(moduleNamespace, null);
    }
    checkState(closureModule.isGoogModule(), closureModule);
    return resolveBehaviorName(GOOG_MODULE_EXPORTS, closureModule);
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata)

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