forked from microsoft/typescript-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.go
632 lines (542 loc) · 21.6 KB
/
program.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
package compiler
import (
"fmt"
"slices"
"sync"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/binder"
"github.com/microsoft/typescript-go/internal/checker"
"github.com/microsoft/typescript-go/internal/compiler/diagnostics"
"github.com/microsoft/typescript-go/internal/compiler/module"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/parser"
"github.com/microsoft/typescript-go/internal/printer"
"github.com/microsoft/typescript-go/internal/scanner"
"github.com/microsoft/typescript-go/internal/sourcemap"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
)
type ProgramOptions struct {
ConfigFileName string
RootFiles []string
Host CompilerHost
Options *core.CompilerOptions
SingleThreaded bool
ProjectReference []core.ProjectReference
ConfigFileParsingDiagnostics []*ast.Diagnostic
}
type Program struct {
host CompilerHost
programOptions ProgramOptions
compilerOptions *core.CompilerOptions
configFileName string
nodeModules map[string]*ast.SourceFile
checkers []*checker.Checker
checkersOnce sync.Once
checkersByFile map[*ast.SourceFile]*checker.Checker
currentDirectory string
configFileParsingDiagnostics []*ast.Diagnostic
resolver *module.Resolver
resolvedModules map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule]
comparePathsOptions tspath.ComparePathsOptions
files []*ast.SourceFile
filesByPath map[tspath.Path]*ast.SourceFile
sourceFileMetaDatas map[tspath.Path]*ast.SourceFileMetaData
// The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
// This works as imported modules are discovered recursively in a depth first manner, specifically:
// - For each root file, findSourceFile is called.
// - This calls processImportedModules for each module imported in the source file.
// - This calls resolveModuleNames, and then calls findSourceFile for each resolved module.
// As all these operations happen - and are nested - within the createProgram call, they close over the below variables.
// The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses.
// maxNodeModuleJsDepth int
currentNodeModulesDepth int
usesUriStyleNodeCoreModules core.Tristate
commonSourceDirectory string
commonSourceDirectoryOnce sync.Once
// List of present unsupported extensions
unsupportedExtensions []string
}
func NewProgram(options ProgramOptions) *Program {
p := &Program{}
p.programOptions = options
p.compilerOptions = options.Options
p.configFileParsingDiagnostics = slices.Clip(options.ConfigFileParsingDiagnostics)
p.sourceFileMetaDatas = make(map[tspath.Path]*ast.SourceFileMetaData)
if p.compilerOptions == nil {
p.compilerOptions = &core.CompilerOptions{}
}
// p.maxNodeModuleJsDepth = p.options.MaxNodeModuleJsDepth
// TODO(ercornel): !!! tracing?
// tracing?.push(tracing.Phase.Program, "createProgram", { configFilePath: options.configFilePath, rootDir: options.rootDir }, /*separateBeginAndEnd*/ true);
// performance.mark("beforeProgram");
p.host = options.Host
if p.host == nil {
panic("host required")
}
rootFiles := options.RootFiles
p.configFileName = options.ConfigFileName
if p.configFileName != "" {
jsonText, ok := p.host.FS().ReadFile(p.configFileName)
if !ok {
panic("config file not found")
}
configFilePath := tspath.ToPath(p.configFileName, p.host.GetCurrentDirectory(), p.host.FS().UseCaseSensitiveFileNames())
parsedConfig := parser.ParseJSONText(p.configFileName, configFilePath, jsonText)
if len(parsedConfig.Diagnostics()) > 0 {
p.configFileParsingDiagnostics = append(p.configFileParsingDiagnostics, parsedConfig.Diagnostics()...)
return p
}
tsConfigSourceFile := &tsoptions.TsConfigSourceFile{
SourceFile: parsedConfig,
}
parseConfigFileContent := tsoptions.ParseJsonSourceFileConfigFileContent(
tsConfigSourceFile,
p.host,
p.host.GetCurrentDirectory(),
options.Options,
p.configFileName,
/*resolutionStack*/ nil,
/*extraFileExtensions*/ nil,
/*extendedConfigCache*/ nil,
)
p.compilerOptions = parseConfigFileContent.CompilerOptions()
if len(parseConfigFileContent.Errors) > 0 {
p.configFileParsingDiagnostics = append(p.configFileParsingDiagnostics, parseConfigFileContent.Errors...)
return p
}
if rootFiles == nil {
// !!! merge? override? this?
rootFiles = parseConfigFileContent.FileNames()
}
}
p.resolver = module.NewResolver(p.host, p.compilerOptions)
var libs []string
if p.compilerOptions.NoLib != core.TSTrue {
if p.compilerOptions.Lib == nil {
name := tsoptions.GetDefaultLibFileName(p.compilerOptions)
libs = append(libs, tspath.CombinePaths(p.host.DefaultLibraryPath(), name))
} else {
for _, lib := range p.compilerOptions.Lib {
name, ok := tsoptions.GetLibFileName(lib)
if ok {
libs = append(libs, tspath.CombinePaths(p.host.DefaultLibraryPath(), name))
}
// !!! error on unknown name
}
}
}
p.files, p.resolvedModules, p.sourceFileMetaDatas = processAllProgramFiles(p.host, p.programOptions, p.compilerOptions, p.resolver, rootFiles, libs)
p.filesByPath = make(map[tspath.Path]*ast.SourceFile, len(p.files))
for _, file := range p.files {
p.filesByPath[file.Path()] = file
}
for _, file := range p.files {
extension := tspath.TryGetExtensionFromPath(file.FileName())
if extension == tspath.ExtensionTsx || slices.Contains(tspath.SupportedJSExtensionsFlat, extension) {
p.unsupportedExtensions = core.AppendIfUnique(p.unsupportedExtensions, extension)
}
}
return p
}
func NewProgramFromParsedCommandLine(config *tsoptions.ParsedCommandLine, host CompilerHost) *Program {
programOptions := ProgramOptions{
RootFiles: config.FileNames(),
Options: config.CompilerOptions(),
Host: host,
// todo: ProjectReferences
ConfigFileParsingDiagnostics: config.GetConfigFileParsingDiagnostics(),
}
return NewProgram(programOptions)
}
func (p *Program) SourceFiles() []*ast.SourceFile { return p.files }
func (p *Program) Options() *core.CompilerOptions { return p.compilerOptions }
func (p *Program) Host() CompilerHost { return p.host }
func (p *Program) GetConfigFileParsingDiagnostics() []*ast.Diagnostic {
return slices.Clip(p.configFileParsingDiagnostics)
}
func (p *Program) BindSourceFiles() {
wg := core.NewWorkGroup(p.programOptions.SingleThreaded)
for _, file := range p.files {
if !file.IsBound() {
wg.Queue(func() {
binder.BindSourceFile(file, p.compilerOptions)
})
}
}
wg.RunAndWait()
}
func (p *Program) CheckSourceFiles() {
p.createCheckers()
wg := core.NewWorkGroup(p.programOptions.SingleThreaded)
for index, checker := range p.checkers {
wg.Queue(func() {
for i := index; i < len(p.files); i += len(p.checkers) {
checker.CheckSourceFile(p.files[i])
}
})
}
wg.RunAndWait()
}
func (p *Program) createCheckers() {
p.checkersOnce.Do(func() {
p.checkers = make([]*checker.Checker, core.IfElse(p.programOptions.SingleThreaded, 1, 4))
for i := range p.checkers {
p.checkers[i] = checker.NewChecker(p)
}
p.checkersByFile = make(map[*ast.SourceFile]*checker.Checker)
for i, file := range p.files {
p.checkersByFile[file] = p.checkers[i%len(p.checkers)]
}
})
}
// Return the type checker associated with the program.
func (p *Program) GetTypeChecker() *checker.Checker {
p.createCheckers()
// Just use the first (and possibly only) checker for checker requests. Such requests are likely
// to obtain types through multiple API calls and we want to ensure that those types are created
// by the same checker so they can interoperate.
return p.checkers[0]
}
// 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 (p *Program) GetTypeCheckerForFile(file *ast.SourceFile) *checker.Checker {
p.createCheckers()
return p.checkersByFile[file]
}
func (p *Program) GetResolvedModule(file *ast.SourceFile, moduleReference string) *ast.SourceFile {
if resolutions, ok := p.resolvedModules[file.Path()]; ok {
if resolved, ok := resolutions[module.ModeAwareCacheKey{Name: moduleReference, Mode: core.ModuleKindCommonJS}]; ok {
return p.findSourceFile(resolved.ResolvedFileName, FileIncludeReason{FileIncludeKindImport, 0})
}
}
return nil
}
func (p *Program) findSourceFile(candidate string, reason FileIncludeReason) *ast.SourceFile {
path := tspath.ToPath(candidate, p.host.GetCurrentDirectory(), p.host.FS().UseCaseSensitiveFileNames())
return p.filesByPath[path]
}
func getModuleNames(file *ast.SourceFile) []*ast.Node {
res := slices.Clone(file.Imports)
for _, imp := range file.ModuleAugmentations {
if imp.Kind == ast.KindStringLiteral {
res = append(res, imp)
}
// Do nothing if it's an Identifier; we don't need to do module resolution for `declare global`.
}
return res
}
func (p *Program) GetSyntacticDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
return p.getDiagnosticsHelper(sourceFile, false /*ensureBound*/, false /*ensureChecked*/, p.getSyntacticDiagnosticsForFile)
}
func (p *Program) GetBindDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
return p.getDiagnosticsHelper(sourceFile, true /*ensureBound*/, false /*ensureChecked*/, p.getBindDiagnosticsForFile)
}
func (p *Program) GetSemanticDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
return p.getDiagnosticsHelper(sourceFile, true /*ensureBound*/, true /*ensureChecked*/, p.getSemanticDiagnosticsForFile)
}
func (p *Program) GetGlobalDiagnostics() []*ast.Diagnostic {
p.createCheckers()
var globalDiagnostics []*ast.Diagnostic
for _, checker := range p.checkers {
globalDiagnostics = append(globalDiagnostics, checker.GetGlobalDiagnostics()...)
}
return SortAndDeduplicateDiagnostics(globalDiagnostics)
}
func (p *Program) GetOptionsDiagnostics() []*ast.Diagnostic {
return SortAndDeduplicateDiagnostics(append(p.GetGlobalDiagnostics(), p.getOptionsDiagnosticsOfConfigFile()...))
}
func (p *Program) getOptionsDiagnosticsOfConfigFile() []*ast.Diagnostic {
// todo update p.configParsingDiagnostics when updateAndGetProgramDiagnostics is implemented
if p.Options() == nil || p.Options().ConfigFilePath == "" {
return nil
}
return p.configFileParsingDiagnostics // TODO: actually call getDiagnosticsHelper on config path
}
func (p *Program) getSyntacticDiagnosticsForFile(sourceFile *ast.SourceFile) []*ast.Diagnostic {
return sourceFile.Diagnostics()
}
func (p *Program) getBindDiagnosticsForFile(sourceFile *ast.SourceFile) []*ast.Diagnostic {
return sourceFile.BindDiagnostics()
}
func (p *Program) getSemanticDiagnosticsForFile(sourceFile *ast.SourceFile) []*ast.Diagnostic {
var fileChecker *checker.Checker
if sourceFile != nil {
fileChecker = p.GetTypeCheckerForFile(sourceFile)
}
diags := slices.Clip(sourceFile.BindDiagnostics())
// Ask for diags from all checkers; checking one file may add diagnostics to other files.
// These are deduplicated later.
for _, checker := range p.checkers {
if sourceFile == nil || checker == fileChecker {
diags = append(diags, checker.GetDiagnostics(sourceFile)...)
} else {
diags = append(diags, checker.GetDiagnosticsWithoutCheck(sourceFile)...)
}
}
if len(sourceFile.CommentDirectives) == 0 {
return diags
}
// Build map of directives by line number
directivesByLine := make(map[int]ast.CommentDirective)
for _, directive := range sourceFile.CommentDirectives {
line, _ := scanner.GetLineAndCharacterOfPosition(sourceFile, directive.Loc.Pos())
directivesByLine[line] = directive
}
lineStarts := scanner.GetLineStarts(sourceFile)
filtered := make([]*ast.Diagnostic, 0, len(diags))
for _, diagnostic := range diags {
ignoreDiagnostic := false
for line := scanner.ComputeLineOfPosition(lineStarts, diagnostic.Pos()) - 1; line >= 0; line-- {
// If line contains a @ts-ignore or @ts-expect-error directive, ignore this diagnostic and change
// the directive kind to @ts-ignore to indicate it was used.
if directive, ok := directivesByLine[line]; ok {
ignoreDiagnostic = true
directive.Kind = ast.CommentDirectiveKindIgnore
directivesByLine[line] = directive
break
}
// Stop searching backwards when we encounter a line that isn't blank or a comment.
if !isCommentOrBlankLine(sourceFile.Text, int(lineStarts[line])) {
break
}
}
if !ignoreDiagnostic {
filtered = append(filtered, diagnostic)
}
}
for _, directive := range directivesByLine {
// Above we changed all used directive kinds to @ts-ignore, so any @ts-expect-error directives that
// remain are unused and thus errors.
if directive.Kind == ast.CommentDirectiveKindExpectError {
filtered = append(filtered, ast.NewDiagnostic(sourceFile, directive.Loc, diagnostics.Unused_ts_expect_error_directive))
}
}
return filtered
}
func isCommentOrBlankLine(text string, pos int) bool {
for pos < len(text) && (text[pos] == ' ' || text[pos] == '\t') {
pos++
}
return pos == len(text) ||
pos < len(text) && (text[pos] == '\r' || text[pos] == '\n') ||
pos+1 < len(text) && text[pos] == '/' && text[pos+1] == '/'
}
func SortAndDeduplicateDiagnostics(diagnostics []*ast.Diagnostic) []*ast.Diagnostic {
result := slices.Clone(diagnostics)
slices.SortFunc(result, ast.CompareDiagnostics)
return slices.CompactFunc(result, ast.EqualDiagnostics)
}
func (p *Program) getDiagnosticsHelper(sourceFile *ast.SourceFile, ensureBound bool, ensureChecked bool, getDiagnostics func(*ast.SourceFile) []*ast.Diagnostic) []*ast.Diagnostic {
if sourceFile != nil {
if ensureBound {
binder.BindSourceFile(sourceFile, p.compilerOptions)
}
return SortAndDeduplicateDiagnostics(getDiagnostics(sourceFile))
}
if ensureBound {
p.BindSourceFiles()
}
if ensureChecked {
p.CheckSourceFiles()
}
var result []*ast.Diagnostic
for _, file := range p.files {
result = append(result, getDiagnostics(file)...)
}
return SortAndDeduplicateDiagnostics(result)
}
func (p *Program) TypeCount() int {
var count int
for _, checker := range p.checkers {
count += int(checker.TypeCount)
}
return count
}
func (p *Program) PrintSourceFileWithTypes() {
for _, file := range p.files {
if tspath.GetBaseFileName(file.FileName()) == "main.ts" {
fmt.Print(p.GetTypeChecker().SourceFileWithTypes(file))
}
}
}
func (p *Program) GetSourceFileMetaData(path tspath.Path) *ast.SourceFileMetaData {
return p.sourceFileMetaDatas[path]
}
func (p *Program) GetEmitModuleFormatOfFile(sourceFile *ast.SourceFile) core.ModuleKind {
return p.GetEmitModuleFormatOfFileWorker(sourceFile, p.compilerOptions)
}
func (p *Program) GetEmitModuleFormatOfFileWorker(sourceFile *ast.SourceFile, options *core.CompilerOptions) core.ModuleKind {
return ast.GetEmitModuleFormatOfFileWorker(sourceFile, options, p.GetSourceFileMetaData(sourceFile.Path()))
}
func (p *Program) GetImpliedNodeFormatForEmit(sourceFile *ast.SourceFile) core.ResolutionMode {
return ast.GetImpliedNodeFormatForEmitWorker(sourceFile.FileName(), p.compilerOptions, p.GetSourceFileMetaData(sourceFile.Path()))
}
func (p *Program) CommonSourceDirectory() string {
p.commonSourceDirectoryOnce.Do(func() {
var files []string
host := &emitHost{program: p}
for _, file := range p.files {
if sourceFileMayBeEmitted(file, host, false /*forceDtsEmit*/) {
files = append(files, file.FileName())
}
}
p.commonSourceDirectory = getCommonSourceDirectory(
p.compilerOptions,
files,
p.host.GetCurrentDirectory(),
p.host.FS().UseCaseSensitiveFileNames(),
)
})
return p.commonSourceDirectory
}
func (p *Program) GetCompilerOptions() *core.CompilerOptions {
return p.compilerOptions
}
func computeCommonSourceDirectoryOfFilenames(fileNames []string, currentDirectory string, useCaseSensitiveFileNames bool) string {
var commonPathComponents []string
for _, sourceFile := range fileNames {
// Each file contributes into common source file path
sourcePathComponents := tspath.GetNormalizedPathComponents(sourceFile, currentDirectory)
// The base file name is not part of the common directory path
sourcePathComponents = sourcePathComponents[:len(sourcePathComponents)-1]
if commonPathComponents == nil {
// first file
commonPathComponents = sourcePathComponents
continue
}
n := min(len(commonPathComponents), len(sourcePathComponents))
for i := range n {
if tspath.GetCanonicalFileName(commonPathComponents[i], useCaseSensitiveFileNames) != tspath.GetCanonicalFileName(sourcePathComponents[i], useCaseSensitiveFileNames) {
if i == 0 {
// Failed to find any common path component
return ""
}
// New common path found that is 0 -> i-1
commonPathComponents = commonPathComponents[:i]
break
}
}
// If the sourcePathComponents was shorter than the commonPathComponents, truncate to the sourcePathComponents
if len(sourcePathComponents) < len(commonPathComponents) {
commonPathComponents = commonPathComponents[:len(sourcePathComponents)]
}
}
if len(commonPathComponents) == 0 {
// Can happen when all input files are .d.ts files
return currentDirectory
}
return tspath.GetPathFromPathComponents(commonPathComponents)
}
func getCommonSourceDirectory(options *core.CompilerOptions, files []string, currentDirectory string, useCaseSensitiveFileNames bool) string {
var commonSourceDirectory string
// !!! If a rootDir is specified use it as the commonSourceDirectory
// !!! Project compilations never infer their root from the input source paths
commonSourceDirectory = computeCommonSourceDirectoryOfFilenames(files, currentDirectory, useCaseSensitiveFileNames)
if len(commonSourceDirectory) > 0 {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory = tspath.EnsureTrailingDirectorySeparator(commonSourceDirectory)
}
return commonSourceDirectory
}
type EmitOptions struct {
TargetSourceFile *ast.SourceFile // Single file to emit. If `nil`, emits all files
forceDtsEmit bool
}
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 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
}
func (p *Program) Emit(options EmitOptions) *EmitResult {
// !!! performance measurement
p.BindSourceFiles()
host := &emitHost{program: p}
writerPool := &sync.Pool{
New: func() any {
return printer.NewTextWriter(host.Options().NewLine.GetNewLineCharacter())
},
}
wg := core.NewWorkGroup(p.programOptions.SingleThreaded)
var emitters []*emitter
sourceFiles := getSourceFilesToEmit(host, options.TargetSourceFile, options.forceDtsEmit)
for _, sourceFile := range sourceFiles {
emitter := &emitter{
host: host,
emittedFilesList: nil,
sourceMapDataList: nil,
writer: nil,
sourceFile: sourceFile,
}
emitters = append(emitters, emitter)
wg.Queue(func() {
// take an unused writer
writer := writerPool.Get().(printer.EmitTextWriter)
writer.Clear()
// attach writer and perform emit
emitter.writer = writer
emitter.paths = getOutputPathsFor(sourceFile, host, options.forceDtsEmit)
emitter.emit()
emitter.writer = nil
// put the writer back in the pool
writerPool.Put(writer)
})
}
// wait for emit to complete
wg.RunAndWait()
// collect results from emit, preserving input order
result := &EmitResult{}
for _, emitter := range emitters {
if emitter.emitSkipped {
result.EmitSkipped = true
}
result.Diagnostics = append(result.Diagnostics, emitter.emitterDiagnostics.GetDiagnostics()...)
if emitter.emittedFilesList != nil {
result.EmittedFiles = append(result.EmittedFiles, emitter.emittedFilesList...)
}
if emitter.sourceMapDataList != nil {
result.sourceMaps = append(result.sourceMaps, emitter.sourceMapDataList...)
}
}
return result
}
func (p *Program) GetSourceFile(filename string) *ast.SourceFile {
path := tspath.ToPath(filename, p.host.GetCurrentDirectory(), p.host.FS().UseCaseSensitiveFileNames())
return p.GetSourceFileByPath(path)
}
func (p *Program) GetSourceFileByPath(path tspath.Path) *ast.SourceFile {
return p.filesByPath[path]
}
func (p *Program) GetSourceFiles() []*ast.SourceFile {
return p.files
}
type FileIncludeKind int
const (
FileIncludeKindRootFile FileIncludeKind = iota
FileIncludeKindSourceFromProjectReference
FileIncludeKindOutputFromProjectReference
FileIncludeKindImport
FileIncludeKindReferenceFile
FileIncludeKindTypeReferenceDirective
FileIncludeKindLibFile
FileIncludeKindLibReferenceDirective
FileIncludeKindAutomaticTypeDirectiveFile
)
type FileIncludeReason struct {
Kind FileIncludeKind
Index int
}
// UnsupportedExtensions returns a list of all present "unsupported" extensions,
// e.g. extensions that are not yet supported by the port.
func (p *Program) UnsupportedExtensions() []string {
return p.unsupportedExtensions
}