@@ -2,6 +2,7 @@ package incremental
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
6
7
"github.com/microsoft/typescript-go/internal/ast"
7
8
"github.com/microsoft/typescript-go/internal/compiler"
@@ -22,10 +23,14 @@ func NewProgram(program *compiler.Program, oldProgram *Program) *Program {
22
23
}
23
24
}
24
25
25
- func (p * Program ) GetProgram () * compiler. Program {
26
+ func (p * Program ) panicIfNoProgram ( method string ) {
26
27
if p .program == nil {
27
- panic ("GetProgram should not be called without program" )
28
+ panic (fmt . Sprintf ( "%s should not be called without program", method ) )
28
29
}
30
+ }
31
+
32
+ func (p * Program ) GetProgram () * compiler.Program {
33
+ p .panicIfNoProgram ("GetProgram" )
29
34
return p .program
30
35
}
31
36
@@ -34,37 +39,27 @@ func (p *Program) Options() *core.CompilerOptions {
34
39
}
35
40
36
41
func (p * Program ) GetSourceFiles () []* ast.SourceFile {
37
- if p .program == nil {
38
- panic ("GetSourceFiles should not be called without program" )
39
- }
42
+ p .panicIfNoProgram ("GetSourceFiles" )
40
43
return p .program .GetSourceFiles ()
41
44
}
42
45
43
46
func (p * Program ) GetConfigFileParsingDiagnostics () []* ast.Diagnostic {
44
- if p .program == nil {
45
- panic ("GetConfigFileParsingDiagnostics should not be called without program" )
46
- }
47
+ p .panicIfNoProgram ("GetConfigFileParsingDiagnostics" )
47
48
return p .program .GetConfigFileParsingDiagnostics ()
48
49
}
49
50
50
51
func (p * Program ) GetSyntacticDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic {
51
- if p .program == nil {
52
- panic ("GetSyntacticDiagnostics should not be called without program" )
53
- }
52
+ p .panicIfNoProgram ("GetSyntacticDiagnostics" )
54
53
return p .program .GetSyntacticDiagnostics (ctx , file )
55
54
}
56
55
57
56
func (p * Program ) GetBindDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic {
58
- if p .program == nil {
59
- panic ("GetBindDiagnostics should not be called without program" )
60
- }
57
+ p .panicIfNoProgram ("GetBindDiagnostics" )
61
58
return p .program .GetBindDiagnostics (ctx , file )
62
59
}
63
60
64
61
func (p * Program ) GetOptionsDiagnostics (ctx context.Context ) []* ast.Diagnostic {
65
- if p .program == nil {
66
- panic ("GetOptionsDiagnostics should not be called without program" )
67
- }
62
+ p .panicIfNoProgram ("GetOptionsDiagnostics" )
68
63
return p .program .GetOptionsDiagnostics (ctx )
69
64
}
70
65
@@ -76,29 +71,21 @@ func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic {
76
71
}
77
72
78
73
func (p * Program ) GetGlobalDiagnostics (ctx context.Context ) []* ast.Diagnostic {
79
- if p .program == nil {
80
- panic ("GetGlobalDiagnostics should not be called without program" )
81
- }
74
+ p .panicIfNoProgram ("GetGlobalDiagnostics" )
82
75
return p .program .GetGlobalDiagnostics (ctx )
83
76
}
84
77
85
78
func (p * Program ) GetSemanticDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic {
86
- if p .program == nil {
87
- panic ("GetSemanticDiagnostics should not be called without program" )
88
- }
79
+ p .panicIfNoProgram ("GetSemanticDiagnostics" )
89
80
return p .state .getSemanticDiagnostics (ctx , p .program , file )
90
81
}
91
82
92
83
func (p * Program ) GetDeclarationDiagnostics (ctx context.Context , file * ast.SourceFile ) []* ast.Diagnostic {
93
- if p .program == nil {
94
- panic ("GetDeclarationDiagnostics should not be called without program" )
95
- }
84
+ p .panicIfNoProgram ("GetDeclarationDiagnostics" )
96
85
return p .state .getDeclarationDiagnostics (ctx , p .program , file )
97
86
}
98
87
99
88
func (p * Program ) Emit (ctx context.Context , options compiler.EmitOptions ) * compiler.EmitResult {
100
- if p .program == nil {
101
- panic ("Emit should not be called without program" )
102
- }
89
+ p .panicIfNoProgram ("Emit" )
103
90
return p .state .emit (ctx , p .program , options )
104
91
}
0 commit comments