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 classAn 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 classStores a buffer of text to which more can be appended.protected static classSerializable state of the compiler specific to multistage binary buildsstatic classSubclasses are responsible for loading sources that were not provided as explicit inputs to the compiler.static classA 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 classA 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.LifeCycleStageNested classes/interfaces inherited from interface com.google.javascript.jscomp.SourceExcerptProvider
SourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LoggerLogger 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 TypeMethodDescriptionvoidaddExportedNames(Set<String> exportedNames) Adds exported names to keep track.voidaddInputSourceMap(String sourceFileName, SourceMapInput inputSourceMap) Adds aSourceMapInputfor the givensourceFileName, to be used for error reporting and source map combining.voidcompile(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.CompilerExecutorprotected ConfigcreateConfig(Config.LanguageMode mode, Config.StrictMode strictMode) protected PassConfigCreate the passes object.voidDisable threads.protected NodeensureLibraryInjected(String resourceName, boolean force) voidforwardDeclareType(String typeName) voidGenerates 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 StringgetBase64SourceMapContents(String sourceFileName) Returns thefrom a `//# sourceMappingURL=data:application/json;base64, ` comment. intGets 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.CompilerExecutorprotected Compiler.CompilerStateGets 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@suppressannotation.intGets 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 CompilerInputLooks up an input (possibly an externs input) by input id.Returns an unmodifiable view of the compiler inputs indexed by id.protected Nodestatic @Nullable StringgetLicenseForFile(AbstractCompiler compiler, @Nullable String fileName) protected NodegetNodeForCodeInsertion(@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 NodegetScriptNode(String filename) @Nullable CharSequencegetSourceFileContentByName(String sourceName) @Nullable StringgetSourceLine(String sourceName, int lineNumber) Get the line indicated by the line number.@Nullable RegiongetSourceLines(String sourceName, int lineNumber, int length) Gets the specific lines returned by the beginning and excerpt length.@Nullable com.google.debugging.sourcemap.proto.Mapping.OriginalMappinggetSourceMapping(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 RegiongetSourceRegion(String sourceName, int lineNumber) Get a region around the indicated line number.@Nullable TypedScopeGets the top scope.booleanGets whether any file needed to transpile any featurecom.google.javascript.jscomp.ScopeCreatorGets the central registry of type violations.Gets a central registry of type information from the compiled JS.intGets the number of warnings.com.google.common.collect.ImmutableList<JSError> Returns the list of warnings (never null).booleanConsults theErrorManagerto see if we've encountered errors that should halt compilation.booleanWhether the AST has been annotated with optimization colors.booleanReturns whether the typechecking passes have runvoidfinal voidinit(List<SourceFile> externs, List<SourceFile> sources, CompilerOptions options) Initializes the instance state needed for a compile job.voidDo any initialization that is dependent on the compiler options.voidinitChunks(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options) Initializes the instance state needed for a compile job if the sources are in modules.voidinitChunksWithTypedAstFilesystem(List<SourceFile> externs, List<JSChunk> chunks, CompilerOptions options, InputStream typedAstListStream) Initializes a compiler with deserialized state from the given TypedAst.ListvoidinitOptions(CompilerOptions options) Initializes the compiler options.voidinitRuntimeLibraryTypedAsts(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.voidinitWebpackMap(com.google.common.collect.ImmutableMap<String, String> inputPathByWebpackId) final voidinitWithTypedAstFilesystem(List<SourceFile> externs, List<SourceFile> sources, CompilerOptions options, InputStream typedAstListStream) Initializes a compiler with deserialized state from the given TypedAst.ListvoidInstrument code for coverage.booleanReturns `true` when type checking has run, but the type registry has been cleared.static StringjoinPathParts(String... pathParts) Creates an OS specific path string from partsvoidprotected CompilerOptionsAllow subclasses to override the default CompileOptions object.voidparse()Parses input files without doing progress tracking that is part of a full compile.parse(SourceFile file) voidParses input files in preparation for compilation.parseSyntheticCode(String fileName, String js) Parses code for injecting, and associate it with a given source file.voidPerforms all the bookkeeping required at the end of a compilation.voidvoidRebuilds the internal input map by iterating over all modules.protected voidWhen the CompilerOptions and its WarningsGuard overlap, reconcile any discrepancies.voidreport(CheckLevel ignoredLevel, JSError error) voidReport an error or warning.voidreportAmbiguatePropertiesSummary(Supplier<String> summarySupplier) Used by `AmbiguateProperties` to record a one-line summary of the work it accomplished, if any.voidreportChangeToChangeScope(Node changeScopeRoot) Mark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)voidPasses that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)voidreportDisambiguatePropertiesSummary(Supplier<String> summarySupplier) Used by `DisambiguateProperties` to record a one-line summary of the work it accomplished, if any.voidvoidprotected voidrestoreFromState(Compiler.CompilerState compilerState) Restore the portions of the compiler state that don't require access to the serialized AST.voidrestoreState(InputStream inputStream) <T> TrunInCompilerThread(Callable<T> callable) The primary purpose of this method is to run the provided code with a larger than standard stack.voidsaveState(OutputStream outputStream) voidsetAccessorSummary(com.google.javascript.jscomp.AccessorSummary summary) Sets the summary of properties with getters and setters.voidsetAnonymousFunctionNameMap(VariableMap functionMap) Sets the naming map for anonymous functionsvoidsetColorRegistry(ColorRegistry colorRegistry) Sets the color registryvoidsetCssNames(Set<String> cssNames) Sets the css names found during compilation.voidsetDefineNames(Collection<String> defineNames) Adds @define names to keep track.voidsetErrorManager(ErrorManager errorManager) Sets the error manager.voidsetIdGeneratorMap(String serializedIdMappings) Sets the id generator for cross-module motion.voidsetInstrumentationMapping(VariableMap instrumentationMapping) Sets the mapping for instrumentation parameter encoding.static voidsetLoggingLevel(Level level) Sets the logging level for the com.google.javascript.jscomp package.voidsetModuleMap(ModuleMap moduleMap) voidsetModuleMetadataMap(ModuleMetadataMap moduleMetadataMap) voidsetPassConfig(PassConfig passes) voidsetPropertyMap(VariableMap propertyMap) Sets the property renaming mapvoidsetStringMap(VariableMap stringMap) Sets the string replacement mapvoidsetTimeout(int timeout) Sets the timeout when Compiler is run in a threadvoidsetTranspiledFiles(boolean transpiledFiles) voidsetVariableMap(VariableMap variableMap) Sets the variable renaming mapvoidPerform compiler passes for stage 1 of compilation.voidstage2Passes(PassConfig.OptimizationPasses optimizationPasses) Perform compiler passes for stage 2 of compilation.voidPerform 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.voidtoSource(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.voidvoidMethods 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:AbstractCompilerDeserialize 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:
initRuntimeLibraryTypedAstsin 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:
getScriptNodein 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:AbstractCompilerReturns the root node of the AST, which includes both externs and source.- Specified by:
getRootin classAbstractCompiler
-
getAllowableFeatures
-
getInput
Description copied from class:AbstractCompilerLooks up an input (possibly an externs input) by input id. May return null.- Specified by:
getInputin interfaceCompilerInputProvider- Specified by:
getInputin classAbstractCompiler
-
getChunks
Gets the JS source modules in dependency order.Returns null if
#initor#initChunkshasn'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:
clearJSTypeRegistryin classAbstractCompiler
-
isTypeRegistryCleared
public boolean isTypeRegistryCleared()Description copied from class:AbstractCompilerReturns `true` when type checking has run, but the type registry has been cleared.See also `clearJSTypeRegistry()`.
- Specified by:
isTypeRegistryClearedin classAbstractCompiler
-
getTypeRegistry
Description copied from class:AbstractCompilerGets a central registry of type information from the compiled JS.- Specified by:
getTypeRegistryin classAbstractCompiler
-
getColorRegistry
Description copied from class:AbstractCompilerGets a central registry of colors from deserialized JS types.- Specified by:
getColorRegistryin classAbstractCompiler
-
setColorRegistry
Description copied from class:AbstractCompilerSets the color registry- Specified by:
setColorRegistryin classAbstractCompiler
-
forwardDeclareType
-
hasTypeCheckingRun
public boolean hasTypeCheckingRun()Description copied from class:AbstractCompilerReturns whether the typechecking passes have run- Specified by:
hasTypeCheckingRunin classAbstractCompiler
-
hasOptimizationColors
public boolean hasOptimizationColors()Description copied from class:AbstractCompilerWhether the AST has been annotated with optimization colors.- Specified by:
hasOptimizationColorsin classAbstractCompiler
-
getTypedScopeCreator
public com.google.javascript.jscomp.ScopeCreator getTypedScopeCreator() -
buildKnownSymbolTable
-
getTopScope
Description copied from class:AbstractCompilerGets the top scope.- Specified by:
getTopScopein classAbstractCompiler
-
getReverseAbstractInterpreter
Description copied from class:AbstractCompilerGet an interpreter for type analysis.- Specified by:
getReverseAbstractInterpreterin classAbstractCompiler
-
getTypeMismatches
Description copied from class:AbstractCompilerGets the central registry of type violations.- Specified by:
getTypeMismatchesin classAbstractCompiler
-
maybeSetTracker
public void maybeSetTracker() -
newCompilerOptions
Allow subclasses to override the default CompileOptions object. -
parseSyntheticCode
Description copied from class:AbstractCompilerParses code for injecting, and associate it with a given source file.- Specified by:
parseSyntheticCodein classAbstractCompiler
-
toSource
Converts the main parse tree back to JS code.- Specified by:
toSourcein 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.ChunkGraphAwareLicenseTrackeris 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.SingleBinaryLicenseTrackerimplementation. -
toSource
Generates JavaScript source code for an AST, doesn't generate source map info.- Specified by:
toSourcein 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.ChunkGraphAwareLicenseTrackeris 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:AbstractCompilerMark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)- Specified by:
reportChangeToChangeScopein classAbstractCompiler
-
reportFunctionDeleted
-
reportDisambiguatePropertiesSummary
Description copied from class:AbstractCompilerUsed 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:
reportDisambiguatePropertiesSummaryin classAbstractCompiler
-
reportAmbiguatePropertiesSummary
Description copied from class:AbstractCompilerUsed 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:
reportAmbiguatePropertiesSummaryin classAbstractCompiler
-
reportChangeToEnclosingScope
Description copied from class:AbstractCompilerPasses that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)- Specified by:
reportChangeToEnclosingScopein classAbstractCompiler
-
getCodingConvention
Description copied from class:AbstractCompilerGets the current coding convention.- Specified by:
getCodingConventionin classAbstractCompiler
-
createConfig
-
getDiagnosticGroups
The warning classes that are available from the command-line, and are suppressible by the@suppressannotation. -
report
Description copied from class:AbstractCompilerReport an error or warning.- Specified by:
reportin classAbstractCompiler
-
report
- Specified by:
reportin 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 theErrorManagerto see if we've encountered errors that should halt compilation.If
CompilerOptions.canContinueAfterErrors()istrue, this function always returnsfalsewithout 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:AbstractCompilerAdds aSourceMapInputfor the givensourceFileName, to be used for error reporting and source map combining.- Specified by:
addInputSourceMapin 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:
getBase64SourceMapContentsin classAbstractCompiler
-
getSourceMapping
public @Nullable com.google.debugging.sourcemap.proto.Mapping.OriginalMapping getSourceMapping(String sourceName, int lineNumber, int columnNumber) Description copied from interface:SourceFileMappingReturns the original mapping for the file name, line number and column position found in the source map. Returnsnullif none is found.- Specified by:
getSourceMappingin interfaceSourceExcerptProvider- Specified by:
getSourceMappingin interfaceSourceFileMapping- Parameters:
lineNumber- The line number, 1-based.columnNumber- The column index, 1-based.
-
getSourceLine
Description copied from interface:SourceExcerptProviderGet the line indicated by the line number. This call will return only the specific line.- Specified by:
getSourceLinein interfaceSourceExcerptProvider- Parameters:
lineNumber- the line number, 1 being the first line of the file- Returns:
- the line indicated, or
nullif it does not exist
-
getSourceLines
Description copied from interface:SourceExcerptProviderGets 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:
getSourceLinesin 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
nullif it does not exist
-
getSourceRegion
Description copied from interface:SourceExcerptProviderGet 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:
getSourceRegionin interfaceSourceExcerptProvider- Parameters:
lineNumber- the line number, 1 being the first line of the file- Returns:
- the region around the line number indicated, or
nullif it does not exist
-
getNodeForCodeInsertion
-
getSourceMap
-
setVariableMap
Description copied from class:AbstractCompilerSets the variable renaming map- Specified by:
setVariableMapin classAbstractCompiler
-
setPropertyMap
Description copied from class:AbstractCompilerSets the property renaming map- Specified by:
setPropertyMapin classAbstractCompiler
-
setStringMap
Description copied from class:AbstractCompilerSets the string replacement map- Specified by:
setStringMapin classAbstractCompiler
-
setCssNames
Description copied from class:AbstractCompilerSets the css names found during compilation.- Specified by:
setCssNamesin classAbstractCompiler
-
setIdGeneratorMap
Description copied from class:AbstractCompilerSets the id generator for cross-module motion.- Specified by:
setIdGeneratorMapin classAbstractCompiler
-
getTranspiledFiles
public boolean getTranspiledFiles()Description copied from class:AbstractCompilerGets whether any file needed to transpile any feature- Specified by:
getTranspiledFilesin classAbstractCompiler
-
setTranspiledFiles
public void setTranspiledFiles(boolean transpiledFiles) -
getCrossModuleIdGenerator
Description copied from class:AbstractCompilerGets the id generator for cross-module motion.- Specified by:
getCrossModuleIdGeneratorin classAbstractCompiler
-
setAnonymousFunctionNameMap
Description copied from class:AbstractCompilerSets the naming map for anonymous functions- Specified by:
setAnonymousFunctionNameMapin classAbstractCompiler
-
setInstrumentationMapping
Description copied from class:AbstractCompilerSets the mapping for instrumentation parameter encoding.- Specified by:
setInstrumentationMappingin classAbstractCompiler
-
getInstrumentationMapping
-
addExportedNames
Description copied from class:AbstractCompilerAdds exported names to keep track.- Specified by:
addExportedNamesin classAbstractCompiler
-
getExportedNames
Description copied from class:AbstractCompilerGets the names that have been exported.- Specified by:
getExportedNamesin classAbstractCompiler
-
setDefineNames
Description copied from class:AbstractCompilerAdds @define names to keep track.- Specified by:
setDefineNamesin classAbstractCompiler
-
getDefineNames
- Specified by:
getDefineNamesin 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:AbstractCompilerGets the error manager.- Specified by:
getErrorManagerin classAbstractCompiler
-
getInputsById
Returns an unmodifiable view of the compiler inputs indexed by id. -
getExternProperties
Description copied from class:AbstractCompilerGets the names of the properties defined in externs or null if GatherExternProperties pass was not run yet.- Specified by:
getExternPropertiesin classAbstractCompiler
-
setAccessorSummary
public void setAccessorSummary(com.google.javascript.jscomp.AccessorSummary summary) Description copied from class:AbstractCompilerSets the summary of properties with getters and setters.- Specified by:
setAccessorSummaryin 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:
IOExceptionClassNotFoundException
-
getModuleMetadataMap
- Specified by:
getModuleMetadataMapin classAbstractCompiler
-
setModuleMetadataMap
- Specified by:
setModuleMetadataMapin classAbstractCompiler
-
getModuleMap
- Specified by:
getModuleMapin classAbstractCompiler
-
setModuleMap
- Specified by:
setModuleMapin classAbstractCompiler
-
resetAndIntitializeSourceMap
public void resetAndIntitializeSourceMap()
-