Search in sources :

Example 31 with ModuleMetadata

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

the class CheckClosureImportsTest method getProcessor.

@Override
protected CompilerPass getProcessor(Compiler compiler) {
    ModuleMetadata testMetadata = ModuleMetadata.builder().addGoogNamespace("test").moduleType(moduleType).usesClosure(true).isTestOnly(false).build();
    ModuleMetadataMap metadata = useDefaultModuleMetadata ? new ModuleMetadataMap(ImmutableMap.of(PROVIDES_SYMBOL_PATH, PROVIDES_SYMBOL_METADATA, ES_MODULE_PATH, ES_MODULE_METADATA, TEST_CODE_PATH, testMetadata, "externs", EXTERN_METADATA), ImmutableMap.of("symbol", PROVIDES_SYMBOL_METADATA, "es.module", ES_MODULE_METADATA, "test", testMetadata)) : compiler.getModuleMetadataMap();
    return new CheckClosureImports(compiler, metadata);
}
Also used : ModuleMetadataMap(com.google.javascript.jscomp.modules.ModuleMetadataMap) ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata)

Example 32 with ModuleMetadata

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

the class GlobalNamespaceTest method esModuleLevelNamesAreCaptured.

@Test
public void esModuleLevelNamesAreCaptured() {
    GlobalNamespace namespace = parseAndGatherModuleData("class Foo {} Foo.Bar = 0; export {Foo};");
    ModuleMetadata metadata = lastCompiler.getModuleMetadataMap().getModulesByPath().get("test.js");
    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 33 with ModuleMetadata

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

the class GlobalNamespaceTest method moduleLevelNamesAreCaptured_esExportDefaultFunctionDecl.

@Test
public void moduleLevelNamesAreCaptured_esExportDefaultFunctionDecl() {
    GlobalNamespace namespace = parseAndGatherModuleData("export default 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);
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 34 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata 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);
}
Also used : ModuleMetadata(com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata) Name(com.google.javascript.jscomp.GlobalNamespace.Name) Test(org.junit.Test)

Example 35 with ModuleMetadata

use of com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata 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);
}
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