Package com.google.javascript.jscomp.js
Class RuntimeJsLibManager
java.lang.Object
com.google.javascript.jscomp.js.RuntimeJsLibManager
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceARuntimeJsLibManager.InjectedJsLibFieldthat was injected inRuntimeJsLibManager.RuntimeLibraryMode.EXTERN_FIELD_NAMESmode, and so has both a regular "qualified name" by which transpilation passes should refer to it - this is the externed name - but also provides the uncompiled, raw name of the field.static interfaceARuntimeJsLibManager.JsLibFieldthat is statically guaranteed to be available at runtime, i.e.static interfaceA $jscomp.* field (could be a method, class, or any arbitrary value) that exists in some runtime library under the js/ directory.static interfaceLoads /js resources into AST formatstatic enumWhat to do with the runtime libraries under the js/ directory: the compiler can ignore them completely; can validate any attempted library usage is correct but not modify the AST; or both validate invalid input: '&' add to the AST. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeJsLibManagercreate(RuntimeJsLibManager.RuntimeLibraryMode mode, RuntimeJsLibManager.ResourceProvider resourceProvider, ChangeTracker changeTracker, Supplier<Node> nodeForCodeInsertion) @Nullable NodeensureLibraryInjected(String resourceName, boolean force) The subdir js/ contains libraries of code that we inject at compile-time only if requested by this function.com.google.common.collect.ImmutableList<RuntimeJsLibManager.ExternedField> Returns a list of all fields previously injected, via one of the other methods on this class.com.google.common.collect.ImmutableList<String> Returns a list of all library paths previously injected, via one of the other methods on this class.getJsLibField(String fieldName) Returns a field definition for the given name, without actually asserting or requiring its definition to be injected.@Nullable NodebooleanhasInjectedLibrary(String resourceName) Returns true if the given library has already been injected into the compilation.voidinjectLibForField(String fieldName) Injects the runtime library that defines the given $jscomp.* field.voidrecordLibraryInjected(String resourceName) Records that the given library has already been injected into the compilation.voidsetLastInjectedLibrary(@Nullable Node lastInjectedLibrary)
-
Field Details
-
RUNTIME_LIB_DIR
- See Also:
-
-
Method Details
-
create
public static RuntimeJsLibManager create(RuntimeJsLibManager.RuntimeLibraryMode mode, RuntimeJsLibManager.ResourceProvider resourceProvider, ChangeTracker changeTracker, Supplier<Node> nodeForCodeInsertion) -
recordLibraryInjected
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
Returns true if the given library has already been injected into the compilation. -
getInjectedLibraries
Returns a list of all library paths previously injected, via one of the other methods on this class. -
getExternedFields
public com.google.common.collect.ImmutableList<RuntimeJsLibManager.ExternedField> getExternedFields()Returns a list of all fields previously injected, via one of the other methods on this class. -
getJsLibField
Returns a field definition for the given name, without actually asserting or requiring its definition to be injected. -
injectLibForField
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.jsforce- 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
-
getLastInjectedLibrary
-