Class Module
- java.lang.Object
-
- com.google.javascript.jscomp.modules.Module
-
public abstract class Module extends java.lang.Object
Information for modules, particularly ES modules, that is useful for rewriting. The primary pieces of information are what variables are exported (transitive or local), and what names are imported.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Module.Builder
Builder forModule
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract com.google.common.collect.ImmutableMap<java.lang.String,Binding>
boundNames()
Map of local identifiers to originating binding.static Module.Builder
builder()
Creates a new builder.abstract @Nullable java.lang.String
closureNamespace()
The specific Closure namespace this module represents, if any.abstract com.google.common.collect.ImmutableMap<java.lang.String,Export>
localNameToLocalExport()
Map of local identifier name to local export definition.abstract ModuleMetadataMap.ModuleMetadata
metadata()
abstract com.google.common.collect.ImmutableMap<java.lang.String,Binding>
namespace()
Map of exported identifiers to originating binding.abstract @Nullable ModuleLoader.ModulePath
path()
Path of this module.abstract Module.Builder
toBuilder()
Returns this module in builder form.
-
-
-
Method Detail
-
metadata
public abstract ModuleMetadataMap.ModuleMetadata metadata()
-
path
public abstract @Nullable ModuleLoader.ModulePath path()
Path of this module. Null if this module is a nestedgoog.loadModule
.
-
namespace
public abstract com.google.common.collect.ImmutableMap<java.lang.String,Binding> namespace()
Map of exported identifiers to originating binding.Note that the keys are different than
boundNames()
. Here the keys are the exported name, not the local name.Examples:
- Locally defined exports (e.g.
export let x;
,let x; export {x as v};
) creates an entry with the exported name for the local module's export definition. export default function foo() {};
creates an entry with the name "default" for the local module's default export definition.export {x as v} from 'mod';
creates an entry with the name "v" for the export definition x from 'mod'.import
statements make no entries on their own. If imported values are exported withexport {};
then an entry is created likeexport {} from
.exports.foo = bar;
creates an entry with the name "foo" for the expression on the right-hand side. This is not bound to a local name.
- Locally defined exports (e.g.
-
boundNames
public abstract com.google.common.collect.ImmutableMap<java.lang.String,Binding> boundNames()
Map of local identifiers to originating binding.This includes all names bound by import and exported names which originate in this module. Used for rewriting in later stages of the compiler.
ES modules may have names bound by both imports and exports. Closure modules only have names bound by imports, as it is impossible to create a new local identifier in an export.
Examples:
import {x as v} from 'mod';
creates an entry with the name "v" for the export definition x from 'mod'.import * as ns from 'mod';
creates an entry with the name "ns" with a binding containing all of mod's bindings.export default function foo() {}
creates an entry with the name "foo" for the local module's export definition.export {x as v} from 'mod';
does not create any entry in this module.const C = goog.require('mod.C')
creates an entry with the name "C" for the binding containing the default export of 'mod.C'
-
localNameToLocalExport
public abstract com.google.common.collect.ImmutableMap<java.lang.String,Export> localNameToLocalExport()
Map of local identifier name to local export definition.
-
closureNamespace
public abstract @Nullable java.lang.String closureNamespace()
The specific Closure namespace this module represents, if any. This can be fromgoog.provide
,goog.module
, orgoog.module.declareNamespace
. Null otherwise.
-
builder
public static Module.Builder builder()
Creates a new builder.
-
toBuilder
public abstract Module.Builder toBuilder()
Returns this module in builder form.
-
-