Documentation
¶
Overview ¶
Package compiler implements the TypeScript compiler.
Index ¶
- func FilterNoEmitSemanticDiagnostics(diagnostics []*ast.Diagnostic, options *core.CompilerOptions) []*ast.Diagnostic
- func GetDiagnosticsOfAnyProgram(ctx context.Context, program ProgramLike, file *ast.SourceFile, ...) []*ast.Diagnostic
- func SortAndDeduplicateDiagnostics(diagnostics []*ast.Diagnostic) []*ast.Diagnostic
- type CheckerPool
- type CompilerHost
- type EmitHost
- type EmitOnly
- type EmitOptions
- type EmitResult
- type LibFile
- type Program
- func (p *Program) BindSourceFiles()
- func (p *Program) CheckSourceFiles(ctx context.Context, files []*ast.SourceFile)
- func (p *Program) CommandLine() *tsoptions.ParsedCommandLine
- func (p *Program) CommonSourceDirectory() string
- func (p *Program) Emit(ctx context.Context, options EmitOptions) *EmitResult
- func (p *Program) ExplainFiles(w io.Writer)
- func (p *Program) FileExists(path string) bool
- func (p *Program) ForEachResolvedProjectReference(fn func(path tspath.Path, config *tsoptions.ParsedCommandLine, ...))
- func (p *Program) GetBindDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetConfigFileParsingDiagnostics() []*ast.Diagnostic
- func (p *Program) GetCurrentDirectory() string
- func (p *Program) GetDeclarationDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetDefaultLibFile(path tspath.Path) *LibFile
- func (p *Program) GetDefaultResolutionModeForFile(sourceFile ast.HasFileName) core.ResolutionMode
- func (p *Program) GetEmitModuleFormatOfFile(sourceFile ast.HasFileName) core.ModuleKind
- func (p *Program) GetEmitSyntaxForUsageLocation(sourceFile ast.HasFileName, location *ast.StringLiteralLike) core.ResolutionMode
- func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic
- func (p *Program) GetGlobalTypingsCacheLocation() string
- func (p *Program) GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ResolutionMode
- func (p *Program) GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
- func (p *Program) GetIncludeProcessorDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetIncludeReasons() map[tspath.Path][]*fileIncludeReason
- func (p *Program) GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node)
- func (p *Program) GetLibFileFromReference(ref *ast.FileReference) *ast.SourceFile
- func (p *Program) GetModeForUsageLocation(sourceFile ast.HasFileName, location *ast.StringLiteralLike) core.ResolutionMode
- func (p *Program) GetNearestAncestorDirectoryWithPackageJson(dirname string) string
- func (p *Program) GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic
- func (p *Program) GetPackageJsonInfo(pkgJsonPath string) modulespecifiers.PackageJsonInfo
- func (p *Program) GetParseFileRedirect(fileName string) string
- func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic
- func (p *Program) GetProjectReferenceFromOutputDts(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
- func (p *Program) GetProjectReferenceFromSource(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
- func (p *Program) GetRedirectForResolution(file ast.HasFileName) *tsoptions.ParsedCommandLine
- func (p *Program) GetRedirectTargets(path tspath.Path) []string
- func (p *Program) GetResolvedModule(file ast.HasFileName, moduleReference string, mode core.ResolutionMode) *module.ResolvedModule
- func (p *Program) GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) *module.ResolvedModule
- func (p *Program) GetResolvedModules() map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
- func (p *Program) GetResolvedProjectReferenceFor(path tspath.Path) (*tsoptions.ParsedCommandLine, bool)
- func (p *Program) GetResolvedTypeReferenceDirectiveFromTypeReferenceDirective(typeRef *ast.FileReference, sourceFile *ast.SourceFile) *module.ResolvedTypeReferenceDirective
- func (p *Program) GetResolvedTypeReferenceDirectives() map[tspath.Path]module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
- func (p *Program) GetSemanticDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetSemanticDiagnosticsNoFilter(ctx context.Context, sourceFiles []*ast.SourceFile) map[*ast.SourceFile][]*ast.Diagnostic
- func (p *Program) GetSourceFile(filename string) *ast.SourceFile
- func (p *Program) GetSourceFileByPath(path tspath.Path) *ast.SourceFile
- func (p *Program) GetSourceFileForResolvedModule(fileName string) *ast.SourceFile
- func (p *Program) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.FileReference) *ast.SourceFile
- func (p *Program) GetSourceFileMetaData(path tspath.Path) ast.SourceFileMetaData
- func (p *Program) GetSourceFiles() []*ast.SourceFile
- func (p *Program) GetSourceOfProjectReferenceIfOutputIncluded(file ast.HasFileName) string
- func (p *Program) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetSyntacticDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetTypeChecker(ctx context.Context) (*checker.Checker, func())
- func (p *Program) GetTypeCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())
- func (p *Program) GetTypeCheckers(ctx context.Context) ([]*checker.Checker, func())
- func (p *Program) GetUnresolvedImports() *collections.Set[string]
- func (p *Program) HasSameFileNames(other *Program) bool
- func (p *Program) Host() CompilerHost
- func (p *Program) IdentifierCount() int
- func (p *Program) InstantiationCount() int
- func (p *Program) IsEmitBlocked(emitFileName string) bool
- func (p *Program) IsMissingPath(path tspath.Path) bool
- func (p *Program) IsSourceFileDefaultLibrary(path tspath.Path) bool
- func (p *Program) IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool
- func (p *Program) IsSourceFromProjectReference(path tspath.Path) bool
- func (p *Program) LineCount() int
- func (p *Program) Options() *core.CompilerOptions
- func (p *Program) SingleThreaded() bool
- func (p *Program) SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmit bool) bool
- func (p *Program) SourceFiles() []*ast.SourceFile
- func (p *Program) SymbolCount() int
- func (p *Program) TypeCount() int
- func (p *Program) UnsupportedExtensions() []string
- func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHost) (*Program, bool)
- func (p *Program) UseCaseSensitiveFileNames() bool
- func (p *Program) UsesUriStyleNodeCoreModules() bool
- type ProgramLike
- type ProgramOptions
- type SourceFileMayBeEmittedHost
- type SourceMapEmitResult
- type WriteFile
- type WriteFileData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterNoEmitSemanticDiagnostics ¶
func FilterNoEmitSemanticDiagnostics(diagnostics []*ast.Diagnostic, options *core.CompilerOptions) []*ast.Diagnostic
func GetDiagnosticsOfAnyProgram ¶
func GetDiagnosticsOfAnyProgram( ctx context.Context, program ProgramLike, file *ast.SourceFile, skipNoEmitCheckForDtsDiagnostics bool, getBindDiagnostics func(context.Context, *ast.SourceFile) []*ast.Diagnostic, getSemanticDiagnostics func(context.Context, *ast.SourceFile) []*ast.Diagnostic, ) []*ast.Diagnostic
func SortAndDeduplicateDiagnostics ¶
func SortAndDeduplicateDiagnostics(diagnostics []*ast.Diagnostic) []*ast.Diagnostic
Types ¶
type CheckerPool ¶
type CheckerPool interface {
GetChecker(ctx context.Context) (*checker.Checker, func())
GetCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())
GetAllCheckers(ctx context.Context) ([]*checker.Checker, func())
Files(checker *checker.Checker) iter.Seq[*ast.SourceFile]
}
type CompilerHost ¶
type CompilerHost interface {
FS() vfs.FS
DefaultLibraryPath() string
GetCurrentDirectory() string
Trace(msg string)
GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile
GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine
}
func NewCachedFSCompilerHost ¶
func NewCachedFSCompilerHost( currentDirectory string, fs vfs.FS, defaultLibraryPath string, extendedConfigCache tsoptions.ExtendedConfigCache, trace func(msg string), ) CompilerHost
func NewCompilerHost ¶
func NewCompilerHost( currentDirectory string, fs vfs.FS, defaultLibraryPath string, extendedConfigCache tsoptions.ExtendedConfigCache, trace func(msg string), ) CompilerHost
type EmitHost ¶
type EmitHost interface {
printer.EmitHost
declarations.DeclarationEmitHost
Options() *core.CompilerOptions
SourceFiles() []*ast.SourceFile
UseCaseSensitiveFileNames() bool
GetCurrentDirectory() string
CommonSourceDirectory() string
IsEmitBlocked(file string) bool
}
NOTE: EmitHost operations must be thread-safe
type EmitOptions ¶
type EmitOptions struct {
TargetSourceFile *ast.SourceFile // Single file to emit. If `nil`, emits all files
EmitOnly EmitOnly
WriteFile WriteFile
}
type EmitResult ¶
type EmitResult struct {
EmitSkipped bool
Diagnostics []*ast.Diagnostic // Contains declaration emit diagnostics
EmittedFiles []string // Array of files the compiler wrote to disk
SourceMaps []*SourceMapEmitResult // Array of sourceMapData if compiler emitted sourcemaps
}
func CombineEmitResults ¶
func CombineEmitResults(results []*EmitResult) *EmitResult
func HandleNoEmitOnError ¶
func HandleNoEmitOnError(ctx context.Context, program ProgramLike, file *ast.SourceFile) *EmitResult
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
func NewProgram ¶
func NewProgram(opts ProgramOptions) *Program
func (*Program) BindSourceFiles ¶
func (p *Program) BindSourceFiles()
func (*Program) CheckSourceFiles ¶
func (p *Program) CheckSourceFiles(ctx context.Context, files []*ast.SourceFile)
func (*Program) CommandLine ¶
func (p *Program) CommandLine() *tsoptions.ParsedCommandLine
func (*Program) CommonSourceDirectory ¶
func (*Program) Emit ¶
func (p *Program) Emit(ctx context.Context, options EmitOptions) *EmitResult
func (*Program) ExplainFiles ¶
func (*Program) FileExists ¶
FileExists implements checker.Program.
func (*Program) ForEachResolvedProjectReference ¶
func (p *Program) ForEachResolvedProjectReference( fn func(path tspath.Path, config *tsoptions.ParsedCommandLine, parent *tsoptions.ParsedCommandLine, index int), )
func (*Program) GetBindDiagnostics ¶
func (p *Program) GetBindDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetConfigFileParsingDiagnostics ¶
func (p *Program) GetConfigFileParsingDiagnostics() []*ast.Diagnostic
func (*Program) GetCurrentDirectory ¶
GetCurrentDirectory implements checker.Program.
func (*Program) GetDeclarationDiagnostics ¶
func (p *Program) GetDeclarationDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetDefaultResolutionModeForFile ¶
func (p *Program) GetDefaultResolutionModeForFile(sourceFile ast.HasFileName) core.ResolutionMode
func (*Program) GetEmitModuleFormatOfFile ¶
func (p *Program) GetEmitModuleFormatOfFile(sourceFile ast.HasFileName) core.ModuleKind
func (*Program) GetEmitSyntaxForUsageLocation ¶
func (p *Program) GetEmitSyntaxForUsageLocation(sourceFile ast.HasFileName, location *ast.StringLiteralLike) core.ResolutionMode
func (*Program) GetGlobalDiagnostics ¶
func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic
func (*Program) GetGlobalTypingsCacheLocation ¶
GetGlobalTypingsCacheLocation implements checker.Program.
func (*Program) GetImpliedNodeFormatForEmit ¶
func (p *Program) GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ResolutionMode
func (*Program) GetImportHelpersImportSpecifier ¶
func (*Program) GetIncludeProcessorDiagnostics ¶
func (p *Program) GetIncludeProcessorDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetIncludeReasons ¶
Testing only
func (*Program) GetJSXRuntimeImportSpecifier ¶
func (*Program) GetLibFileFromReference ¶
func (p *Program) GetLibFileFromReference(ref *ast.FileReference) *ast.SourceFile
func (*Program) GetModeForUsageLocation ¶
func (p *Program) GetModeForUsageLocation(sourceFile ast.HasFileName, location *ast.StringLiteralLike) core.ResolutionMode
func (*Program) GetNearestAncestorDirectoryWithPackageJson ¶
GetNearestAncestorDirectoryWithPackageJson implements checker.Program.
func (*Program) GetOptionsDiagnostics ¶
func (p *Program) GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic
func (*Program) GetPackageJsonInfo ¶
func (p *Program) GetPackageJsonInfo(pkgJsonPath string) modulespecifiers.PackageJsonInfo
GetPackageJsonInfo implements checker.Program.
func (*Program) GetParseFileRedirect ¶
func (*Program) GetProgramDiagnostics ¶
func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic
func (*Program) GetProjectReferenceFromOutputDts ¶
func (p *Program) GetProjectReferenceFromOutputDts(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
func (*Program) GetProjectReferenceFromSource ¶
func (p *Program) GetProjectReferenceFromSource(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
GetProjectReferenceFromSource implements checker.Program.
func (*Program) GetRedirectForResolution ¶
func (p *Program) GetRedirectForResolution(file ast.HasFileName) *tsoptions.ParsedCommandLine
func (*Program) GetRedirectTargets ¶
GetRedirectTargets implements checker.Program.
func (*Program) GetResolvedModule ¶
func (p *Program) GetResolvedModule(file ast.HasFileName, moduleReference string, mode core.ResolutionMode) *module.ResolvedModule
func (*Program) GetResolvedModuleFromModuleSpecifier ¶
func (p *Program) GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) *module.ResolvedModule
func (*Program) GetResolvedModules ¶
func (p *Program) GetResolvedModules() map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
func (*Program) GetResolvedProjectReferenceFor ¶
func (*Program) GetResolvedTypeReferenceDirectiveFromTypeReferenceDirective ¶
func (p *Program) GetResolvedTypeReferenceDirectiveFromTypeReferenceDirective(typeRef *ast.FileReference, sourceFile *ast.SourceFile) *module.ResolvedTypeReferenceDirective
func (*Program) GetResolvedTypeReferenceDirectives ¶
func (p *Program) GetResolvedTypeReferenceDirectives() map[tspath.Path]module.ModeAwareCache[*module.ResolvedTypeReferenceDirective]
func (*Program) GetSemanticDiagnostics ¶
func (p *Program) GetSemanticDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetSemanticDiagnosticsNoFilter ¶
func (p *Program) GetSemanticDiagnosticsNoFilter(ctx context.Context, sourceFiles []*ast.SourceFile) map[*ast.SourceFile][]*ast.Diagnostic
func (*Program) GetSourceFile ¶
func (p *Program) GetSourceFile(filename string) *ast.SourceFile
func (*Program) GetSourceFileByPath ¶
func (p *Program) GetSourceFileByPath(path tspath.Path) *ast.SourceFile
func (*Program) GetSourceFileForResolvedModule ¶
func (p *Program) GetSourceFileForResolvedModule(fileName string) *ast.SourceFile
func (*Program) GetSourceFileFromReference ¶
func (p *Program) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.FileReference) *ast.SourceFile
* This should have similar behavior to 'processSourceFile' without diagnostics or mutation.
func (*Program) GetSourceFileMetaData ¶
func (p *Program) GetSourceFileMetaData(path tspath.Path) ast.SourceFileMetaData
func (*Program) GetSourceFiles ¶
func (p *Program) GetSourceFiles() []*ast.SourceFile
func (*Program) GetSourceOfProjectReferenceIfOutputIncluded ¶
func (p *Program) GetSourceOfProjectReferenceIfOutputIncluded(file ast.HasFileName) string
gets the original file that was included in program this returns original source file name when including output of project reference otherwise same name Equivalent to originalFileName on SourceFile in Strada
func (*Program) GetSuggestionDiagnostics ¶
func (p *Program) GetSuggestionDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetSyntacticDiagnostics ¶
func (p *Program) GetSyntacticDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetTypeChecker ¶
Return the type checker associated with the program.
func (*Program) GetTypeCheckerForFile ¶
func (p *Program) GetTypeCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func())
Return a checker for the given file. We may have multiple checkers in concurrent scenarios and this method returns the checker that was tasked with checking the file. Note that it isn't possible to mix types obtained from different checkers, so only non-type data (such as diagnostics or string representations of types) should be obtained from checkers returned by this method.
func (*Program) GetTypeCheckers ¶
func (*Program) GetUnresolvedImports ¶
func (p *Program) GetUnresolvedImports() *collections.Set[string]
GetUnresolvedImports returns the unresolved imports for this program. The result is cached and computed only once.
func (*Program) HasSameFileNames ¶
func (*Program) Host ¶
func (p *Program) Host() CompilerHost
func (*Program) IdentifierCount ¶
func (*Program) InstantiationCount ¶
func (*Program) IsEmitBlocked ¶
func (*Program) IsSourceFileDefaultLibrary ¶
func (*Program) IsSourceFileFromExternalLibrary ¶
func (p *Program) IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool
func (*Program) IsSourceFromProjectReference ¶
IsSourceFromProjectReference implements checker.Program.
func (*Program) Options ¶
func (p *Program) Options() *core.CompilerOptions
func (*Program) SingleThreaded ¶
func (*Program) SourceFileMayBeEmitted ¶
func (p *Program) SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmit bool) bool
func (*Program) SourceFiles ¶
func (p *Program) SourceFiles() []*ast.SourceFile
func (*Program) SymbolCount ¶
func (*Program) UnsupportedExtensions ¶
UnsupportedExtensions returns a list of all present "unsupported" extensions, e.g. extensions that are not yet supported by the port.
func (*Program) UpdateProgram ¶
Return an updated program for which it is known that only the file with the given path has changed. In addition to a new program, return a boolean indicating whether the data of the old program was reused.
func (*Program) UseCaseSensitiveFileNames ¶
UseCaseSensitiveFileNames implements checker.Program.
func (*Program) UsesUriStyleNodeCoreModules ¶
type ProgramLike ¶
type ProgramLike interface {
Options() *core.CompilerOptions
GetSourceFiles() []*ast.SourceFile
GetConfigFileParsingDiagnostics() []*ast.Diagnostic
GetSyntacticDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic
GetBindDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic
GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic
GetProgramDiagnostics() []*ast.Diagnostic
GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic
GetSemanticDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic
GetDeclarationDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic
Emit(ctx context.Context, options EmitOptions) *EmitResult
}
type ProgramOptions ¶
type ProgramOptions struct {
Host CompilerHost
Config *tsoptions.ParsedCommandLine
UseSourceOfProjectReference bool
SingleThreaded core.Tristate
CreateCheckerPool func(*Program) CheckerPool
TypingsLocation string
ProjectName string
JSDocParsingMode ast.JSDocParsingMode
}
type SourceFileMayBeEmittedHost ¶
type SourceFileMayBeEmittedHost interface {
Options() *core.CompilerOptions
GetProjectReferenceFromSource(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool
GetCurrentDirectory() string
UseCaseSensitiveFileNames() bool
SourceFiles() []*ast.SourceFile
}
type SourceMapEmitResult ¶
type SourceMapEmitResult struct {
InputSourceFileNames []string // Input source file (which one can use on program to get the file), 1:1 mapping with the sourceMap.sources list
SourceMap *sourcemap.RawSourceMap
GeneratedFile string
}
type WriteFile ¶
type WriteFile func(fileName string, text string, writeByteOrderMark bool, data *WriteFileData) error
type WriteFileData ¶
type WriteFileData struct {
SourceMapUrlPos int
BuildInfo any
Diagnostics []*ast.Diagnostic
SkippedDtsWrite bool
}