ttsc 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +5 -6
  2. package/cmd/platform/main.go +86 -76
  3. package/cmd/ttsc/api_compile.go +122 -105
  4. package/cmd/ttsc/api_transform.go +57 -49
  5. package/cmd/ttsc/build.go +116 -103
  6. package/cmd/ttsc/main.go +117 -117
  7. package/cmd/ttsc/main_test.go +191 -191
  8. package/driver/host.go +9 -9
  9. package/driver/program.go +285 -285
  10. package/driver/rewrite.go +225 -219
  11. package/lib/compiler/internal/compileProjectInMemory.js +3 -3
  12. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  13. package/lib/compiler/internal/resolveEmittedJavaScript.js +2 -1
  14. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
  15. package/lib/compiler/internal/resolveTsgo.js.map +1 -1
  16. package/lib/compiler/internal/runBuild.js.map +1 -1
  17. package/lib/launcher/internal/getCompilerVersionText.js +1 -2
  18. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
  19. package/lib/launcher/internal/prepareExecution.js +92 -9
  20. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  21. package/lib/launcher/internal/runTtsc.js +30 -4
  22. package/lib/launcher/internal/runTtsc.js.map +1 -1
  23. package/lib/launcher/internal/runTtsx.js +7 -2
  24. package/lib/launcher/internal/runTtsx.js.map +1 -1
  25. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  26. package/package.json +9 -9
  27. package/shim/ast/lint.go +171 -171
  28. package/shim/ast/shim.go +83 -83
  29. package/shim/bundled/shim.go +5 -1
  30. package/shim/checker/shim.go +79 -79
  31. package/shim/compiler/shim.go +16 -1
  32. package/shim/core/shim.go +10 -10
  33. package/shim/diagnosticwriter/lint.go +79 -79
  34. package/shim/diagnosticwriter/shim.go +19 -19
  35. package/shim/parser/shim.go +7 -1
  36. package/shim/scanner/shim.go +39 -1
  37. package/shim/tsoptions/shim.go +51 -1
  38. package/shim/tspath/shim.go +72 -1
  39. package/shim/vfs/cachedvfs/shim.go +1 -1
  40. package/shim/vfs/osvfs/shim.go +1 -1
  41. package/shim/vfs/shim.go +4 -1
  42. package/src/compiler/internal/compileProjectInMemory.ts +6 -3
  43. package/src/compiler/internal/resolveEmittedJavaScript.ts +2 -1
  44. package/src/compiler/internal/resolveTsgo.ts +0 -1
  45. package/src/compiler/internal/runBuild.ts +4 -1
  46. package/src/launcher/internal/getCompilerVersionText.ts +1 -2
  47. package/src/launcher/internal/prepareExecution.ts +115 -9
  48. package/src/launcher/internal/runTtsc.ts +35 -4
  49. package/src/launcher/internal/runTtsx.ts +16 -5
  50. package/src/plugin/internal/buildSourcePlugin.ts +7 -2
  51. package/test/platform.test.ts +1 -3
  52. package/test/tsgo.test.ts +6 -1
  53. package/tools/gen_shims/main.go +409 -409
package/driver/program.go CHANGED
@@ -1,21 +1,21 @@
1
1
  package driver
2
2
 
