Class RuntimeJsLibManager

java.lang.Object
com.google.javascript.jscomp.js.RuntimeJsLibManager

public final class RuntimeJsLibManager extends Object
Injects runtime libraries from the jscomp/js directory into an AST

Supports injecting libraries either based on the library path name, or by the specific `$jscomp.*` field/class name.

  • Field Details

  • Method Details

    • create

      public static RuntimeJsLibManager create(RuntimeJsLibManager.RuntimeLibraryMode mode, RuntimeJsLibManager.ResourceProvider resourceProvider, ChangeTracker changeTracker, Supplier<Node> nodeForCodeInsertion)
    • recordLibraryInjected

      public void recordLibraryInjected(String resourceName)
      Records that the given library has already been injected into the compilation.

      This doesn't actually modify the AST - it can be used if e.g. restoring compilation state after serialization/deserialization.

      Parameters:
      resourceName - The name of the library. For example, if "base" is is specified, then we record js/base.js
    • hasInjectedLibrary

      public boolean hasInjectedLibrary(String resourceName)
      Returns true if the given library has already been injected into the compilation.
    • getInjectedLibraries

      public com.google.common.collect.ImmutableList<String> getInjectedLibraries()
      Returns a list of all library paths previously injected, via one of the other methods on this class.
    • getJsLibField

      public RuntimeJsLibManager.JsLibField getJsLibField(String fieldName)
      Returns a field definition for the given name, without actually asserting or requiring its definition to be injected.
    • injectLibForField

      public void injectLibForField(String fieldName)
      Injects the runtime library that defines the given $jscomp.* field.
    • ensureLibraryInjected

      @CanIgnoreReturnValue public @Nullable Node ensureLibraryInjected(String resourceName, boolean force)
      The subdir js/ contains libraries of code that we inject at compile-time only if requested by this function.

      Notice that these libraries will almost always create global symbols.

      Parameters:
      resourceName - The name of the library. For example, if "base" is is specified, then we load js/base.js
      force - Inject the library even if compiler options say not to.
      Returns:
      The last node of the most-recently-injected runtime library. If new code was injected, this will be the last expression node of the library. If the caller needs to add additional code, they should add it as the next sibling of this node. If no runtime libraries have been injected, then null is returned.
    • setLastInjectedLibrary

      public void setLastInjectedLibrary(@Nullable Node lastInjectedLibrary)
    • getLastInjectedLibrary

      public @Nullable Node getLastInjectedLibrary()