|
1 | 1 | package compiler |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "encoding/base64" |
6 | | - "slices" |
7 | | - "time" |
8 | 5 |
|
9 | 6 | "github.com/microsoft/typescript-go/internal/ast" |
10 | 7 | "github.com/microsoft/typescript-go/internal/binder" |
@@ -469,93 +466,3 @@ func getDeclarationDiagnostics(host EmitHost, file *ast.SourceFile) []*ast.Diagn |
469 | 466 | transform.TransformSourceFile(file) |
470 | 467 | return transform.GetDiagnostics() |
471 | 468 | } |
472 | | - |
473 | | -type AnyProgram interface { |
474 | | - Options() *core.CompilerOptions |
475 | | - GetSourceFiles() []*ast.SourceFile |
476 | | - GetConfigFileParsingDiagnostics() []*ast.Diagnostic |
477 | | - GetSyntacticDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic |
478 | | - GetBindDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic |
479 | | - GetOptionsDiagnostics(ctx context.Context) []*ast.Diagnostic |
480 | | - GetProgramDiagnostics() []*ast.Diagnostic |
481 | | - GetGlobalDiagnostics(ctx context.Context) []*ast.Diagnostic |
482 | | - GetSemanticDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic |
483 | | - GetDeclarationDiagnostics(ctx context.Context, file *ast.SourceFile) []*ast.Diagnostic |
484 | | - Emit(ctx context.Context, options EmitOptions) *EmitResult |
485 | | -} |
486 | | - |
487 | | -func HandleNoEmitOnError(ctx context.Context, program AnyProgram, file *ast.SourceFile) *EmitResult { |
488 | | - if !program.Options().NoEmitOnError.IsTrue() { |
489 | | - return nil // No emit on error is not set, so we can proceed with emitting |
490 | | - } |
491 | | - |
492 | | - diagnostics := GetDiagnosticsOfAnyProgram(ctx, program, file, true, func(name string, start bool, nameStart time.Time) time.Time { return time.Time{} }) |
493 | | - if len(diagnostics) == 0 { |
494 | | - return nil // No diagnostics, so we can proceed with emitting |
495 | | - } |
496 | | - return &EmitResult{ |
497 | | - Diagnostics: diagnostics, |
498 | | - EmitSkipped: true, |
499 | | - } |
500 | | -} |
501 | | - |
502 | | -func GetDiagnosticsOfAnyProgram( |
503 | | - ctx context.Context, |
504 | | - program AnyProgram, |
505 | | - file *ast.SourceFile, |
506 | | - skipNoEmitCheckForDtsDiagnostics bool, |
507 | | - recordTime func(name string, start bool, nameStart time.Time) time.Time, |
508 | | -) []*ast.Diagnostic { |
509 | | - allDiagnostics := slices.Clip(program.GetConfigFileParsingDiagnostics()) |
510 | | - configFileParsingDiagnosticsLength := len(allDiagnostics) |
511 | | - |
512 | | - allDiagnostics = append(allDiagnostics, program.GetSyntacticDiagnostics(ctx, file)...) |
513 | | - allDiagnostics = append(allDiagnostics, program.GetProgramDiagnostics()...) |
514 | | - |
515 | | - if len(allDiagnostics) == configFileParsingDiagnosticsLength { |
516 | | - // Options diagnostics include global diagnostics (even though we collect them separately), |
517 | | - // and global diagnostics create checkers, which then bind all of the files. Do this binding |
518 | | - // early so we can track the time. |
519 | | - bindStart := recordTime("bind", true, time.Time{}) |
520 | | - _ = program.GetBindDiagnostics(ctx, file) |
521 | | - recordTime("bind", false, bindStart) |
522 | | - |
523 | | - allDiagnostics = append(allDiagnostics, program.GetOptionsDiagnostics(ctx)...) |
524 | | - |
525 | | - if program.Options().ListFilesOnly.IsFalseOrUnknown() { |
526 | | - allDiagnostics = append(allDiagnostics, program.GetGlobalDiagnostics(ctx)...) |
527 | | - |
528 | | - if len(allDiagnostics) == configFileParsingDiagnosticsLength { |
529 | | - // !!! add program diagnostics here instead of merging with the semantic diagnostics for better api usage with with incremental and |
530 | | - checkStart := recordTime("check", true, time.Time{}) |
531 | | - allDiagnostics = append(allDiagnostics, program.GetSemanticDiagnostics(ctx, file)...) |
532 | | - recordTime("check", false, checkStart) |
533 | | - } |
534 | | - |
535 | | - if (skipNoEmitCheckForDtsDiagnostics || program.Options().NoEmit.IsTrue()) && program.Options().GetEmitDeclarations() && len(allDiagnostics) == configFileParsingDiagnosticsLength { |
536 | | - allDiagnostics = append(allDiagnostics, program.GetDeclarationDiagnostics(ctx, file)...) |
537 | | - } |
538 | | - } |
539 | | - } |
540 | | - return allDiagnostics |
541 | | -} |
542 | | - |
543 | | -func CombineEmitResults(results []*EmitResult) *EmitResult { |
544 | | - result := &EmitResult{} |
545 | | - for _, emitResult := range results { |
546 | | - if emitResult == nil { |
547 | | - continue // Skip nil results |
548 | | - } |
549 | | - if emitResult.EmitSkipped { |
550 | | - result.EmitSkipped = true |
551 | | - } |
552 | | - result.Diagnostics = append(result.Diagnostics, emitResult.Diagnostics...) |
553 | | - if emitResult.EmittedFiles != nil { |
554 | | - result.EmittedFiles = append(result.EmittedFiles, emitResult.EmittedFiles...) |
555 | | - } |
556 | | - if emitResult.SourceMaps != nil { |
557 | | - result.SourceMaps = append(result.SourceMaps, emitResult.SourceMaps...) |
558 | | - } |
559 | | - } |
560 | | - return result |
561 | | -} |
0 commit comments