Class Compiler
- java.lang.Object
-
- com.google.javascript.jscomp.AbstractCompiler
-
- com.google.javascript.jscomp.Compiler
-
- All Implemented Interfaces:
CompilerInputProvider,ErrorHandler,SourceExcerptProvider,SourceFileMapping
public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFileMapping
Compiler (and the other classes in this package) does the following:- 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 Classes Modifier and Type Class Description static classCompiler.CodeBuilderStores a buffer of text to which more can be appended.static classCompiler.ExternalSourceLoaderSubclasses are responsible for loading sources that were not provided as explicit inputs to the compiler.-
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.SourceExcerptProvider
SourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.logging.LoggerloggerLogger for the whole com.google.javascript.jscomp domain - setting configuration for this logger affects all loggers in other classes within the compiler.static DiagnosticTypeMOTION_ITERATIONS_ERRORstatic DiagnosticTypeOPTIMIZE_LOOP_ERRORError strings used for reporting JSErrorsprotected com.google.javascript.jscomp.RecentChangerecentChangePerformanceTrackertracker-
Fields inherited from class com.google.javascript.jscomp.AbstractCompiler
annotationMap
-
-
Constructor Summary
Constructors Constructor Description Compiler()Creates a Compiler that reports errors and warnings to its logger.Compiler(ErrorManager errorManager)Creates a Compiler that uses a custom error manager.Compiler(java.io.PrintStream outStream)Creates a Compiler that reports errors and warnings to an output stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExportedNames(java.util.Set<java.lang.String> exportedNames)Adds exported names to keep track.voidaddInputSourceMap(java.lang.String sourceFileName, SourceMapInput inputSourceMap)Adds aSourceMapInputfor the givensourceFileName, to be used for error reporting and source map combining.voidaddNewScript(JsAst ast)Adds a new Script AST to the compile state.SymbolTablebuildKnownSymbolTable()voidclearJSTypeRegistry()Resultcompile(SourceFile extern, SourceFile input, CompilerOptions options)Compiles a single source file and a single externs file.<T1 extends SourceFile,T2 extends SourceFile>
Resultcompile(java.util.List<T1> externs, java.util.List<T2> inputs, CompilerOptions options)Compiles a list of inputs.<T extends SourceFile>
ResultcompileModules(java.util.List<T> externs, java.util.List<JSModule> modules, CompilerOptions options)Compiles a list of modules.protected com.google.javascript.jscomp.CompilerExecutorcreateCompilerExecutor()protected ConfigcreateConfig(Config.LanguageMode mode, Config.StrictMode strictMode)protected PassConfigcreatePassConfigInternal()Create the passes object.voiddisableThreads()Disable threads.protected NodeensureLibraryInjected(java.lang.String resourceName, boolean force)voidforwardDeclareType(java.lang.String typeName)voidgenerateReport()Generates a report of all warnings and errors found during compilation to stderr.java.lang.StringgetAstDotGraph()Gets the DOT graph of the AST generated at the end of compilation.intgetChangeStamp()CodingConventiongetCodingConvention()Gets the current coding convention.java.util.List<Comment>getComments(java.lang.String filename)protected com.google.javascript.jscomp.CompilerExecutorgetCompilerExecutor()com.google.javascript.jscomp.IdGeneratorgetCrossModuleIdGenerator()Gets the id generator for cross-module motion.DiagnosticGroupsgetDiagnosticGroups()The warning classes that are available from the command-line, and are suppressible by the@suppressannotation.intgetErrorCount()Gets the number of errors.CheckLevelgetErrorLevel(JSError error)ErrorManagergetErrorManager()Gets the error manager.com.google.common.collect.ImmutableList<JSError>getErrors()Returns the list of errors (never null).java.util.Set<java.lang.String>getExportedNames()Gets the names that have been exported.protected NodegetExternsRoot()java.lang.Iterable<TypeMismatch>getImplicitInterfaceUses()Gets all types that are used implicitly as a matching interface type.CompilerInputgetInput(InputId id)Looks up an input (possibly an externs input) by input id.java.util.Map<InputId,CompilerInput>getInputsById()Returns an unmodifiable view of the compiler inputs indexed by id.protected NodegetJsRoot()ModuleLoadergetModuleLoader()ModuleMapgetModuleMap()ModuleMetadataMapgetModuleMetadataMap()java.lang.Iterable<JSModule>getModules()Gets the JS source modules in dependency order.protected NodegetNodeForCodeInsertion(JSModule module)CompilerOptionsgetOptions()doublegetProgress()static java.lang.StringgetReleaseDate()Returns the compiler date baked into the jar.static java.lang.StringgetReleaseVersion()Returns the compiler version baked into the jar.ResultgetResult()Returns the result of the compilation.ReverseAbstractInterpretergetReverseAbstractInterpreter()Get an interpreter for type analysis.NodegetRoot()Returns the root node of the AST, which includes both externs and source.NodegetScriptNode(java.lang.String filename)java.lang.CharSequencegetSourceFileContentByName(java.lang.String sourceName)java.lang.StringgetSourceLine(java.lang.String sourceName, int lineNumber)Get the line indicated by the line number.RegiongetSourceLines(java.lang.String sourceName, int lineNumber, int length)Gets the specific lines returned by the beginning and excerpt length.SourceMapgetSourceMap()com.google.debugging.sourcemap.proto.Mapping.OriginalMappinggetSourceMapping(java.lang.String sourceName, int lineNumber, int columnNumber)Returns the original mapping for the file name, line number and column position found in the source map.RegiongetSourceRegion(java.lang.String sourceName, int lineNumber)Get a region around the indicated line number.TypedScopegetTopScope()Gets the top scope.com.google.javascript.jscomp.TypedScopeCreatorgetTypedScopeCreator()java.lang.Iterable<TypeMismatch>getTypeMismatches()Gets the central registry of type violations.JSTypeRegistrygetTypeRegistry()Gets a central registry of type information from the compiled JS.intgetWarningCount()Gets the number of warnings.com.google.common.collect.ImmutableList<JSError>getWarnings()Returns the list of warnings (never null).booleanhasErrors()Consults theErrorManagerto see if we've encountered errors that should halt compilation.voidincrementChangeStamp()<T1 extends SourceFile,T2 extends SourceFile>
voidinit(java.util.List<T1> externs, java.util.List<T2> sources, CompilerOptions options)Initializes the instance state needed for a compile job.voidinitBasedOnOptions()Do any initialization that is dependent on the compiler options.<T extends SourceFile>
voidinitModules(java.util.List<T> externs, java.util.List<JSModule> modules, CompilerOptions options)Initializes the instance state needed for a compile job if the sources are in modules.voidinitOptions(CompilerOptions options)Initializes the compiler options.voidinitWebpackMap(com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String> inputPathByWebpackId)voidinstrumentForCoverage()Instrument code for coverage.static java.lang.StringjoinPathParts(java.lang.String... pathParts)Creates an OS specific path string from partsvoidmaybeSetTracker()protected CompilerOptionsnewCompilerOptions()Allow subclasses to override the default CompileOptions object.voidparse()Parses input files without doing progress tracking that is part of a full compile.Nodeparse(SourceFile file)voidparseForCompilation()Parses input files in preparation for compilation.protected NodeparseSyntheticCode(java.lang.String js)voidperformPostCompilationTasks()Performs all the bookkeeping required at the end of a compilation.voidprintConfig(java.io.PrintStream printStream)voidrebuildInputsFromModules()Rebuilds the internal input map by iterating over all modules.protected voidreconcileOptionsWithGuards()When the CompilerOptions and its WarningsGuard overlap, reconcile any discrepancies.protected voidremoveExternInput(InputId id)Removes an input file from AST.voidreplaceScript(JsAst ast)Replaces one file in a hot-swap mode.voidreport(CheckLevel ignoredLevel, JSError error)voidreport(JSError error)Report an error or warning.voidreportChangeToChangeScope(Node changeScopeRoot)Mark modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)voidreportChangeToEnclosingScope(Node n)Passes that make modifications in a scope that is different than the Compiler.currentScope use this (eg, InlineVariables and many others)voidreportFunctionDeleted(Node n)voidresetAndIntitializeSourceMap()voidrestoreState(java.io.InputStream inputStream)voidsaveState(java.io.OutputStream outputStream)voidsetAnonymousFunctionNameMap(VariableMap functionMap)Sets the naming map for anonymous functionsvoidsetCssNames(java.util.Map<java.lang.String,java.lang.Integer> cssNames)Sets the css names found during compilation.voidsetErrorManager(ErrorManager errorManager)Sets the error manager.voidsetIdGeneratorMap(java.lang.String serializedIdMappings)Sets the id generator for cross-module motion.static voidsetLoggingLevel(java.util.logging.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 threadvoidsetVariableMap(VariableMap variableMap)Sets the variable renaming mapvoidstage1Passes()Perform compiler passes for stage 1 of compilation.voidstage2Passes()Perform compiler passes for stage 2 of compilation.java.lang.StringtoSource()Converts the main parse tree back to JS code.voidtoSource(Compiler.CodeBuilder cb, int inputSeqNum, Node root)Writes out JS code from a root node.java.lang.StringtoSource(JSModule module)Converts the parse tree for a module back to JS code.java.lang.StringtoSource(Node n)Generates JavaScript source code for an AST, doesn't generate source map info.java.lang.String[]toSourceArray()Converts the parse tree for each input back to JS code.java.lang.String[]toSourceArray(JSModule module)Converts the parse tree for each input in a module back to JS code.voidtranspileAndDontCheck()voidwhitespaceOnlyPasses()-
Methods inherited from class com.google.javascript.jscomp.AbstractCompiler
createAstFactory, createOrReopenIndexedLog, createOrReopenLog, getAstAnalyzer, isFillFileName
-
-
-
-
Field Detail
-
tracker
public PerformanceTracker tracker
-
OPTIMIZE_LOOP_ERROR
public static final DiagnosticType OPTIMIZE_LOOP_ERROR
Error strings used for reporting JSErrors
-
MOTION_ITERATIONS_ERROR
public static final DiagnosticType MOTION_ITERATIONS_ERROR
-
logger
public static final java.util.logging.Logger 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 Detail
-
Compiler
public Compiler()
Creates a Compiler that reports errors and warnings to its logger.
-
Compiler
public Compiler(java.io.PrintStream outStream)
Creates a Compiler that reports errors and warnings to an output stream.
-
Compiler
public Compiler(ErrorManager errorManager)
Creates a Compiler that uses a custom error manager.
-
-
Method Detail
-
setErrorManager
public void setErrorManager(ErrorManager errorManager)
Sets the error manager.- Parameters:
errorManager- the error manager, it cannot benull
-
initOptions
public void initOptions(CompilerOptions options)
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(java.io.PrintStream printStream)
-
reconcileOptionsWithGuards
protected void reconcileOptionsWithGuards()
When the CompilerOptions and its WarningsGuard overlap, reconcile any discrepancies.
-
init
public final <T1 extends SourceFile,T2 extends SourceFile> void init(java.util.List<T1> externs, java.util.List<T2> sources, CompilerOptions options)
Initializes the instance state needed for a compile job.
-
initModules
public <T extends SourceFile> void initModules(java.util.List<T> externs, java.util.List<JSModule> modules, CompilerOptions options)
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
public static java.lang.String joinPathParts(java.lang.String... pathParts)
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<T1>, java.util.List<T2>, com.google.javascript.jscomp.CompilerOptions)orinitModules(java.util.List<T>, java.util.List<com.google.javascript.jscomp.JSModule>, com.google.javascript.jscomp.CompilerOptions)call.
-
compile
public Result compile(SourceFile extern, SourceFile input, CompilerOptions options)
Compiles a single source file and a single externs file.
-
compile
public <T1 extends SourceFile,T2 extends SourceFile> Result compile(java.util.List<T1> externs, java.util.List<T2> inputs, CompilerOptions options)
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.
-
compileModules
public <T extends SourceFile> Result compileModules(java.util.List<T> externs, java.util.List<JSModule> modules, CompilerOptions options)
Compiles a list of modules.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
public void stage2Passes()
Perform compiler passes for stage 2 of compilation.Stage 2 consists primarily of 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.
-
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
-
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()orinitModules()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()orinitModules()must be called first to set up the input files to be read.TODO(bradfordcsmith): Rename this to parseIndependentOfCompilation() or similar.
-
parse
public Node parse(SourceFile file)
-
createPassConfigInternal
protected PassConfig createPassConfigInternal()
Create the passes object. Clients should use setPassConfig instead of overriding this.
-
setPassConfig
public void setPassConfig(PassConfig passes)
- Parameters:
passes- The PassConfig to use with this Compiler.- Throws:
java.lang.NullPointerException- if passes is nulljava.lang.IllegalStateException- if this.passes has already been assigned
-
whitespaceOnlyPasses
public void whitespaceOnlyPasses()
-
transpileAndDontCheck
public void transpileAndDontCheck()
-
getScriptNode
@Nullable public final Node getScriptNode(java.lang.String filename)
- Specified by:
getScriptNodein classAbstractCompiler
-
getResult
public Result getResult()
Returns the result of the compilation.
-
getErrors
public com.google.common.collect.ImmutableList<JSError> getErrors()
Returns the list of errors (never null).
-
getWarnings
public com.google.common.collect.ImmutableList<JSError> getWarnings()
Returns the list of warnings (never null).
-
getRoot
public Node getRoot()
Description copied from class:AbstractCompilerReturns the root node of the AST, which includes both externs and source.- Specified by:
getRootin classAbstractCompiler
-
getInput
public CompilerInput getInput(InputId id)
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
-
removeExternInput
protected void removeExternInput(InputId id)
Removes an input file from AST.- Parameters:
id- The id of the input to be removed.
-
getModules
@Nullable public java.lang.Iterable<JSModule> getModules()
Gets the JS source modules in dependency order.Returns null if
#initor#initModuleshasn'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
-
getTypeRegistry
public JSTypeRegistry getTypeRegistry()
Description copied from class:AbstractCompilerGets a central registry of type information from the compiled JS.- Specified by:
getTypeRegistryin classAbstractCompiler
-
forwardDeclareType
public void forwardDeclareType(java.lang.String typeName)
-
getTypedScopeCreator
public com.google.javascript.jscomp.TypedScopeCreator getTypedScopeCreator()
-
buildKnownSymbolTable
public SymbolTable buildKnownSymbolTable()
-
getTopScope
public TypedScope getTopScope()
Description copied from class:AbstractCompilerGets the top scope.- Specified by:
getTopScopein classAbstractCompiler
-
getReverseAbstractInterpreter
public ReverseAbstractInterpreter getReverseAbstractInterpreter()
Description copied from class:AbstractCompilerGet an interpreter for type analysis.- Specified by:
getReverseAbstractInterpreterin classAbstractCompiler
-
getTypeMismatches
public java.lang.Iterable<TypeMismatch> getTypeMismatches()
Description copied from class:AbstractCompilerGets the central registry of type violations.- Specified by:
getTypeMismatchesin classAbstractCompiler
-
getImplicitInterfaceUses
public java.lang.Iterable<TypeMismatch> getImplicitInterfaceUses()
Description copied from class:AbstractCompilerGets all types that are used implicitly as a matching interface type. These are recorded as TypeMismatchs only for convenience- Specified by:
getImplicitInterfaceUsesin classAbstractCompiler
-
maybeSetTracker
public void maybeSetTracker()
-
newCompilerOptions
protected CompilerOptions newCompilerOptions()
Allow subclasses to override the default CompileOptions object.
-
parseSyntheticCode
protected Node parseSyntheticCode(java.lang.String js)
-
toSource
public java.lang.String toSource()
Converts the main parse tree back to JS code.- Specified by:
toSourcein classAbstractCompiler
-
toSource
public java.lang.String toSource(JSModule module)
Converts the parse tree for a module back to JS code.
-
toSource
public void toSource(Compiler.CodeBuilder cb, 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.
-
toSource
public java.lang.String toSource(Node n)
Generates JavaScript source code for an AST, doesn't generate source map info.- Specified by:
toSourcein classAbstractCompiler
-
toSourceArray
public java.lang.String[] toSourceArray()
Converts the parse tree for each input back to JS code.
-
toSourceArray
public java.lang.String[] toSourceArray(JSModule module)
Converts the parse tree for each input in a module back to JS code.
-
getExternsRoot
protected Node getExternsRoot()
-
getJsRoot
protected Node getJsRoot()
-
getChangeStamp
public int getChangeStamp()
-
incrementChangeStamp
public void incrementChangeStamp()
-
reportChangeToChangeScope
public void reportChangeToChangeScope(Node changeScopeRoot)
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
public void reportFunctionDeleted(Node n)
-
reportChangeToEnclosingScope
public void reportChangeToEnclosingScope(Node n)
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
public CodingConvention getCodingConvention()
Description copied from class:AbstractCompilerGets the current coding convention.- Specified by:
getCodingConventionin classAbstractCompiler
-
createConfig
protected Config createConfig(Config.LanguageMode mode, Config.StrictMode strictMode)
-
getDiagnosticGroups
public DiagnosticGroups getDiagnosticGroups()
The warning classes that are available from the command-line, and are suppressible by the@suppressannotation.
-
report
public void report(JSError error)
Description copied from class:AbstractCompilerReport an error or warning.- Specified by:
reportin classAbstractCompiler
-
report
public void report(CheckLevel ignoredLevel, JSError error)
- Specified by:
reportin interfaceErrorHandler- Parameters:
ignoredLevel- the reporting levelerror- the error to report
-
getErrorLevel
public CheckLevel getErrorLevel(JSError error)
-
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
public java.lang.CharSequence getSourceFileContentByName(java.lang.String sourceName)
-
addInputSourceMap
public void addInputSourceMap(java.lang.String sourceFileName, SourceMapInput inputSourceMap)Description copied from class:AbstractCompilerAdds aSourceMapInputfor the givensourceFileName, to be used for error reporting and source map combining.- Specified by:
addInputSourceMapin classAbstractCompiler
-
getSourceMapping
@Nullable public com.google.debugging.sourcemap.proto.Mapping.OriginalMapping getSourceMapping(java.lang.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 interfaceSourceFileMappinglineNumber- The line number, 1-based.columnNumber- The column index, 1-based.
-
getSourceLine
public java.lang.String getSourceLine(java.lang.String sourceName, int lineNumber)Description copied from interface:SourceExcerptProviderGet the line indicated by the line number. This call will return only the specific line.- Specified by:
getSourceLinein interfaceSourceExcerptProviderlineNumber- the line number, 1 being the first line of the file- Returns:
- the line indicated, or
nullif it does not exist
-
getSourceLines
public Region getSourceLines(java.lang.String sourceName, int lineNumber, int length)
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 interfaceSourceExcerptProviderlineNumber- 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
public Region getSourceRegion(java.lang.String sourceName, int lineNumber)
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 interfaceSourceExcerptProviderlineNumber- 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
-
getSourceMap
public SourceMap getSourceMap()
-
setVariableMap
public void setVariableMap(VariableMap variableMap)
Description copied from class:AbstractCompilerSets the variable renaming map- Specified by:
setVariableMapin classAbstractCompiler
-
setPropertyMap
public void setPropertyMap(VariableMap propertyMap)
Description copied from class:AbstractCompilerSets the property renaming map- Specified by:
setPropertyMapin classAbstractCompiler
-
setStringMap
public void setStringMap(VariableMap stringMap)
Description copied from class:AbstractCompilerSets the string replacement map- Specified by:
setStringMapin classAbstractCompiler
-
setCssNames
public void setCssNames(java.util.Map<java.lang.String,java.lang.Integer> cssNames)
Description copied from class:AbstractCompilerSets the css names found during compilation.- Specified by:
setCssNamesin classAbstractCompiler
-
setIdGeneratorMap
public void setIdGeneratorMap(java.lang.String serializedIdMappings)
Description copied from class:AbstractCompilerSets the id generator for cross-module motion.- Specified by:
setIdGeneratorMapin classAbstractCompiler
-
getCrossModuleIdGenerator
public com.google.javascript.jscomp.IdGenerator getCrossModuleIdGenerator()
Description copied from class:AbstractCompilerGets the id generator for cross-module motion.- Specified by:
getCrossModuleIdGeneratorin classAbstractCompiler
-
setAnonymousFunctionNameMap
public void setAnonymousFunctionNameMap(VariableMap functionMap)
Description copied from class:AbstractCompilerSets the naming map for anonymous functions- Specified by:
setAnonymousFunctionNameMapin classAbstractCompiler
-
addExportedNames
public void addExportedNames(java.util.Set<java.lang.String> exportedNames)
Description copied from class:AbstractCompilerAdds exported names to keep track.- Specified by:
addExportedNamesin classAbstractCompiler
-
getExportedNames
public java.util.Set<java.lang.String> getExportedNames()
Description copied from class:AbstractCompilerGets the names that have been exported.- Specified by:
getExportedNamesin classAbstractCompiler
-
getOptions
public CompilerOptions getOptions()
-
setLoggingLevel
public static void setLoggingLevel(java.util.logging.Level level)
Sets the logging level for the com.google.javascript.jscomp package.
-
getAstDotGraph
public java.lang.String getAstDotGraph() throws java.io.IOExceptionGets the DOT graph of the AST generated at the end of compilation.- Throws:
java.io.IOException
-
getErrorManager
public ErrorManager getErrorManager()
Description copied from class:AbstractCompilerGets the error manager.- Specified by:
getErrorManagerin classAbstractCompiler
-
getInputsById
public java.util.Map<InputId,CompilerInput> getInputsById()
Returns an unmodifiable view of the compiler inputs indexed by id.
-
getProgress
public double getProgress()
- Specified by:
getProgressin classAbstractCompiler- Returns:
- a number in [0,1] range indicating an approximate progress of the last compile. Note this should only be used as a hint and no assumptions should be made on accuracy, even a completed compile may choose not to set this to 1.0 at the end.
-
replaceScript
public void replaceScript(JsAst ast)
Replaces one file in a hot-swap mode. The given JsAst should be made from a new version of a file that already was present in the last compile call. If the file is new, this will silently ignored.- Parameters:
ast- the ast of the file that is being replaced
-
addNewScript
public void addNewScript(JsAst ast)
Adds a new Script AST to the compile state. If a script for the same file already exists the script will not be added, instead a call to #replaceScript should be used.- Parameters:
ast- the ast of the new file
-
ensureLibraryInjected
protected Node ensureLibraryInjected(java.lang.String resourceName, boolean force)
-
getReleaseVersion
@GwtIncompatible("java.util.ResourceBundle") public static java.lang.String getReleaseVersion()Returns the compiler version baked into the jar.
-
getReleaseDate
@GwtIncompatible("java.util.ResourceBundle") public static java.lang.String getReleaseDate()Returns the compiler date baked into the jar.
-
getComments
public java.util.List<Comment> getComments(java.lang.String filename)
-
getModuleLoader
public ModuleLoader getModuleLoader()
-
initWebpackMap
public void initWebpackMap(com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String> inputPathByWebpackId)
-
createCompilerExecutor
protected com.google.javascript.jscomp.CompilerExecutor createCompilerExecutor()
-
getCompilerExecutor
protected com.google.javascript.jscomp.CompilerExecutor getCompilerExecutor()
-
saveState
@GwtIncompatible("ObjectOutputStream") public void saveState(java.io.OutputStream outputStream) throws java.io.IOException- Throws:
java.io.IOException
-
restoreState
@GwtIncompatible("ObjectInputStream") public void restoreState(java.io.InputStream inputStream) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
getModuleMetadataMap
public ModuleMetadataMap getModuleMetadataMap()
- Specified by:
getModuleMetadataMapin classAbstractCompiler
-
setModuleMetadataMap
public void setModuleMetadataMap(ModuleMetadataMap moduleMetadataMap)
- Specified by:
setModuleMetadataMapin classAbstractCompiler
-
getModuleMap
public ModuleMap getModuleMap()
- Specified by:
getModuleMapin classAbstractCompiler
-
setModuleMap
public void setModuleMap(ModuleMap moduleMap)
- Specified by:
setModuleMapin classAbstractCompiler
-
resetAndIntitializeSourceMap
public void resetAndIntitializeSourceMap()
-
-