Documentation
¶
Overview ¶
Package compiler implements the TypeScript compiler.
Index ¶
- func SortAndDeduplicateDiagnostics(diagnostics []*ast.Diagnostic) []*ast.Diagnostic
- type CheckerPool
- type CompilerHost
- type EmitHost
- type EmitOptions
- type EmitResult
- type FileIncludeKind
- type FileIncludeReason
- type FileInfo
- type Program
- func (p *Program) BindSourceFiles()
- func (p *Program) CheckSourceFiles(ctx context.Context)
- func (p *Program) CommonSourceDirectory() string
- func (p *Program) Emit(options EmitOptions) *EmitResult
- func (p *Program) FileExists(path string) bool
- func (p *Program) GetBindDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetCompilerOptions() *core.CompilerOptions
- 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) GetEmitModuleFormatOfFile(sourceFile *ast.SourceFile) core.ModuleKind
- func (p *Program) GetEmitModuleFormatOfFileWorker(sourceFile *ast.SourceFile, options *core.CompilerOptions) core.ModuleKind
- func (p *Program) GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic
- func (p *Program) GetGlobalTypingsCacheLocation() string
- func (p *Program) GetImpliedNodeFormatForEmit(sourceFile *ast.SourceFile) core.ResolutionMode
- func (p *Program) GetImportHelpersImportSpecifier(path tspath.Path) *ast.Node
- func (p *Program) GetJSXRuntimeImportSpecifier(path tspath.Path) (moduleReference string, specifier *ast.Node)
- 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) GetProjectReferenceRedirect(path string) string
- func (p *Program) GetRedirectTargets(path tspath.Path) []string
- func (p *Program) GetResolvedModule(file *ast.SourceFile, moduleReference string) *ast.SourceFile
- func (p *Program) GetResolvedModules() map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
- func (p *Program) GetSemanticDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
- func (p *Program) GetSourceFile(filename string) *ast.SourceFile
- func (p *Program) GetSourceFileByPath(path tspath.Path) *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) 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) Host() CompilerHost
- func (p *Program) IdentifierCount() int
- func (p *Program) InstantiationCount() int
- func (p *Program) IsSourceOfProjectReferenceRedirect(path string) bool
- func (p *Program) LineCount() int
- func (p *Program) Options() *core.CompilerOptions
- 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) (*Program, bool)
- func (p *Program) UseCaseSensitiveFileNames() bool
- type ProgramOptions
- type SourceMapEmitResult
- type WriteFileData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 NewLine() string Trace(msg string) GetSourceFile(fileName string, path tspath.Path, languageVersion core.ScriptTarget) *ast.SourceFile }
func NewCachedFSCompilerHost ¶
func NewCachedFSCompilerHost(options *core.CompilerOptions, currentDirectory string, fs vfs.FS, defaultLibraryPath string) CompilerHost
func NewCompilerHost ¶
func NewCompilerHost(options *core.CompilerOptions, currentDirectory string, fs vfs.FS, defaultLibraryPath 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 GetSourceFileMetaData(path tspath.Path) *ast.SourceFileMetaData GetEmitResolver(file *ast.SourceFile, skipDiagnostics bool) printer.EmitResolver }
NOTE: EmitHost operations must be thread-safe
type EmitOptions ¶
type EmitOptions struct { TargetSourceFile *ast.SourceFile // Single file to emit. If `nil`, emits all files // contains filtered or unexported fields }
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 }
type FileIncludeKind ¶
type FileIncludeKind int
const ( FileIncludeKindRootFile FileIncludeKind = iota FileIncludeKindSourceFromProjectReference FileIncludeKindOutputFromProjectReference FileIncludeKindImport FileIncludeKindReferenceFile FileIncludeKindTypeReferenceDirective FileIncludeKindLibFile FileIncludeKindLibReferenceDirective FileIncludeKindAutomaticTypeDirectiveFile )
type FileIncludeReason ¶
type FileIncludeReason struct { Kind FileIncludeKind Index int }
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
func NewProgram ¶
func NewProgram(options ProgramOptions) *Program
func NewProgramFromParsedCommandLine ¶
func NewProgramFromParsedCommandLine(config *tsoptions.ParsedCommandLine, host CompilerHost) *Program
func (*Program) BindSourceFiles ¶
func (p *Program) BindSourceFiles()
func (*Program) CheckSourceFiles ¶
func (*Program) CommonSourceDirectory ¶
func (*Program) Emit ¶
func (p *Program) Emit(options EmitOptions) *EmitResult
func (*Program) FileExists ¶
FileExists implements checker.Program.
func (*Program) GetBindDiagnostics ¶
func (p *Program) GetBindDiagnostics(ctx context.Context, sourceFile *ast.SourceFile) []*ast.Diagnostic
func (*Program) GetCompilerOptions ¶
func (p *Program) GetCompilerOptions() *core.CompilerOptions
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) GetEmitModuleFormatOfFile ¶
func (p *Program) GetEmitModuleFormatOfFile(sourceFile *ast.SourceFile) core.ModuleKind
func (*Program) GetEmitModuleFormatOfFileWorker ¶
func (p *Program) GetEmitModuleFormatOfFileWorker(sourceFile *ast.SourceFile, options *core.CompilerOptions) core.ModuleKind
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.SourceFile) core.ResolutionMode
func (*Program) GetImportHelpersImportSpecifier ¶
func (*Program) GetJSXRuntimeImportSpecifier ¶
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) GetProjectReferenceRedirect ¶
GetProjectReferenceRedirect implements checker.Program.
func (*Program) GetRedirectTargets ¶
GetRedirectTargets implements checker.Program.
func (*Program) GetResolvedModule ¶
func (p *Program) GetResolvedModule(file *ast.SourceFile, moduleReference string) *ast.SourceFile
func (*Program) GetResolvedModules ¶
func (p *Program) GetResolvedModules() map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
func (*Program) GetSemanticDiagnostics ¶
func (p *Program) GetSemanticDiagnostics(ctx context.Context, sourceFile *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) 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) 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) Host ¶
func (p *Program) Host() CompilerHost
func (*Program) IdentifierCount ¶
func (*Program) InstantiationCount ¶
func (*Program) IsSourceOfProjectReferenceRedirect ¶
IsSourceOfProjectReferenceRedirect implements checker.Program.
func (*Program) Options ¶
func (p *Program) Options() *core.CompilerOptions
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.
type ProgramOptions ¶
type ProgramOptions struct { RootFiles []string Host CompilerHost Options *core.CompilerOptions SingleThreaded core.Tristate ProjectReference []core.ProjectReference ConfigFileParsingDiagnostics []*ast.Diagnostic CreateCheckerPool func(*Program) CheckerPool TypingsLocation string ProjectName string }
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 WriteFileData ¶
type WriteFileData struct { SourceMapUrlPos int // BuildInfo BuildInfo Diagnostics []*ast.Diagnostic DiffersOnlyInMap bool SkippedDtsWrite bool }