Skip to content

Commit b52d094

Browse files
committed
more change
1 parent fae0baf commit b52d094

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

internal/incremental/program.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package incremental
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/microsoft/typescript-go/internal/ast"
78
"github.com/microsoft/typescript-go/internal/compiler"
@@ -22,10 +23,14 @@ func NewProgram(program *compiler.Program, oldProgram *Program) *Program {
2223
}
2324
}
2425

25-
func (p *Program) GetProgram() *compiler.Program {
26+
func (p *Program) panicIfNoProgram(method string) {
2627
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))
2829
}
30+
}
31+
32+
func (p *Program) GetProgram() *compiler.Program {
33+
p.panicIfNoProgram("GetProgram")
2934
return p.program
3035
}
3136

@@ -34,37 +39,27 @@ func (p *Program) Options() *core.CompilerOptions {
3439
}
3540

3641
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")
4043
return p.program.GetSourceFiles()
4144
}
4245

4346
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")
4748
return p.program.GetConfigFileParsingDiagnostics()
4849
}
4950

5051
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")
5453
return p.program.GetSyntacticDiagnostics(ctx, file)
5554
}
5655

5756
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")
6158
return p.program.GetBindDiagnostics(ctx, file)
6259
}
6360

6461
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")
6863
return p.program.GetOptionsDiagnostics(ctx)
6964
}
7065

@@ -76,29 +71,21 @@ func (p *Program) GetProgramDiagnostics() []*ast.Diagnostic {
7671
}
7772

7873
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")
8275
return p.program.GetGlobalDiagnostics(ctx)
8376
}
8477

8578
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")
8980
return p.state.getSemanticDiagnostics(ctx, p.program, file)
9081
}
9182

9283
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")
9685
return p.state.getDeclarationDiagnostics(ctx, p.program, file)
9786
}
9887

9988
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")
10390
return p.state.emit(ctx, p.program, options)
10491
}

internal/testutil/incrementaltestutil/readablebuildinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func toReadableBuildInfo(buildInfo *incremental.BuildInfo, buildInfoText string)
191191
readable.setEmitDiagnostics()
192192
readable.setAffectedFilesPendingEmit()
193193
readable.setEmitSignatures()
194-
contents, err := json.MarshalIndent(&readable, "", " ")
194+
contents, err := json.MarshalIndent(&readable, "", " ")
195195
if err != nil {
196196
panic("readableBuildInfo: failed to marshal readable build info: " + err.Error())
197197
}

0 commit comments

Comments
 (0)