Skip to content

Commit a8171c9

Browse files
committed
tsc -b
1 parent 2dc8537 commit a8171c9

File tree

78 files changed

+4649
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4649
-495
lines changed

internal/api/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"strconv"
1010
"sync"
11+
"time"
1112

1213
"github.com/microsoft/typescript-go/internal/bundled"
1314
"github.com/microsoft/typescript-go/internal/core"
@@ -472,3 +473,8 @@ func (s *Server) Stat(path string) vfs.FileInfo {
472473
func (s *Server) Remove(path string) error {
473474
panic("unimplemented")
474475
}
476+
477+
// Chtimes implements vfs.FS.
478+
func (s *Server) Chtimes(path string, aTime time.Time, mTime time.Time) error {
479+
panic("unimplemented")
480+
}

internal/bundled/embed.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ func (vfs *wrappedFS) Remove(path string) error {
161161
return vfs.fs.Remove(path)
162162
}
163163

164+
func (vfs *wrappedFS) Chtimes(path string, aTime time.Time, mTime time.Time) error {
165+
if _, ok := splitPath(path); ok {
166+
panic("cannot change times on embedded file system")
167+
}
168+
return vfs.fs.Chtimes(path, aTime, mTime)
169+
}
170+
164171
type fileInfo struct {
165172
mode fs.FileMode
166173
name string

internal/compiler/emitter.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ type emitter struct {
4242
}
4343

4444
func (e *emitter) emit() {
45-
if e.host.Options().ListEmittedFiles.IsTrue() {
46-
e.emitResult.EmittedFiles = []string{}
47-
}
4845
// !!! tracing
4946
e.emitJSFile(e.sourceFile, e.paths.JsFilePath(), e.paths.SourceMapFilePath())
5047
e.emitDeclarationFile(e.sourceFile, e.paths.DeclarationFilePath(), e.paths.DeclarationMapPath())
@@ -254,7 +251,7 @@ func (e *emitter) printSourceFile(jsFilePath string, sourceMapFilePath string, s
254251
err := e.host.WriteFile(sourceMapFilePath, sourceMap, false /*writeByteOrderMark*/)
255252
if err != nil {
256253
e.emitterDiagnostics.Add(ast.NewCompilerDiagnostic(diagnostics.Could_not_write_file_0_Colon_1, jsFilePath, err.Error()))
257-
} else if e.emitResult.EmittedFiles != nil {
254+
} else {
258255
e.emitResult.EmittedFiles = append(e.emitResult.EmittedFiles, sourceMapFilePath)
259256
}
260257
}
@@ -278,7 +275,7 @@ func (e *emitter) printSourceFile(jsFilePath string, sourceMapFilePath string, s
278275
}
279276
if err != nil {
280277
e.emitterDiagnostics.Add(ast.NewCompilerDiagnostic(diagnostics.Could_not_write_file_0_Colon_1, jsFilePath, err.Error()))
281-
} else if e.emitResult.EmittedFiles != nil && !skippedDtsWrite {
278+
} else if !skippedDtsWrite {
282279
e.emitResult.EmittedFiles = append(e.emitResult.EmittedFiles, jsFilePath)
283280
}
284281

internal/compiler/fileloader.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,6 @@ func getInferredLibraryNameResolveFrom(options *core.CompilerOptions, currentDir
567567
return tspath.CombinePaths(containingDirectory, "__lib_node_modules_lookup_"+libFileName+"__.ts")
568568
}
569569

570-
type resolution struct {
571-
node *ast.Node
572-
resolvedModule *module.ResolvedModule
573-
}
574-
575570
func getModeForTypeReferenceDirectiveInFile(ref *ast.FileReference, file *ast.SourceFile, meta ast.SourceFileMetaData, options *core.CompilerOptions) core.ResolutionMode {
576571
if ref.ResolutionMode != core.ResolutionModeNone {
577572
return ref.ResolutionMode

internal/compiler/program.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func equalCheckJSDirectives(d1 *ast.CheckJsDirective, d2 *ast.CheckJsDirective)
257257

258258
func (p *Program) SourceFiles() []*ast.SourceFile { return p.files }
259259
func (p *Program) Options() *core.CompilerOptions { return p.opts.Config.CompilerOptions() }
260+
func (p *Program) GetRootFileNames() []string { return p.opts.Config.FileNames() }
260261
func (p *Program) Host() CompilerHost { return p.opts.Host }
261262
func (p *Program) GetConfigFileParsingDiagnostics() []*ast.Diagnostic {
262263
return slices.Clip(p.opts.Config.GetConfigFileParsingDiagnostics())
@@ -1302,9 +1303,7 @@ func CombineEmitResults(results []*EmitResult) *EmitResult {
13021303
result.EmitSkipped = true
13031304
}
13041305
result.Diagnostics = append(result.Diagnostics, emitResult.Diagnostics...)
1305-
if emitResult.EmittedFiles != nil {
1306-
result.EmittedFiles = append(result.EmittedFiles, emitResult.EmittedFiles...)
1307-
}
1306+
result.EmittedFiles = append(result.EmittedFiles, emitResult.EmittedFiles...)
13081307
if emitResult.SourceMaps != nil {
13091308
result.SourceMaps = append(result.SourceMaps, emitResult.SourceMaps...)
13101309
}

internal/compiler/projectreferencedtsfakinghost.go

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

33
import (
44
"strings"
5+
"time"
56

67
"github.com/microsoft/typescript-go/internal/collections"
78
"github.com/microsoft/typescript-go/internal/core"
@@ -87,6 +88,11 @@ func (fs *projectReferenceDtsFakingVfs) Remove(path string) error {
8788
panic("should not be called by resolver")
8889
}
8990

91+
// Chtimes implements vfs.FS.
92+
func (fs *projectReferenceDtsFakingVfs) Chtimes(path string, aTime time.Time, mTime time.Time) error {
93+
panic("should not be called by resolver")
94+
}
95+
9096
// DirectoryExists implements vfs.FS.
9197
func (fs *projectReferenceDtsFakingVfs) DirectoryExists(path string) bool {
9298
if fs.projectReferenceFileMapper.opts.Host.FS().DirectoryExists(path) {

internal/diagnostics/diagnostics_generated.go

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/diagnostics/extraDiagnosticMessages.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,21 @@
2222
"A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag.": {
2323
"category": "Error",
2424
"code": 8040
25+
},
26+
"Failed to delete file '{0}'.": {
27+
"category": "Message",
28+
"code": 6353
29+
},
30+
"Project '{0}' is out of date because config file does not exist.": {
31+
"category": "Message",
32+
"code": 6401
33+
},
34+
"Project '{0}' is out of date because input '{1}' does not exist.": {
35+
"category": "Message",
36+
"code": 6420
37+
},
38+
"Failed to update timestamp of file '{0}'.": {
39+
"category": "Message",
40+
"code": 6450
2541
}
2642
}

internal/diagnosticwriter/diagnosticwriter.go

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type FormattingOptions struct {
2121
}
2222

2323
const (
24-
foregroundColorEscapeGrey = "\u001b[90m"
24+
ForegroundColorEscapeGrey = "\u001b[90m"
2525
foregroundColorEscapeRed = "\u001b[91m"
2626
foregroundColorEscapeYellow = "\u001b[93m"
2727
foregroundColorEscapeBlue = "\u001b[94m"
@@ -31,51 +31,53 @@ const (
3131
const (
3232
gutterStyleSequence = "\u001b[7m"
3333
gutterSeparator = " "
34-
resetEscapeSequence = "\u001b[0m"
34+
ResetEscapeSequence = "\u001b[0m"
3535
ellipsis = "..."
3636
)
3737

3838
func FormatDiagnosticsWithColorAndContext(output io.Writer, diags []*ast.Diagnostic, formatOpts *FormattingOptions) {
3939
if len(diags) == 0 {
4040
return
4141
}
42-
4342
for i, diagnostic := range diags {
4443
if i > 0 {
4544
fmt.Fprint(output, formatOpts.NewLine)
4645
}
46+
FormatDiagnosticWithColorAndContext(output, diagnostic, formatOpts)
47+
}
48+
}
4749

48-
if diagnostic.File() != nil {
49-
file := diagnostic.File()
50-
pos := diagnostic.Loc().Pos()
51-
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
52-
fmt.Fprint(output, " - ")
53-
}
50+
func FormatDiagnosticWithColorAndContext(output io.Writer, diagnostic *ast.Diagnostic, formatOpts *FormattingOptions) {
51+
if diagnostic.File() != nil {
52+
file := diagnostic.File()
53+
pos := diagnostic.Loc().Pos()
54+
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
55+
fmt.Fprint(output, " - ")
56+
}
5457

55-
writeWithStyleAndReset(output, diagnostic.Category().Name(), getCategoryFormat(diagnostic.Category()))
56-
fmt.Fprintf(output, "%s TS%d: %s", foregroundColorEscapeGrey, diagnostic.Code(), resetEscapeSequence)
57-
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
58+
writeWithStyleAndReset(output, diagnostic.Category().Name(), getCategoryFormat(diagnostic.Category()))
59+
fmt.Fprintf(output, "%s TS%d: %s", ForegroundColorEscapeGrey, diagnostic.Code(), ResetEscapeSequence)
60+
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
5861

59-
if diagnostic.File() != nil && diagnostic.Code() != diagnostics.File_appears_to_be_binary.Code() {
60-
fmt.Fprint(output, formatOpts.NewLine)
61-
writeCodeSnippet(output, diagnostic.File(), diagnostic.Pos(), diagnostic.Len(), getCategoryFormat(diagnostic.Category()), "", formatOpts)
62-
fmt.Fprint(output, formatOpts.NewLine)
63-
}
62+
if diagnostic.File() != nil && diagnostic.Code() != diagnostics.File_appears_to_be_binary.Code() {
63+
fmt.Fprint(output, formatOpts.NewLine)
64+
writeCodeSnippet(output, diagnostic.File(), diagnostic.Pos(), diagnostic.Len(), getCategoryFormat(diagnostic.Category()), "", formatOpts)
65+
fmt.Fprint(output, formatOpts.NewLine)
66+
}
6467

65-
if (diagnostic.RelatedInformation() != nil) && (len(diagnostic.RelatedInformation()) > 0) {
66-
for _, relatedInformation := range diagnostic.RelatedInformation() {
67-
file := relatedInformation.File()
68-
if file != nil {
69-
fmt.Fprint(output, formatOpts.NewLine)
70-
fmt.Fprint(output, " ")
71-
pos := relatedInformation.Pos()
72-
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
73-
fmt.Fprint(output, " - ")
74-
WriteFlattenedDiagnosticMessage(output, relatedInformation, formatOpts.NewLine)
75-
writeCodeSnippet(output, file, pos, relatedInformation.Len(), foregroundColorEscapeCyan, " ", formatOpts)
76-
}
68+
if (diagnostic.RelatedInformation() != nil) && (len(diagnostic.RelatedInformation()) > 0) {
69+
for _, relatedInformation := range diagnostic.RelatedInformation() {
70+
file := relatedInformation.File()
71+
if file != nil {
7772
fmt.Fprint(output, formatOpts.NewLine)
73+
fmt.Fprint(output, " ")
74+
pos := relatedInformation.Pos()
75+
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
76+
fmt.Fprint(output, " - ")
77+
WriteFlattenedDiagnosticMessage(output, relatedInformation, formatOpts.NewLine)
78+
writeCodeSnippet(output, file, pos, relatedInformation.Len(), foregroundColorEscapeCyan, " ", formatOpts)
7879
}
80+
fmt.Fprint(output, formatOpts.NewLine)
7981
}
8082
}
8183
}
@@ -104,7 +106,7 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
104106
fmt.Fprint(writer, indent)
105107
fmt.Fprint(writer, gutterStyleSequence)
106108
fmt.Fprintf(writer, "%*s", gutterWidth, ellipsis)
107-
fmt.Fprint(writer, resetEscapeSequence)
109+
fmt.Fprint(writer, ResetEscapeSequence)
108110
fmt.Fprint(writer, gutterSeparator)
109111
fmt.Fprint(writer, formatOpts.NewLine)
110112
i = lastLine - 1
@@ -125,7 +127,7 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
125127
fmt.Fprint(writer, indent)
126128
fmt.Fprint(writer, gutterStyleSequence)
127129
fmt.Fprintf(writer, "%*d", gutterWidth, i+1)
128-
fmt.Fprint(writer, resetEscapeSequence)
130+
fmt.Fprint(writer, ResetEscapeSequence)
129131
fmt.Fprint(writer, gutterSeparator)
130132
fmt.Fprint(writer, lineContent)
131133
fmt.Fprint(writer, formatOpts.NewLine)
@@ -134,7 +136,7 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
134136
fmt.Fprint(writer, indent)
135137
fmt.Fprint(writer, gutterStyleSequence)
136138
fmt.Fprintf(writer, "%*s", gutterWidth, "")
137-
fmt.Fprint(writer, resetEscapeSequence)
139+
fmt.Fprint(writer, ResetEscapeSequence)
138140
fmt.Fprint(writer, gutterSeparator)
139141
fmt.Fprint(writer, squiggleColor)
140142
if i == firstLine {
@@ -159,7 +161,7 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
159161
fmt.Fprint(writer, strings.Repeat("~", len(lineContent)))
160162
}
161163

162-
fmt.Fprint(writer, resetEscapeSequence)
164+
fmt.Fprint(writer, ResetEscapeSequence)
163165
}
164166
}
165167

@@ -196,7 +198,7 @@ func getCategoryFormat(category diagnostics.Category) string {
196198
case diagnostics.CategoryWarning:
197199
return foregroundColorEscapeYellow
198200
case diagnostics.CategorySuggestion:
199-
return foregroundColorEscapeGrey
201+
return ForegroundColorEscapeGrey
200202
case diagnostics.CategoryMessage:
201203
return foregroundColorEscapeBlue
202204
}
@@ -208,7 +210,7 @@ type FormattedWriter func(output io.Writer, text string, formatStyle string)
208210
func writeWithStyleAndReset(output io.Writer, text string, formatStyle string) {
209211
fmt.Fprint(output, formatStyle)
210212
fmt.Fprint(output, text)
211-
fmt.Fprint(output, resetEscapeSequence)
213+
fmt.Fprint(output, ResetEscapeSequence)
212214
}
213215

214216
func WriteLocation(output io.Writer, file *ast.SourceFile, pos int, formatOpts *FormattingOptions, writeWithStyleAndReset FormattedWriter) {
@@ -359,9 +361,9 @@ func prettyPathForFileError(file *ast.SourceFile, fileErrors []*ast.Diagnostic,
359361
}
360362
return fmt.Sprintf("%s%s:%d%s",
361363
fileName,
362-
foregroundColorEscapeGrey,
364+
ForegroundColorEscapeGrey,
363365
line+1,
364-
resetEscapeSequence,
366+
ResetEscapeSequence,
365367
)
366368
}
367369

@@ -383,3 +385,15 @@ func WriteFormatDiagnostic(output io.Writer, diagnostic *ast.Diagnostic, formatO
383385
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
384386
fmt.Fprint(output, formatOpts.NewLine)
385387
}
388+
389+
func FormatDiagnosticsStatusWithColorAndTime(output io.Writer, time string, diag *ast.Diagnostic, formatOpts *FormattingOptions) {
390+
fmt.Fprint(output, "[")
391+
writeWithStyleAndReset(output, time, ForegroundColorEscapeGrey)
392+
fmt.Fprint(output, "] ")
393+
WriteFlattenedDiagnosticMessage(output, diag, formatOpts.NewLine)
394+
}
395+
396+
func FormatDiagnosticsStatusAndTime(output io.Writer, time string, diag *ast.Diagnostic, formatOpts *FormattingOptions) {
397+
fmt.Fprint(output, time, " - ")
398+
WriteFlattenedDiagnosticMessage(output, diag, formatOpts.NewLine)
399+
}

0 commit comments

Comments
 (0)