3
3
  import (
4
- "context"
5
- "errors"
6
- "fmt"
7
- "io"
8
- "path/filepath"
4
+ "context"
5
+ "errors"
6
+ "fmt"
7
+ "io"
8
+ "path/filepath"
9
9
 
10
- "github.com/microsoft/typescript-go/shim/ast"
11
- shimchecker "github.com/microsoft/typescript-go/shim/checker"
12
- shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
13
- "github.com/microsoft/typescript-go/shim/core"
14
- shimdiagnosticwriter "github.com/microsoft/typescript-go/shim/diagnosticwriter"
15
- shimscanner "github.com/microsoft/typescript-go/shim/scanner"
16
- "github.com/microsoft/typescript-go/shim/tsoptions"
17
- "github.com/microsoft/typescript-go/shim/tspath"
18
- "github.com/microsoft/typescript-go/shim/vfs"
10
+ "github.com/microsoft/typescript-go/shim/ast"
11
+ shimchecker "github.com/microsoft/typescript-go/shim/checker"
12
+ shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
13
+ "github.com/microsoft/typescript-go/shim/core"
14
+ shimdiagnosticwriter "github.com/microsoft/typescript-go/shim/diagnosticwriter"
15
+ shimscanner "github.com/microsoft/typescript-go/shim/scanner"
16
+ "github.com/microsoft/typescript-go/shim/tsoptions"
17
+ "github.com/microsoft/typescript-go/shim/tspath"
18
+ "github.com/microsoft/typescript-go/shim/vfs"
19
19
  )
20
20
 
21
21
  // Diagnostic is the compilation diagnostic shape ttsc passes around. Kept
