|
2 | 2 | package main
|
3 | 3 |
|
4 | 4 | import (
|
5 |
| - "github.com/microsoft/typescript-go/internal/compiler" |
| 5 | + "flag" |
| 6 | + "fmt" |
| 7 | + "runtime" |
| 8 | + "strings" |
| 9 | + "time" |
| 10 | + |
| 11 | + ts "github.com/microsoft/typescript-go/internal/compiler" |
6 | 12 | )
|
7 | 13 |
|
| 14 | +var quiet = false |
| 15 | +var singleThreaded = false |
| 16 | +var parseAndBindOnly = false |
| 17 | + |
| 18 | +func printDiagnostic(d *ts.Diagnostic, level int) { |
| 19 | + file := d.File() |
| 20 | + if file != nil { |
| 21 | + line, character := ts.GetLineAndCharacterOfPosition(file, d.Loc().Pos()) |
| 22 | + fmt.Printf("%v%v(%v,%v): error TS%v: %v\n", strings.Repeat(" ", level*2), file.FileName(), line+1, character+1, d.Code(), d.Message()) |
| 23 | + } else { |
| 24 | + fmt.Printf("%verror TS%v: %v\n", strings.Repeat(" ", level*2), d.Code(), d.Message()) |
| 25 | + } |
| 26 | + for _, r := range d.RelatedInformation() { |
| 27 | + printDiagnostic(r, level+1) |
| 28 | + } |
| 29 | +} |
| 30 | + |
8 | 31 | func main() {
|
9 |
| - compiler.CreateSourceFile() |
| 32 | + flag.BoolVar(&quiet, "q", false, "Quiet output") |
| 33 | + flag.BoolVar(&singleThreaded, "s", false, "Single threaded") |
| 34 | + flag.BoolVar(&parseAndBindOnly, "p", false, "Parse and bind only") |
| 35 | + flag.Parse() |
| 36 | + compilerOptions := &ts.CompilerOptions{Target: ts.ScriptTargetESNext, ModuleKind: ts.ModuleKindNodeNext} |
| 37 | + programOptions := ts.ProgramOptions{RootPath: flag.Arg(0), Options: compilerOptions, SingleThreaded: singleThreaded} |
| 38 | + startTime := time.Now() |
| 39 | + program := ts.NewProgram(programOptions) |
| 40 | + diagnostics := program.GetSyntacticDiagnostics(nil) |
| 41 | + if len(diagnostics) == 0 { |
| 42 | + if parseAndBindOnly { |
| 43 | + diagnostics = program.GetBindDiagnostics(nil) |
| 44 | + } else { |
| 45 | + diagnostics = program.GetSemanticDiagnostics(nil) |
| 46 | + } |
| 47 | + } |
| 48 | + compileTime := time.Since(startTime) |
| 49 | + var memStats runtime.MemStats |
| 50 | + runtime.GC() |
| 51 | + runtime.GC() |
| 52 | + runtime.ReadMemStats(&memStats) |
| 53 | + if !quiet { |
| 54 | + for _, diagnostic := range diagnostics { |
| 55 | + printDiagnostic(diagnostic, 0) |
| 56 | + } |
| 57 | + } |
| 58 | + fmt.Printf("Files: %v\n", len(program.SourceFiles())) |
| 59 | + fmt.Printf("Compile time: %v\n", compileTime) |
| 60 | + fmt.Printf("Memory used: %vK\n", memStats.Alloc/1024) |
10 | 61 | }
|
0 commit comments