Record Class Module

java.lang.Object
java.lang.Record
com.google.javascript.jscomp.modules.Module
Record Components:
path - Path of this module. Null if this module is a nested goog.loadModule.
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 with export {}; then an entry is created like export {} 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.
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 - Map of local identifier name to local export definition.
closureNamespace - The specific Closure namespace this module represents, if any. This can be from goog.provide, goog.module, or goog.module.declareNamespace. Null otherwise.

public record Module(ModuleMetadataMap.ModuleMetadata metadata, @Nullable ModuleLoader.ModulePath path, com.google.common.collect.ImmutableMap<String,Binding> namespace, com.google.common.collect.ImmutableMap<String,Binding> boundNames, com.google.common.collect.ImmutableMap<String,Export> localNameToLocalExport, @Nullable String closureNamespace) extends Record
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.
  • Constructor Details

  • Method Details

    • builder

      public static Module.Builder builder()
      Creates a new builder.
    • toBuilder

      public Module.Builder toBuilder()
      Returns this module in builder form.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • metadata

      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component
    • path

      public @Nullable ModuleLoader.ModulePath path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component
    • namespace

      public com.google.common.collect.ImmutableMap<String,Binding> namespace()
      Returns the value of the namespace record component.
      Returns:
      the value of the namespace record component
    • boundNames

      public com.google.common.collect.ImmutableMap<String,Binding> boundNames()
      Returns the value of the boundNames record component.
      Returns:
      the value of the boundNames record component
    • localNameToLocalExport

      public com.google.common.collect.ImmutableMap<String,Export> localNameToLocalExport()
      Returns the value of the localNameToLocalExport record component.
      Returns:
      the value of the localNameToLocalExport record component
    • closureNamespace

      public @Nullable String closureNamespace()
      Returns the value of the closureNamespace record component.
      Returns:
      the value of the closureNamespace record component