@@ -27,16 +27,16 @@ import (
27
27
  // `@ttsc/lint`). At most one of `raw` / `lint` is non-nil; both nil falls
28
28
  // back to the legacy single-line form.
29
29
  type Diagnostic struct {
30
- File string
31
- Line int
32
- Column int
33
- Code int32
34
- Start *int
35
- Length *int
36
- Message string
37
- Severity Severity
38
- raw *ast.Diagnostic
39
- lint *shimdiagnosticwriter.LintDiagnostic
30
+ File string
31
+ Line int
32
+ Column int
33
+ Code int32
34
+ Start *int
35
+ Length *int
36
+ Message string
37
+ Severity Severity
38
+ raw *ast.Diagnostic
39
+ lint *shimdiagnosticwriter.LintDiagnostic
40
40
  }
41
41
 
42
42
  // Severity classifies a diagnostic's blast radius. ttsc treats Error as a
@@ -44,12 +44,12 @@ type Diagnostic struct {
44
44
  type Severity int
45
45
 
46
46
  const (
47
- // SeverityError is the default for tsgo typecheck output and any
48
- // plugin-emitted finding that should fail the build.
49
- SeverityError Severity = iota
50
- // SeverityWarning prints with warning coloring but keeps the build
51
- // status at zero.
52
- SeverityWarning
47
+ // SeverityError is the default for tsgo typecheck output and any
48
+ // plugin-emitted finding that should fail the build.
49
+ SeverityError Severity = iota
50
+ // SeverityWarning prints with warning coloring but keeps the build
51
+ // status at zero.
52
+ SeverityWarning
53
53
  )
54
54
 
55
55
  // IsError reports whether the diagnostic counts toward the build's error
@@ -63,60 +63,60 @@ func (d Diagnostic) IsError() bool { return d.Severity == SeverityError }
63
63
  // rule's enum index). Severity controls both the rendered banner color and
64
64
  // the exit-code outcome.
65
65
  func NewLintDiagnostic(
66
- file *ast.SourceFile,
67
- pos, end int,
68
- code int32,
69
- severity Severity,
70
- message string,
66
+ file *ast.SourceFile,
67
+ pos, end int,
68
+ code int32,
69
+ severity Severity,
70
+ message string,
71
71
  ) Diagnostic {
72
- cat := shimdiagnosticwriter.LintCategoryError
73
- if severity == SeverityWarning {
74
- cat = shimdiagnosticwriter.LintCategoryWarning
75
- }
76
- lint := shimdiagnosticwriter.NewLintDiagnostic(file, pos, end, code, cat, message)
77
- d := Diagnostic{
78
- Code: code,
79
- Message: message,
80
- Severity: severity,
81
- lint: lint,
82
- }
83
- if file != nil {
84
- d.File = file.FileName()
85
- if pos >= 0 {
86
- length := end - pos
87
- d.Start = &pos
88
- d.Length = &length
89
- line, col := shimscanner.GetECMALineAndByteOffsetOfPosition(file, pos)
90
- d.Line = line + 1
91
- d.Column = col + 1
92
- }
93
- }
94
- return d
72
+ cat := shimdiagnosticwriter.LintCategoryError
73
+ if severity == SeverityWarning {
74
+ cat = shimdiagnosticwriter.LintCategoryWarning
75
+ }
76
+ lint := shimdiagnosticwriter.NewLintDiagnostic(file, pos, end, code, cat, message)
77
+ d := Diagnostic{
78
+ Code: code,
79
+ Message: message,
80
+ Severity: severity,
81
+ lint: lint,
82
+ }
83
+ if file != nil {
84
+ d.File = file.FileName()
85
+ if pos >= 0 {
86
+ length := end - pos
87
+ d.Start = &pos
88
+ d.Length = &length
89
+ line, col := shimscanner.GetECMALineAndByteOffsetOfPosition(file, pos)
90
+ d.Line = line + 1
91
+ d.Column = col + 1
92
+ }
93
+ }
94
+ return d
95
95
  }
96
96
 
97
97
  // SourceFile returns the program source file matching filename.
98
98
  func (p *Program) SourceFile(filename string) *ast.SourceFile {
99
- if p == nil || p.TSProgram == nil {
100
- return nil
101
- }
102
- normalized := filepath.ToSlash(filename)
103
- for _, file := range p.TSProgram.SourceFiles() {
104
- if filepath.ToSlash(file.FileName()) == normalized {
105
- return file
106
- }
107
- }
108
- return nil
99
+ if p == nil || p.TSProgram == nil {
100
+ return nil
101
+ }
102
+ normalized := filepath.ToSlash(filename)
103
+ for _, file := range p.TSProgram.SourceFiles() {
104
+ if filepath.ToSlash(file.FileName()) == normalized {
105
+ return file
106
+ }
107
+ }
108
+ return nil
109
109
  }
110
110
 
111
111
  // String returns a `path:line:col: message` formatted string.
112
112
  func (d Diagnostic) String() string {
113
- if d.File == "" {
114
- return d.Message
115
- }
116
- if d.Line > 0 {
117
- return fmt.Sprintf("%s:%d:%d: %s", d.File, d.Line, d.Column, d.Message)
118
- }
119
- return fmt.Sprintf("%s: %s", d.File, d.Message)
113
+ if d.File == "" {
114
+ return d.Message
115
+ }
116
+ if d.Line > 0 {
117
+ return fmt.Sprintf("%s:%d:%d: %s", d.File, d.Line, d.Column, d.Message)
118
+ }
119
+ return fmt.Sprintf("%s: %s", d.File, d.Message)
120
120
  }
121
121
 
122
122
  // WritePrettyDiagnostics renders diagnostics with TypeScript-style colors,
@@ -125,90 +125,90 @@ func (d Diagnostic) String() string {
125
125
  // are rendered through the same color/context pipeline; entries without
126
126
  // either anchor fall back to the legacy `path:line:col: message` form.
127
127
  func WritePrettyDiagnostics(w io.Writer, diagnostics []Diagnostic, cwd string) {
128
- if len(diagnostics) == 0 {
129
- return
130
- }
131
- rich := make([]Diagnostic, 0, len(diagnostics))
132
- plain := make([]Diagnostic, 0)
133
- for _, d := range diagnostics {
134
- if d.raw != nil || d.lint != nil {
135
- rich = append(rich, d)
136
- } else {
137
- plain = append(plain, d)
138
- }
139
- }
140
- if len(rich) > 0 {
141
- astDiags := make([]*ast.Diagnostic, 0, len(rich))
142
- lintDiags := make([]*shimdiagnosticwriter.LintDiagnostic, 0, len(rich))
143
- for _, d := range rich {
144
- if d.raw != nil {
145
- astDiags = append(astDiags, d.raw)
146
- }
147
- if d.lint != nil {
148
- lintDiags = append(lintDiags, d.lint)
149
- }
150
- }
151
- shimdiagnosticwriter.FormatMixedDiagnostics(w, astDiags, lintDiags, cwd)
152
- }
153
- for _, d := range plain {
154
- fmt.Fprintln(w, " -", d.String())
155
- }
128
+ if len(diagnostics) == 0 {
129
+ return
130
+ }
131
+ rich := make([]Diagnostic, 0, len(diagnostics))
132
+ plain := make([]Diagnostic, 0)
133
+ for _, d := range diagnostics {
134
+ if d.raw != nil || d.lint != nil {
135
+ rich = append(rich, d)
136
+ } else {
137
+ plain = append(plain, d)
138
+ }
139
+ }
140
+ if len(rich) > 0 {
141
+ astDiags := make([]*ast.Diagnostic, 0, len(rich))
142
+ lintDiags := make([]*shimdiagnosticwriter.LintDiagnostic, 0, len(rich))
143
+ for _, d := range rich {
144
+ if d.raw != nil {
145
+ astDiags = append(astDiags, d.raw)
146
+ }
147
+ if d.lint != nil {
148
+ lintDiags = append(lintDiags, d.lint)
149
+ }
150
+ }
151
+ shimdiagnosticwriter.FormatMixedDiagnostics(w, astDiags, lintDiags, cwd)
152
+ }
153
+ for _, d := range plain {
154
+ fmt.Fprintln(w, " -", d.String())
155
+ }
156
156
  }
157
157
 
158
158
  // CountErrors returns the number of diagnostics that should fail the build.
159
159
  // tsgo diagnostics carry their own `Error` category; lint diagnostics carry a
160
160
  // caller-set Severity. Anything that isn't an explicit warning counts.
161
161
  func CountErrors(diagnostics []Diagnostic) int {
162
- n := 0
163
- for _, d := range diagnostics {
164
- if d.lint != nil {
165
- if d.lint.IsError() {
166
- n++
167
- }
168
- continue
169
- }
170
- if d.raw != nil {
171
- // tsgo diagnostics use the diagnostics package category. The
172
- // renderer shim already mirrors the same Error/Warning split, so
173
- // re-categorize via the public IsError shortcut.
174
- if d.Severity != SeverityWarning {
175
- n++
176
- }
177
- continue
178
- }
179
- // Plain text diagnostics (manually assembled): treat as errors so
180
- // "ttsc: tsconfig not found"-style failures still flip the exit code.
181
- n++
182
- }
183
- return n
162
+ n := 0
163
+ for _, d := range diagnostics {
164
+ if d.lint != nil {
165
+ if d.lint.IsError() {
166
+ n++
167
+ }
168
+ continue
169
+ }
170
+ if d.raw != nil {
171
+ // tsgo diagnostics use the diagnostics package category. The
172
+ // renderer shim already mirrors the same Error/Warning split, so
173
+ // re-categorize via the public IsError shortcut.
174
+ if d.Severity != SeverityWarning {
175
+ n++
176
+ }
177
+ continue
178
+ }
179
+ // Plain text diagnostics (manually assembled): treat as errors so
180
+ // "ttsc: tsconfig not found"-style failures still flip the exit code.
181
+ n++
182
+ }
183
+ return n
184
184
  }
185
185
 
186
186
  // Program is the shim-agnostic facade the rest of the engine sees.
187
187
  type Program struct {
188
- TSProgram *shimcompiler.Program
189
- ParsedConfig *tsoptions.ParsedCommandLine
190
- Checker *shimchecker.Checker
191
- checkerRelease func()
192
- Host shimcompiler.CompilerHost
193
- FS vfs.FS
188
+ TSProgram *shimcompiler.Program
189
+ ParsedConfig *tsoptions.ParsedCommandLine
190
+ Checker *shimchecker.Checker
191
+ checkerRelease func()
192
+ Host shimcompiler.CompilerHost
193
+ FS vfs.FS
194
194
  }
195
195
 
196
196
  // LoadProgramOptions controls tsconfig overrides applied before tsgo creates
197
197
  // the program. `ForceEmit` is used by `ttsc --emit` and runtime compilation
198
198
  // so execution still works when the project defaults to `noEmit`.
199
199
  type LoadProgramOptions struct {
200
- ForceEmit bool
201
- ForceNoEmit bool
202
- OutDir string
200
+ ForceEmit bool
201
+ ForceNoEmit bool
202
+ OutDir string
203
203
  }
204
204
 
205
205
  // Close releases the checker pool lease acquired by LoadProgram.
206
206
  func (p *Program) Close() error {
207
- if p.checkerRelease != nil {
208
- p.checkerRelease()
209
- p.checkerRelease = nil
210
- }
211
- return nil
207
+ if p.checkerRelease != nil {
208
+ p.checkerRelease()
209
+ p.checkerRelease = nil
210
+ }
211
+ return nil
212
212
  }
213
213
 
214
214
  // ParseTSConfig parses a tsconfig.json file via tsgo's native JSONC parser.
@@ -218,36 +218,36 @@ func (p *Program) Close() error {
218
218
  // tsgo's filesystem APIs require absolute paths — mirrors what tsc does when
219
219
  // you pass a relative `--project` flag.
220
220
  func ParseTSConfig(fs vfs.FS, cwd, tsconfigPath string, host shimcompiler.CompilerHost) (*tsoptions.ParsedCommandLine, []Diagnostic, error) {
221
- resolved := tspath.ResolvePath(cwd, tsconfigPath)
222
- if !fs.FileExists(resolved) {
223
- return nil, nil, fmt.Errorf("tsconfig not found: %s", resolved)
224
- }
225
- parsed, diags := tsoptions.GetParsedCommandLineOfConfigFile(resolved, &core.CompilerOptions{}, nil, host, nil)
226
- if len(diags) > 0 {
227
- return nil, convertDiagnostics(diags), nil
228
- }
229
- if parsed == nil {
230
- return nil, nil, errors.New("tsoptions: parsed command line was nil")
231
- }
232
- if len(parsed.Errors) > 0 {
233
- return nil, convertDiagnostics(parsed.Errors), nil
234
- }
235
- return parsed, nil, nil
221
+ resolved := tspath.ResolvePath(cwd, tsconfigPath)
222
+ if !fs.FileExists(resolved) {
223
+ return nil, nil, fmt.Errorf("tsconfig not found: %s", resolved)
224
+ }
225
+ parsed, diags := tsoptions.GetParsedCommandLineOfConfigFile(resolved, &core.CompilerOptions{}, nil, host, nil)
226
+ if len(diags) > 0 {
227
+ return nil, convertDiagnostics(diags), nil
228
+ }
229
+ if parsed == nil {
230
+ return nil, nil, errors.New("tsoptions: parsed command line was nil")
231
+ }
232
+ if len(parsed.Errors) > 0 {
233
+ return nil, convertDiagnostics(parsed.Errors), nil
234
+ }
235
+ return parsed, nil, nil
236
236
  }
237
237
 
238
238
  // CreateProgramFromConfig builds a tsgo Program from the parsed config.
239
239
  func CreateProgramFromConfig(parsed *tsoptions.ParsedCommandLine, host shimcompiler.CompilerHost) (*shimcompiler.Program, []Diagnostic, error) {
240
- opts := shimcompiler.ProgramOptions{
241
- Config: parsed,
242
- SingleThreaded: core.TSTrue,
243
- Host: host,
244
- UseSourceOfProjectReference: true,
245
- }
246
- p := shimcompiler.NewProgram(opts)
247
- if p == nil {
248
- return nil, nil, errors.New("shimcompiler.NewProgram returned nil")
249
- }
250
- return p, nil, nil
240
+ opts := shimcompiler.ProgramOptions{
241
+ Config: parsed,
242
+ SingleThreaded: core.TSTrue,
243
+ Host: host,
244
+ UseSourceOfProjectReference: true,
245
+ }
246
+ p := shimcompiler.NewProgram(opts)
247
+ if p == nil {
248
+ return nil, nil, errors.New("shimcompiler.NewProgram returned nil")
249
+ }
250
+ return p, nil, nil
251
251
  }
252
252
 
253
253
  // LoadProgram is the one-shot convenience used by `ttsc`.
@@ -256,158 +256,158 @@ func CreateProgramFromConfig(parsed *tsoptions.ParsedCommandLine, host shimcompi
256
256
  //
257
257
  // cwd must be absolute; tsconfigPath may be relative to cwd.
258
258
  func LoadProgram(cwd, tsconfigPath string, options LoadProgramOptions) (*Program, []Diagnostic, error) {
259
- if !filepath.IsAbs(cwd) {
260
- if abs, err := filepath.Abs(cwd); err == nil {
261
- cwd = abs
262
- }
263
- }
264
- cwd = tspath.ResolvePath(cwd)
265
- fs := DefaultFS()
266
- host := DefaultHost(cwd, fs)
259
+ if !filepath.IsAbs(cwd) {
260
+ if abs, err := filepath.Abs(cwd); err == nil {
261
+ cwd = abs
262
+ }
263
+ }
264
+ cwd = tspath.ResolvePath(cwd)
265
+ fs := DefaultFS()
266
+ host := DefaultHost(cwd, fs)
267
267
 
268
- parsed, diags, err := ParseTSConfig(fs, cwd, tsconfigPath, host)
269
- if err != nil {
270
- return nil, nil, err
271
- }
272
- if len(diags) > 0 {
273
- return nil, diags, nil
274
- }
275
- if options.ForceNoEmit {
276
- forceNoEmit(parsed)
277
- }
278
- if options.ForceEmit {
279
- forceEmit(parsed)
280
- }
281
- if options.OutDir != "" {
282
- overrideOutDir(cwd, parsed, options.OutDir)
283
- }
268
+ parsed, diags, err := ParseTSConfig(fs, cwd, tsconfigPath, host)
269
+ if err != nil {
270
+ return nil, nil, err
271
+ }
272
+ if len(diags) > 0 {
273
+ return nil, diags, nil
274
+ }
275
+ if options.ForceNoEmit {
276
+ forceNoEmit(parsed)
277
+ }
278
+ if options.ForceEmit {
279
+ forceEmit(parsed)
280
+ }
281
+ if options.OutDir != "" {
282
+ overrideOutDir(cwd, parsed, options.OutDir)
283
+ }
284
284
 
285
- tsProgram, progDiags, err := CreateProgramFromConfig(parsed, host)
286
- if err != nil {
287
- return nil, nil, err
288
- }
289
- if len(progDiags) > 0 {
290
- return nil, progDiags, nil
291
- }
285
+ tsProgram, progDiags, err := CreateProgramFromConfig(parsed, host)
286
+ if err != nil {
287
+ return nil, nil, err
288
+ }
289
+ if len(progDiags) > 0 {
290
+ return nil, progDiags, nil
291
+ }
292
292
 
293
- checker, done := tsProgram.GetTypeChecker(context.Background())
294
- return &Program{
295
- TSProgram: tsProgram,
296
- ParsedConfig: parsed,
297
- Checker: checker,
298
- checkerRelease: done,
299
- Host: host,
300
- FS: fs,
301
- }, nil, nil
293
+ checker, done := tsProgram.GetTypeChecker(context.Background())
294
+ return &Program{
295
+ TSProgram: tsProgram,
296
+ ParsedConfig: parsed,
297
+ Checker: checker,
298
+ checkerRelease: done,
299
+ Host: host,
300
+ FS: fs,
301
+ }, nil, nil
302
302
  }
303
303
 
304
304
  func forceEmit(parsed *tsoptions.ParsedCommandLine) {
305
- if parsed == nil || parsed.ParsedConfig == nil || parsed.ParsedConfig.CompilerOptions == nil {
306
- return
307
- }
308
- options := parsed.ParsedConfig.CompilerOptions
309
- options.NoEmit = core.TSFalse
310
- options.EmitDeclarationOnly = core.TSFalse
305
+ if parsed == nil || parsed.ParsedConfig == nil || parsed.ParsedConfig.CompilerOptions == nil {
306
+ return
307
+ }
308
+ options := parsed.ParsedConfig.CompilerOptions
309
+ options.NoEmit = core.TSFalse
310
+ options.EmitDeclarationOnly = core.TSFalse
311
311
  }
312
312
 
313
313
  func forceNoEmit(parsed *tsoptions.ParsedCommandLine) {
314
- if parsed == nil || parsed.ParsedConfig == nil || parsed.ParsedConfig.CompilerOptions == nil {
315
- return
316
- }
317
- parsed.ParsedConfig.CompilerOptions.NoEmit = core.TSTrue
314
+ if parsed == nil || parsed.ParsedConfig == nil || parsed.ParsedConfig.CompilerOptions == nil {
315
+ return
316
+ }
317
+ parsed.ParsedConfig.CompilerOptions.NoEmit = core.TSTrue
318
318
  }
319
319
 
320
320
  func overrideOutDir(cwd string, parsed *tsoptions.ParsedCommandLine, outDir string) {
321
- if parsed == nil || parsed.ParsedConfig == nil || parsed.ParsedConfig.CompilerOptions == nil {
322
- return
323
- }
324
- parsed.ParsedConfig.CompilerOptions.OutDir = tspath.ResolvePath(cwd, outDir)
321
+ if parsed == nil || parsed.ParsedConfig == nil || parsed.ParsedConfig.CompilerOptions == nil {
322
+ return
323
+ }
324
+ parsed.ParsedConfig.CompilerOptions.OutDir = tspath.ResolvePath(cwd, outDir)
325
325
  }
326
326
 
327
327
  // SourceFiles exposes the program's user-authored source files (declaration
328
328
  // files filtered out).
329
329
  func (p *Program) SourceFiles() []*ast.SourceFile {
330
- out := make([]*ast.SourceFile, 0)
331
- for _, f := range p.TSProgram.SourceFiles() {
332
- if f.IsDeclarationFile {
333
- continue
334
- }
335
- out = append(out, f)
336
- }
337
- return out
330
+ out := make([]*ast.SourceFile, 0)
331
+ for _, f := range p.TSProgram.SourceFiles() {
332
+ if f.IsDeclarationFile {
333
+ continue
334
+ }
335
+ out = append(out, f)
336
+ }
337
+ return out
338
338
  }
339
339
 
340
340
  // Diagnostics returns project diagnostics that must block compilation or
341
341
  // runtime execution before any JavaScript is emitted or evaluated.
342
342
  func (p *Program) Diagnostics() []Diagnostic {
343
- if p == nil || p.TSProgram == nil {
344
- return []Diagnostic{{Message: "driver: nil program"}}
345
- }
346
- ctx := context.Background()
347
- raw := shimcompiler.GetDiagnosticsOfAnyProgram(
348
- ctx,
349
- p.TSProgram,
350
- nil,
351
- false,
352
- p.TSProgram.GetBindDiagnostics,
353
- p.TSProgram.GetSemanticDiagnostics,
354
- )
355
- raw = filterDiagnostics(raw)
356
- return convertDiagnostics(shimcompiler.SortAndDeduplicateDiagnostics(raw))
343
+ if p == nil || p.TSProgram == nil {
344
+ return []Diagnostic{{Message: "driver: nil program"}}
345
+ }
346
+ ctx := context.Background()
347
+ raw := shimcompiler.GetDiagnosticsOfAnyProgram(
348
+ ctx,
349
+ p.TSProgram,
350
+ nil,
351
+ false,
352
+ p.TSProgram.GetBindDiagnostics,
353
+ p.TSProgram.GetSemanticDiagnostics,
354
+ )
355
+ raw = filterDiagnostics(raw)
356
+ return convertDiagnostics(shimcompiler.SortAndDeduplicateDiagnostics(raw))
357
357
  }
358
358
 
359
359
  func filterDiagnostics(in []*ast.Diagnostic) []*ast.Diagnostic {
360
- out := in[:0]
361
- for _, d := range in {
362
- if isUnusedOverloadSignatureTypeParameterDiagnostic(d) {
363
- continue
364
- }
365
- out = append(out, d)
366
- }
367
- return out
360
+ out := in[:0]
361
+ for _, d := range in {
362
+ if isUnusedOverloadSignatureTypeParameterDiagnostic(d) {
363
+ continue
364
+ }
365
+ out = append(out, d)
366
+ }
367
+ return out
368
368
  }
369
369
 
370
370
  func isUnusedOverloadSignatureTypeParameterDiagnostic(d *ast.Diagnostic) bool {
371
- if d == nil || d.File() == nil {
372
- return false
373
- }
374
- switch d.Code() {
375
- case 6196, 6205: // unused declaration / all type parameters are unused
376
- default:
377
- return false
378
- }
379
- node := ast.GetNodeAtPosition(d.File(), d.Pos(), false)
380
- for node != nil {
381
- if node.Kind == ast.KindFunctionDeclaration {
382
- return node.Body() == nil
383
- }
384
- node = node.Parent
385
- }
386
- return false
371
+ if d == nil || d.File() == nil {
372
+ return false
373
+ }
374
+ switch d.Code() {
375
+ case 6196, 6205: // unused declaration / all type parameters are unused
376
+ default:
377
+ return false
378
+ }
379
+ node := ast.GetNodeAtPosition(d.File(), d.Pos(), false)
380
+ for node != nil {
381
+ if node.Kind == ast.KindFunctionDeclaration {
382
+ return node.Body() == nil
383
+ }
384
+ node = node.Parent
385
+ }
386
+ return false
387
387
  }
388
388
 
389
389
  // convertDiagnostics translates shim-specific diagnostics into the plain
390
390
  // Diagnostic struct with line/column populated via tsgo's ECMALineMap (the
391
391
  // same helper tsc uses for its "file:line:col: message" banner).
392
392
  func convertDiagnostics(in []*ast.Diagnostic) []Diagnostic {
393
- out := make([]Diagnostic, 0, len(in))
394
- for _, d := range in {
395
- if d == nil {
396
- continue
397
- }
398
- diag := Diagnostic{Code: d.Code(), Message: d.String(), raw: d}
399
- if file := d.File(); file != nil {
400
- diag.File = file.FileName()
401
- if pos := d.Pos(); pos >= 0 {
402
- length := d.Len()
403
- diag.Start = &pos
404
- diag.Length = &length
405
- line, col := shimscanner.GetECMALineAndByteOffsetOfPosition(file, pos)
406
- diag.Line = line + 1
407
- diag.Column = col + 1
408
- }
409
- }
410
- out = append(out, diag)
411
- }
412
- return out
393
+ out := make([]Diagnostic, 0, len(in))
394
+ for _, d := range in {
395
+ if d == nil {
396
+ continue
397
+ }
398
+ diag := Diagnostic{Code: d.Code(), Message: d.String(), raw: d}
399
+ if file := d.File(); file != nil {
400
+ diag.File = file.FileName()
401
+ if pos := d.Pos(); pos >= 0 {
402
+ length := d.Len()
403
+ diag.Start = &pos
404
+ diag.Length = &length
405
+ line, col := shimscanner.GetECMALineAndByteOffsetOfPosition(file, pos)
406
+ diag.Line = line + 1
407
+ diag.Column = col + 1
408
+ }
409
+ }
410
+ out = append(out, diag)
411
+ }
412
+ return out
413
413
  }