Class Compiler
- All Implemented Interfaces:
CompilerInputProvider
,ErrorHandler
,SourceExcerptProvider
,SourceFileMapping
- parses JS code
- checks for undefined variables
- performs optimizations such as constant folding and constants inlining
- renames variables (to short names)
- outputs compact JavaScript code
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An implementation of a license tracker to be used when licenses can be de-duped among Chunks (because licenses might be loaded by a chunk's transitive dependencies.static class
Stores a buffer of text to which more can be appended.protected static class
Serializable state of the compiler specific to multistage binary buildsstatic class
Subclasses are responsible for loading sources that were not provided as explicit inputs to the compiler.static class
A license tracker implementation that emits all licenses attached to script nodes, regardless of if the content of that script is used anywhere in the compilation.static final class
A license tracker implementation that only retains licenses for which there are useful nodes in a binary.Nested classes/interfaces inherited from class com.google.javascript.jscomp.AbstractCompiler
AbstractCompiler.LifeCycleStage
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.SourceExcerptProvider
SourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Logger
Logger for the whole com.google.javascript.jscomp domain - setting configuration for this logger affects all loggers in other classes within the compiler.protected final com.google.javascript.jscomp.RecentChange
-
Constructor Summary
ConstructorsConstructorDescriptionCompiler()
Creates a Compiler that reports errors and warnings to its logger.Compiler
(ErrorManager errorManager) Creates a Compiler that uses a custom error manager.Compiler
(@Nullable PrintStream outStream) Creates a Compiler that reports errors and warnings to an output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExportedNames
(Set<String> exportedNames) Adds exported names to keep track.void
addInputSourceMap
(String sourceFileName, SourceMapInput inputSourceMap) Adds aSourceMapInput
for the givensourceFileName
, to be used for error reporting and source map combining.void
compile
(SourceFile extern, SourceFile input, CompilerOptions options) Compiles a single source file and a single externs file.compile
(List<SourceFile> externs, List<SourceFile> inputs, CompilerOptions options) Compiles a list of inputs.compileChunks
(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options) Compiles a list of chunks.protected com.google.javascript.jscomp.CompilerExecutor
protected Config
createConfig
(Config.LanguageMode mode, Config.StrictMode strictMode) protected PassConfig
Create the passes object.void
Disable threads.protected Node
ensureLibraryInjected
(String resourceName, boolean force) void
forwardDeclareType
(String typeName) void
Generates a report of all warnings and errors found during compilation to stderr.Gets the DOT graph of the AST generated at the end of compilation.@Nullable String
getBase64SourceMapContents
(String sourceFileName) Returns thefrom a `//# sourceMappingURL=data:application/json;base64, ` comment. int
Gets the JS source modules in dependency order.Gets the current coding convention.Gets a central registry of colors from deserialized JS types.getComments
(String filename) protected com.google.javascript.jscomp.CompilerExecutor
protected Compiler.CompilerState
Gets the id generator for cross-module motion.com.google.common.collect.ImmutableSet
<String> The warning classes that are available from the command-line, and are suppressible by the@suppress
annotation.int
Gets the number of errors.getErrorLevel
(JSError error) Gets the error manager.com.google.common.collect.ImmutableList
<JSError> Returns the list of errors (never null).Gets the names that have been exported.com.google.common.collect.ImmutableSet
<String> Gets the names of the properties defined in externs or null if GatherExternProperties pass was not run yet.protected Node
@Nullable CompilerInput
Looks up an input (possibly an externs input) by input id.Returns an unmodifiable view of the compiler inputs indexed by id.protected Node
static @Nullable String
getLicenseForFile
(AbstractCompiler compiler, @Nullable String fileName) protected Node
getNodeForCodeInsertion
(@Nullable JSChunk chunk) Returns the result of the compilation.Get an interpreter for type analysis.getRoot()
Returns the root node of the AST, which includes both externs and source.final @Nullable Node
getScriptNode
(String filename) @Nullable CharSequence
getSourceFileContentByName
(String sourceName) @Nullable String
getSourceLine
(String sourceName, int lineNumber) Get the line indicated by the line number.@Nullable Region
getSourceLines
(String sourceName, int lineNumber, int length) Gets the specific lines returned by the beginning and excerpt length.@Nullable com.google.debugging.sourcemap.proto.Mapping.OriginalMapping
getSourceMapping
(String sourceName, int lineNumber, int columnNumber) Returns the original mapping for the file name, line number and column position found in the source map.@Nullable Region
getSourceRegion
(String sourceName, int lineNumber) Get a region around the indicated line number.@Nullable TypedScope
Gets the top scope.boolean
Gets whether any file needed to transpile any featurecom.google.javascript.jscomp.ScopeCreator
Gets the central registry of type violations.Gets a central registry of type information from the compiled JS.int
Gets the number of warnings.com.google.common.collect.ImmutableList
<JSError> Returns the list of warnings (never null).boolean
Consults theErrorManager
to see if we've encountered errors that should halt compilation.boolean
Whether the AST has been annotated with optimization colors.boolean
Returns whether the typechecking passes have runvoid
final void
init
(List<SourceFile> externs, List<SourceFile> sources, CompilerOptions options) Initializes the instance state needed for a compile job.void
Do any initialization that is dependent on the compiler options.void
initChunks
(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options) Initializes the instance state needed for a compile job if the sources are in modules.void
initChunksWithTypedAstFilesystem
(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options, InputStream typedAstListStream) Initializes a compiler with deserialized state from the given TypedAst.Listvoid
initOptions
(CompilerOptions options) Initializes the compiler options.void
initRuntimeLibraryTypedAsts
(com.google.common.base.Optional<ColorPool.Builder> colorPoolBuilder) Deserialize runtime libraries from a TypedAST packaged as a JAR resource and reconcile their Colors with the current inputs.void
initWebpackMap
(com.google.common.collect.ImmutableMap<String, String> inputPathByWebpackId) final void
initWithTypedAstFilesystem
(List<SourceFile> externs, List<SourceFile> sources, CompilerOptions options, InputStream typedAstListStream) Initializes a compiler with deserialized state from the given TypedAst.Listvoid
Instrument code for coverage.boolean
Returns `true` when type checking has run, but the type registry has been cleared.static String
joinPathParts
(String... pathParts) Creates an OS specific path string from partsvoid
protected CompilerOptions
Allow subclasses to override the default CompileOptions object.void
parse()
Parses input files without doing progress tracking that is part of a full compile.parse
(SourceFile file) void
Parses input files in preparation for compilation.parseSyntheticCode
(String fileName, String js) Parses code for injecting, and associate it with a given source file.void
Performs all the bookkeeping required at the end of a compilation.void
void
Rebuilds the internal input map by iterating over all modules.protected void
When the CompilerOptions and its WarningsGuard overlap, reconcile any discrepancies.void
report
(CheckLevel ignoredLevel, JSError error) void
Report an error or warning.void
reportAmbiguatePropertiesSummary
(Supplier<String> summarySupplier) Used by `AmbiguateProperties` to record a one-line summary of the work it accomplished, if any.void
reportChangeToChangeScope
(Node changeScopeRoot) Mark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)void
Passes that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)void
reportDisambiguatePropertiesSummary
(Supplier<String> summarySupplier) Used by `DisambiguateProperties` to record a one-line summary of the work it accomplished, if any.void
void
protected void
restoreFromState
(Compiler.CompilerState compilerState) Restore the portions of the compiler state that don't require access to the serialized AST.void
restoreState
(InputStream inputStream) <T> T
runInCompilerThread
(Callable<T> callable) The primary purpose of this method is to run the provided code with a larger than standard stack.void
saveState
(OutputStream outputStream) void
setAccessorSummary
(com.google.javascript.jscomp.AccessorSummary summary) Sets the summary of properties with getters and setters.void
setAnonymousFunctionNameMap
(VariableMap functionMap) Sets the naming map for anonymous functionsvoid
setColorRegistry
(ColorRegistry colorRegistry) Sets the color registryvoid
setCssNames
(Set<String> cssNames) Sets the css names found during compilation.void
setDefineNames
(Collection<String> defineNames) Adds @define names to keep track.void
setErrorManager
(ErrorManager errorManager) Sets the error manager.void
setIdGeneratorMap
(String serializedIdMappings) Sets the id generator for cross-module motion.void
setInstrumentationMapping
(VariableMap instrumentationMapping) Sets the mapping for instrumentation parameter encoding.static void
setLoggingLevel
(Level level) Sets the logging level for the com.google.javascript.jscomp package.void
setModuleMap
(ModuleMap moduleMap) void
setModuleMetadataMap
(ModuleMetadataMap moduleMetadataMap) void
setPassConfig
(PassConfig passes) void
setPropertyMap
(VariableMap propertyMap) Sets the property renaming mapvoid
setStringMap
(VariableMap stringMap) Sets the string replacement mapvoid
setTimeout
(int timeout) Sets the timeout when Compiler is run in a threadvoid
setTranspiledFiles
(boolean transpiledFiles) void
setVariableMap
(VariableMap variableMap) Sets the variable renaming mapvoid
Perform compiler passes for stage 1 of compilation.void
stage2Passes
(PassConfig.OptimizationPasses optimizationPasses) Perform compiler passes for stage 2 of compilation.void
Perform compiler passes for stage 3 of compilation.toSource()
Converts the main parse tree back to JS code.toSource
(CodePrinter.LicenseTracker licenseTracker, JSChunk chunk) Converts the parse tree for a chunk back to JS code, using the given License Tracker to determine which licenses should be emitted before the source code.void
toSource
(Compiler.CodeBuilder cb, CodePrinter.LicenseTracker licenseTracker, int inputSeqNum, Node root) Writes out JS code from a root node.Converts the parse tree for a chunk back to JS code.Generates JavaScript source code for an AST, doesn't generate source map info.String[]
toSourceArray
(CodePrinter.LicenseTracker licenseTracker, JSChunk chunk) Converts the parse tree for each input in a module back to JS code, using the given License Tracker implementation to decide which licenses should be emitted before each input file.void
void
Methods inherited from class com.google.javascript.jscomp.AbstractCompiler
createAstFactory, createAstFactoryWithoutTypes, createDefaultExpressionDecomposer, createExpressionDecomposer, createOrReopenIndexedLog, createOrReopenLog, getAstAnalyzer, getDebugLogFilterList, getLifeCycleStage, isDebugLoggingEnabled, isFillFileName
-
Field Details
-
tracker
-
logger
Logger for the whole com.google.javascript.jscomp domain - setting configuration for this logger affects all loggers in other classes within the compiler. -
recentChange
protected final com.google.javascript.jscomp.RecentChange recentChange
-
-
Constructor Details
-
Compiler
public Compiler()Creates a Compiler that reports errors and warnings to its logger. -
Compiler
Creates a Compiler that reports errors and warnings to an output stream. -
Compiler
Creates a Compiler that uses a custom error manager.
-
-
Method Details
-
setErrorManager
Sets the error manager.- Parameters:
errorManager
- the error manager, it cannot benull
-
initOptions
Initializes the compiler options. It's called as part of a normal compile() job. Public for the callers that are not doing a normal compile() job. -
printConfig
public void printConfig() -
reconcileOptionsWithGuards
protected void reconcileOptionsWithGuards()When the CompilerOptions and its WarningsGuard overlap, reconcile any discrepancies. -
initWithTypedAstFilesystem
public final void initWithTypedAstFilesystem(List<SourceFile> externs, List<SourceFile> sources, CompilerOptions options, InputStream typedAstListStream) Initializes a compiler with deserialized state from the given TypedAst.ListThis method initializes all the state needed to run `.stage2Passes()` or do any similar sort of optimization work.
- Parameters:
typedAstListStream
- a gzipped, binary-serialized TypedAst.List proto
-
initChunksWithTypedAstFilesystem
public void initChunksWithTypedAstFilesystem(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options, InputStream typedAstListStream) Initializes a compiler with deserialized state from the given TypedAst.ListThis method initializes all the state needed to run `.stage2Passes()` or do any similar sort of optimization work.
- Parameters:
typedAstListStream
- a gzipped, binary-serialized TypedAst.List proto
-
initRuntimeLibraryTypedAsts
public void initRuntimeLibraryTypedAsts(com.google.common.base.Optional<ColorPool.Builder> colorPoolBuilder) Description copied from class:AbstractCompiler
Deserialize runtime libraries from a TypedAST packaged as a JAR resource and reconcile their Colors with the current inputs.This method must be called anywhere that Colors are reconciled for application to the AST. Otherwise Color information won't be consistent. `colorPoolBuilder` must be the same builder as used for the other inputs, and the caller retains ownership.
- Overrides:
initRuntimeLibraryTypedAsts
in classAbstractCompiler
- Parameters:
colorPoolBuilder
- if present, includes inferred optimization colors on the deserialized ASTs. If absent, does not include colors.
-
init
Initializes the instance state needed for a compile job. -
initChunks
Initializes the instance state needed for a compile job if the sources are in modules. -
initBasedOnOptions
public void initBasedOnOptions()Do any initialization that is dependent on the compiler options. -
joinPathParts
Creates an OS specific path string from parts -
rebuildInputsFromModules
public void rebuildInputsFromModules()Rebuilds the internal input map by iterating over all modules. This is necessary if inputs have been added to or removed from a module after aninit(java.util.List<com.google.javascript.jscomp.SourceFile>, java.util.List<com.google.javascript.jscomp.SourceFile>, com.google.javascript.jscomp.CompilerOptions)
orinitChunks(java.util.List<com.google.javascript.jscomp.SourceFile>, java.util.List<com.google.javascript.jscomp.JSChunk>, com.google.javascript.jscomp.CompilerOptions)
call. -
compile
Compiles a single source file and a single externs file. -
compile
Compiles a list of inputs.This is a convenience method to wrap up all the work of compilation, including generating the error and warning report.
NOTE: All methods called here must be public, because client code must be able to replicate and customize this.
-
generateReport
public void generateReport()Generates a report of all warnings and errors found during compilation to stderr.Client code must call this method explicitly if it doesn't use one of the convenience methods that do so automatically.
Always call this method, even if the compiler throws an exception. The report will include information about the exception.
-
compileChunks
public Result compileChunks(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options) Compiles a list of chunks.This is a convenience method to wrap up all the work of compilation, including generating the error and warning report.
NOTE: All methods called here must be public, because client code must be able to replicate and customize this.
-
stage1Passes
public void stage1Passes()Perform compiler passes for stage 1 of compilation.Stage 1 consists primarily of error and type checking passes.
parseForCompilation()
must be called before this method is called.The caller is responsible for also calling
generateReport()
to generate a report of warnings and errors to stderr. See the invocation incompile(com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.CompilerOptions)
for a good example. -
stage2Passes
Perform compiler passes for stage 2 of compilation.Stage 2 consists primarily of transpilation and optimization passes.
stage1Passes()
must be called before this method is called.The caller is responsible for also calling
generateReport()
to generate a report of warnings and errors to stderr. See the invocation incompile(com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.CompilerOptions)
for a good example. -
stage3Passes
public void stage3Passes()Perform compiler passes for stage 3 of compilation.Stage 3 consists primarily of localization passes.
stage2Passes()
must be called before this method is called.The caller is responsible for also calling
generateReport()
to generate a report of warnings and errors to stderr. See the invocation incompile(com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.CompilerOptions)
for a good example. -
disableThreads
public void disableThreads()Disable threads. This is for clients that run on AppEngine and don't have threads. -
setTimeout
public void setTimeout(int timeout) Sets the timeout when Compiler is run in a thread- Parameters:
timeout
- seconds to wait before timeout
-
runInCompilerThread
The primary purpose of this method is to run the provided code with a larger than standard stack. -
performPostCompilationTasks
public void performPostCompilationTasks()Performs all the bookkeeping required at the end of a compilation.This method must be called if the compilation makes it as far as doing checks.
DON'T call it if the compiler threw an exception.
DO call it even when
hasErrors()
returns true. -
instrumentForCoverage
public void instrumentForCoverage()Instrument code for coverage.parseForCompilation()
must be called before this method is called.The caller is responsible for also calling
generateReport()
to generate a report of warnings and errors to stderr. See the invocation incompile(com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.SourceFile, com.google.javascript.jscomp.CompilerOptions)
for a good example.This method is mutually exclusive with stage1Passes() and stage2Passes(). Either call those two methods or this one, but not both.
-
parseForCompilation
public void parseForCompilation()Parses input files in preparation for compilation.Either
init()
orinitChunks()
must be called first to set up the input files to be read.TODO(bradfordcsmith): Rename this to parse()
-
parse
public void parse()Parses input files without doing progress tracking that is part of a full compile.Either
init()
orinitChunks()
must be called first to set up the input files to be read.TODO(bradfordcsmith): Rename this to parseIndependentOfCompilation() or similar.
-
parse
-
createPassConfigInternal
Create the passes object. Clients should use setPassConfig instead of overriding this. -
setPassConfig
- Parameters:
passes
- The PassConfig to use with this Compiler.- Throws:
NullPointerException
- if passes is nullIllegalStateException
- if this.passes has already been assigned
-
whitespaceOnlyPasses
public void whitespaceOnlyPasses() -
transpileAndDontCheck
public void transpileAndDontCheck() -
getScriptNode
- Specified by:
getScriptNode
in classAbstractCompiler
-
getResult
Returns the result of the compilation. -
getErrors
Returns the list of errors (never null). -
getWarnings
Returns the list of warnings (never null). -
getRoot
Description copied from class:AbstractCompiler
Returns the root node of the AST, which includes both externs and source.- Specified by:
getRoot
in classAbstractCompiler
-
getAllowableFeatures
-
getInput
Description copied from class:AbstractCompiler
Looks up an input (possibly an externs input) by input id. May return null.- Specified by:
getInput
in interfaceCompilerInputProvider
- Specified by:
getInput
in classAbstractCompiler
-
getChunks
Gets the JS source modules in dependency order.Returns null if
#init
or#initChunks
hasn't been called yet. Otherwise, the result is always non-empty, even in the degenerate case where there's only one module. -
clearJSTypeRegistry
public void clearJSTypeRegistry()- Specified by:
clearJSTypeRegistry
in classAbstractCompiler
-
isTypeRegistryCleared
public boolean isTypeRegistryCleared()Description copied from class:AbstractCompiler
Returns `true` when type checking has run, but the type registry has been cleared.See also `clearJSTypeRegistry()`.
- Specified by:
isTypeRegistryCleared
in classAbstractCompiler
-
getTypeRegistry
Description copied from class:AbstractCompiler
Gets a central registry of type information from the compiled JS.- Specified by:
getTypeRegistry
in classAbstractCompiler
-
getColorRegistry
Description copied from class:AbstractCompiler
Gets a central registry of colors from deserialized JS types.- Specified by:
getColorRegistry
in classAbstractCompiler
-
setColorRegistry
Description copied from class:AbstractCompiler
Sets the color registry- Specified by:
setColorRegistry
in classAbstractCompiler
-
forwardDeclareType
-
hasTypeCheckingRun
public boolean hasTypeCheckingRun()Description copied from class:AbstractCompiler
Returns whether the typechecking passes have run- Specified by:
hasTypeCheckingRun
in classAbstractCompiler
-
hasOptimizationColors
public boolean hasOptimizationColors()Description copied from class:AbstractCompiler
Whether the AST has been annotated with optimization colors.- Specified by:
hasOptimizationColors
in classAbstractCompiler
-
getTypedScopeCreator
public com.google.javascript.jscomp.ScopeCreator getTypedScopeCreator() -
buildKnownSymbolTable
-
getTopScope
Description copied from class:AbstractCompiler
Gets the top scope.- Specified by:
getTopScope
in classAbstractCompiler
-
getReverseAbstractInterpreter
Description copied from class:AbstractCompiler
Get an interpreter for type analysis.- Specified by:
getReverseAbstractInterpreter
in classAbstractCompiler
-
getTypeMismatches
Description copied from class:AbstractCompiler
Gets the central registry of type violations.- Specified by:
getTypeMismatches
in classAbstractCompiler
-
maybeSetTracker
public void maybeSetTracker() -
newCompilerOptions
Allow subclasses to override the default CompileOptions object. -
parseSyntheticCode
Description copied from class:AbstractCompiler
Parses code for injecting, and associate it with a given source file.- Specified by:
parseSyntheticCode
in classAbstractCompiler
-
toSource
Converts the main parse tree back to JS code.- Specified by:
toSource
in classAbstractCompiler
-
toSource
Converts the parse tree for a chunk back to JS code.Consider using toSource(JSChunk, LicenseTracker) for better license handling. This call will emit all license text attached to all direct inputs to the chunk, which can be very inefficient.
-
toSource
Converts the parse tree for a chunk back to JS code, using the given License Tracker to determine which licenses should be emitted before the source code.- Parameters:
licenseTracker
- The license tracker implementation to use.Compiler.ChunkGraphAwareLicenseTracker
is a suitable implementation when this method is being called on each chunk in the chunk graph in dependency order.
-
toSource
public void toSource(Compiler.CodeBuilder cb, CodePrinter.LicenseTracker licenseTracker, int inputSeqNum, Node root) Writes out JS code from a root node. If printing input delimiters, this method will attach a comment to the start of the text indicating which input the output derived from. If there were any preserve annotations within the root's source, they will also be printed in a block comment at the beginning of the output.The LicenseTracker provided determines which licenses attached to the nodes visited should be included in the output. When building a single JS bundle, consider using the
Compiler.SingleBinaryLicenseTracker
implementation. -
toSource
Generates JavaScript source code for an AST, doesn't generate source map info.- Specified by:
toSource
in classAbstractCompiler
-
getLicenseForFile
public static @Nullable String getLicenseForFile(AbstractCompiler compiler, @Nullable String fileName) -
toSourceArray
Converts the parse tree for each input in a module back to JS code, using the given License Tracker implementation to decide which licenses should be emitted before each input file.- Parameters:
licenseTracker
- The license tracker implementation to use.Compiler.ChunkGraphAwareLicenseTracker
is a suitable implementation when this method is being called on each module in the chunk graph in dependency order - see its javadoc on how to use it correctly.module
- the chunk being converted to source.
-
getExternsRoot
-
getJsRoot
-
getChangeStamp
public int getChangeStamp() -
incrementChangeStamp
public void incrementChangeStamp() -
reportChangeToChangeScope
Description copied from class:AbstractCompiler
Mark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)- Specified by:
reportChangeToChangeScope
in classAbstractCompiler
-
reportFunctionDeleted
-
reportDisambiguatePropertiesSummary
Description copied from class:AbstractCompiler
Used by `DisambiguateProperties` to record a one-line summary of the work it accomplished, if any.This information will be included in the tracer mode output, if that is enabled.
- Specified by:
reportDisambiguatePropertiesSummary
in classAbstractCompiler
-
reportAmbiguatePropertiesSummary
Description copied from class:AbstractCompiler
Used by `AmbiguateProperties` to record a one-line summary of the work it accomplished, if any.This information will be included in the tracer mode output, if that is enabled.
- Specified by:
reportAmbiguatePropertiesSummary
in classAbstractCompiler
-
reportChangeToEnclosingScope
Description copied from class:AbstractCompiler
Passes that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)- Specified by:
reportChangeToEnclosingScope
in classAbstractCompiler
-
getCodingConvention
Description copied from class:AbstractCompiler
Gets the current coding convention.- Specified by:
getCodingConvention
in classAbstractCompiler
-
createConfig
-
getDiagnosticGroups
The warning classes that are available from the command-line, and are suppressible by the@suppress
annotation. -
report
Description copied from class:AbstractCompiler
Report an error or warning.- Specified by:
report
in classAbstractCompiler
-
report
- Specified by:
report
in interfaceErrorHandler
- Parameters:
ignoredLevel
- the reporting levelerror
- the error to report
-
getErrorLevel
-
getErrorCount
public int getErrorCount()Gets the number of errors. -
getWarningCount
public int getWarningCount()Gets the number of warnings. -
hasErrors
public boolean hasErrors()Consults theErrorManager
to see if we've encountered errors that should halt compilation.If
CompilerOptions.canContinueAfterErrors()
istrue
, this function always returnsfalse
without consulting the error manager. The error manager will continue to be told about new errors and warnings, but the compiler will complete compilation of all inputs. -
getSourceFileContentByName
-
addInputSourceMap
Description copied from class:AbstractCompiler
Adds aSourceMapInput
for the givensourceFileName
, to be used for error reporting and source map combining.- Specified by:
addInputSourceMap
in classAbstractCompiler
-
getBase64SourceMapContents
Returns thefrom a `//# sourceMappingURL=data:application/json;base64, ` comment. This sourceMappingURL comment is a JS file's inline source map, embedded into the input JS file with a base64-encoded "data url" stored in `//# sourceMappingURL=` comment. - Specified by:
getBase64SourceMapContents
in classAbstractCompiler
-
getSourceMapping
public @Nullable com.google.debugging.sourcemap.proto.Mapping.OriginalMapping getSourceMapping(String sourceName, int lineNumber, int columnNumber) Description copied from interface:SourceFileMapping
Returns the original mapping for the file name, line number and column position found in the source map. Returnsnull
if none is found.- Specified by:
getSourceMapping
in interfaceSourceExcerptProvider
- Specified by:
getSourceMapping
in interfaceSourceFileMapping
- Parameters:
lineNumber
- The line number, 1-based.columnNumber
- The column index, 1-based.
-
getSourceLine
Description copied from interface:SourceExcerptProvider
Get the line indicated by the line number. This call will return only the specific line.- Specified by:
getSourceLine
in interfaceSourceExcerptProvider
- Parameters:
lineNumber
- the line number, 1 being the first line of the file- Returns:
- the line indicated, or
null
if it does not exist
-
getSourceLines
Description copied from interface:SourceExcerptProvider
Gets the specific lines returned by the beginning and excerpt length. Must not start or end with a carriage return. Implementations may decide to truncate lines but will always include the first line and never be longer than the specified length.- Specified by:
getSourceLines
in interfaceSourceExcerptProvider
- Parameters:
lineNumber
- the line number, 1 being the first line of the filelength
- the desired length of the excerpt (in chars). If -1, returns just a single line. Otherwise, returns as many lines as needed. (including the remainder of the last line)- Returns:
- the region around the line number indicated, or
null
if it does not exist
-
getSourceRegion
Description copied from interface:SourceExcerptProvider
Get a region around the indicated line number. The exact definition of a region is implementation specific, but it must contain the line indicated by the line number. A region must not start or end by a carriage return.- Specified by:
getSourceRegion
in interfaceSourceExcerptProvider
- Parameters:
lineNumber
- the line number, 1 being the first line of the file- Returns:
- the region around the line number indicated, or
null
if it does not exist
-
getNodeForCodeInsertion
-
getSourceMap
-
setVariableMap
Description copied from class:AbstractCompiler
Sets the variable renaming map- Specified by:
setVariableMap
in classAbstractCompiler
-
setPropertyMap
Description copied from class:AbstractCompiler
Sets the property renaming map- Specified by:
setPropertyMap
in classAbstractCompiler
-
setStringMap
Description copied from class:AbstractCompiler
Sets the string replacement map- Specified by:
setStringMap
in classAbstractCompiler
-
setCssNames
Description copied from class:AbstractCompiler
Sets the css names found during compilation.- Specified by:
setCssNames
in classAbstractCompiler
-
setIdGeneratorMap
Description copied from class:AbstractCompiler
Sets the id generator for cross-module motion.- Specified by:
setIdGeneratorMap
in classAbstractCompiler
-
getTranspiledFiles
public boolean getTranspiledFiles()Description copied from class:AbstractCompiler
Gets whether any file needed to transpile any feature- Specified by:
getTranspiledFiles
in classAbstractCompiler
-
setTranspiledFiles
public void setTranspiledFiles(boolean transpiledFiles) -
getCrossModuleIdGenerator
Description copied from class:AbstractCompiler
Gets the id generator for cross-module motion.- Specified by:
getCrossModuleIdGenerator
in classAbstractCompiler
-
setAnonymousFunctionNameMap
Description copied from class:AbstractCompiler
Sets the naming map for anonymous functions- Specified by:
setAnonymousFunctionNameMap
in classAbstractCompiler
-
setInstrumentationMapping
Description copied from class:AbstractCompiler
Sets the mapping for instrumentation parameter encoding.- Specified by:
setInstrumentationMapping
in classAbstractCompiler
-
getInstrumentationMapping
-
addExportedNames
Description copied from class:AbstractCompiler
Adds exported names to keep track.- Specified by:
addExportedNames
in classAbstractCompiler
-
getExportedNames
Description copied from class:AbstractCompiler
Gets the names that have been exported.- Specified by:
getExportedNames
in classAbstractCompiler
-
setDefineNames
Description copied from class:AbstractCompiler
Adds @define names to keep track.- Specified by:
setDefineNames
in classAbstractCompiler
-
getDefineNames
- Specified by:
getDefineNames
in classAbstractCompiler
-
getOptions
-
setLoggingLevel
Sets the logging level for the com.google.javascript.jscomp package. -
getAstDotGraph
Gets the DOT graph of the AST generated at the end of compilation.- Throws:
IOException
-
getErrorManager
Description copied from class:AbstractCompiler
Gets the error manager.- Specified by:
getErrorManager
in classAbstractCompiler
-
getInputsById
Returns an unmodifiable view of the compiler inputs indexed by id. -
getExternProperties
Description copied from class:AbstractCompiler
Gets the names of the properties defined in externs or null if GatherExternProperties pass was not run yet.- Specified by:
getExternProperties
in classAbstractCompiler
-
setAccessorSummary
public void setAccessorSummary(com.google.javascript.jscomp.AccessorSummary summary) Description copied from class:AbstractCompiler
Sets the summary of properties with getters and setters.- Specified by:
setAccessorSummary
in classAbstractCompiler
-
ensureLibraryInjected
-
getComments
-
getModuleLoader
-
initWebpackMap
-
createCompilerExecutor
protected com.google.javascript.jscomp.CompilerExecutor createCompilerExecutor() -
getCompilerExecutor
protected com.google.javascript.jscomp.CompilerExecutor getCompilerExecutor() -
restoreFromState
Restore the portions of the compiler state that don't require access to the serialized AST. -
saveState
- Throws:
IOException
-
getCompilerState
-
restoreState
- Throws:
IOException
ClassNotFoundException
-
getModuleMetadataMap
- Specified by:
getModuleMetadataMap
in classAbstractCompiler
-
setModuleMetadataMap
- Specified by:
setModuleMetadataMap
in classAbstractCompiler
-
getModuleMap
- Specified by:
getModuleMap
in classAbstractCompiler
-
setModuleMap
- Specified by:
setModuleMap
in classAbstractCompiler
-
resetAndIntitializeSourceMap
public void resetAndIntitializeSourceMap()
-