@@ -41,30 +41,25 @@ func applyBulkEdits(text string, edits []core.TextChange) string {
41
41
return b .String ()
42
42
}
43
43
44
- func CommandLine (sys System , commandLineArgs []string ) ExitStatus {
45
- status , _ , watcher := commandLineWorker (sys , commandLineArgs )
46
- if watcher == nil {
47
- return status
48
- }
49
- return start (watcher )
50
- }
51
-
52
- func commandLineWorker (sys System , commandLineArgs []string ) (ExitStatus , * tsoptions.ParsedCommandLine , * watcher ) {
44
+ func CommandLine (sys System , commandLineArgs []string , testing bool ) (ExitStatus , * tsoptions.ParsedCommandLine , * incremental.Program , * Watcher ) {
53
45
if len (commandLineArgs ) > 0 {
54
46
// !!! build mode
55
47
switch strings .ToLower (commandLineArgs [0 ]) {
56
48
case "-b" , "--b" , "-build" , "--build" :
57
49
fmt .Fprint (sys .Writer (), "Build mode is currently unsupported." + sys .NewLine ())
58
50
sys .EndWrite ()
59
- return ExitStatusNotImplemented , nil , nil
51
+ return ExitStatusNotImplemented , nil , nil , nil
60
52
// case "-f":
61
53
// return fmtMain(sys, commandLineArgs[1], commandLineArgs[1])
62
54
}
63
55
}
64
56
65
57
parsedCommandLine := tsoptions .ParseCommandLine (commandLineArgs , sys )
66
- status , watcher := tscCompilation (sys , parsedCommandLine )
67
- return status , parsedCommandLine , watcher
58
+ status , incrementalProgram , watcher := tscCompilation (sys , parsedCommandLine , testing )
59
+ if watcher == nil {
60
+ watcher .start ()
61
+ }
62
+ return status , parsedCommandLine , incrementalProgram , watcher
68
63
}
69
64
70
65
func fmtMain (sys System , input , output string ) ExitStatus {
@@ -93,7 +88,7 @@ func fmtMain(sys System, input, output string) ExitStatus {
93
88
return ExitStatusSuccess
94
89
}
95
90
96
- func tscCompilation (sys System , commandLine * tsoptions.ParsedCommandLine ) (ExitStatus , * watcher ) {
91
+ func tscCompilation (sys System , commandLine * tsoptions.ParsedCommandLine , testing bool ) (ExitStatus , * incremental. Program , * Watcher ) {
97
92
configFileName := ""
98
93
reportDiagnostic := createDiagnosticReporter (sys , commandLine .CompilerOptions ())
99
94
// if commandLine.Options().Locale != nil
@@ -102,7 +97,7 @@ func tscCompilation(sys System, commandLine *tsoptions.ParsedCommandLine) (ExitS
102
97
for _ , e := range commandLine .Errors {
103
98
reportDiagnostic (e )
104
99
}
105
- return ExitStatusDiagnosticsPresent_OutputsSkipped , nil
100
+ return ExitStatusDiagnosticsPresent_OutputsSkipped , nil , nil
106
101
}
107
102
108
103
if pprofDir := commandLine .CompilerOptions ().PprofDir ; pprofDir != "" {
@@ -112,42 +107,42 @@ func tscCompilation(sys System, commandLine *tsoptions.ParsedCommandLine) (ExitS
112
107
}
113
108
114
109
if commandLine .CompilerOptions ().Init .IsTrue () {
115
- return ExitStatusNotImplemented , nil
110
+ return ExitStatusNotImplemented , nil , nil
116
111
}
117
112
118
113
if commandLine .CompilerOptions ().Version .IsTrue () {
119
114
printVersion (sys )
120
- return ExitStatusSuccess , nil
115
+ return ExitStatusSuccess , nil , nil
121
116
}
122
117
123
118
if commandLine .CompilerOptions ().Help .IsTrue () || commandLine .CompilerOptions ().All .IsTrue () {
124
119
printHelp (sys , commandLine )
125
- return ExitStatusSuccess , nil
120
+ return ExitStatusSuccess , nil , nil
126
121
}
127
122
128
123
if commandLine .CompilerOptions ().Watch .IsTrue () && commandLine .CompilerOptions ().ListFilesOnly .IsTrue () {
129
124
reportDiagnostic (ast .NewCompilerDiagnostic (diagnostics .Options_0_and_1_cannot_be_combined , "watch" , "listFilesOnly" ))
130
- return ExitStatusDiagnosticsPresent_OutputsSkipped , nil
125
+ return ExitStatusDiagnosticsPresent_OutputsSkipped , nil , nil
131
126
}
132
127
133
128
if commandLine .CompilerOptions ().Project != "" {
134
129
if len (commandLine .FileNames ()) != 0 {
135
130
reportDiagnostic (ast .NewCompilerDiagnostic (diagnostics .Option_project_cannot_be_mixed_with_source_files_on_a_command_line ))
136
- return ExitStatusDiagnosticsPresent_OutputsSkipped , nil
131
+ return ExitStatusDiagnosticsPresent_OutputsSkipped , nil , nil
137
132
}
138
133
139
134
fileOrDirectory := tspath .NormalizePath (commandLine .CompilerOptions ().Project )
140
135
if sys .FS ().DirectoryExists (fileOrDirectory ) {
141
136
configFileName = tspath .CombinePaths (fileOrDirectory , "tsconfig.json" )
142
137
if ! sys .FS ().FileExists (configFileName ) {
143
138
reportDiagnostic (ast .NewCompilerDiagnostic (diagnostics .Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0 , configFileName ))
144
- return ExitStatusDiagnosticsPresent_OutputsSkipped , nil
139
+ return ExitStatusDiagnosticsPresent_OutputsSkipped , nil , nil
145
140
}
146
141
} else {
147
142
configFileName = fileOrDirectory
148
143
if ! sys .FS ().FileExists (configFileName ) {
149
144
reportDiagnostic (ast .NewCompilerDiagnostic (diagnostics .The_specified_path_does_not_exist_Colon_0 , fileOrDirectory ))
150
- return ExitStatusDiagnosticsPresent_OutputsSkipped , nil
145
+ return ExitStatusDiagnosticsPresent_OutputsSkipped , nil , nil
151
146
}
152
147
}
153
148
} else if len (commandLine .FileNames ()) == 0 {
@@ -162,7 +157,7 @@ func tscCompilation(sys System, commandLine *tsoptions.ParsedCommandLine) (ExitS
162
157
printVersion (sys )
163
158
printHelp (sys , commandLine )
164
159
}
165
- return ExitStatusDiagnosticsPresent_OutputsSkipped , nil
160
+ return ExitStatusDiagnosticsPresent_OutputsSkipped , nil , nil
166
161
}
167
162
168
163
// !!! convert to options with absolute paths is usually done here, but for ease of implementation, it's done in `tsoptions.ParseCommandLine()`
@@ -179,7 +174,7 @@ func tscCompilation(sys System, commandLine *tsoptions.ParsedCommandLine) (ExitS
179
174
for _ , e := range errors {
180
175
reportDiagnostic (e )
181
176
}
182
- return ExitStatusDiagnosticsPresent_OutputsGenerated , nil
177
+ return ExitStatusDiagnosticsPresent_OutputsGenerated , nil , nil
183
178
}
184
179
configForCompilation = configParseResult
185
180
// Updater to reflect pretty
@@ -188,26 +183,28 @@ func tscCompilation(sys System, commandLine *tsoptions.ParsedCommandLine) (ExitS
188
183
189
184
if compilerOptionsFromCommandLine .ShowConfig .IsTrue () {
190
185
showConfig (sys , configForCompilation .CompilerOptions ())
191
- return ExitStatusSuccess , nil
186
+ return ExitStatusSuccess , nil , nil
192
187
}
193
188
if configForCompilation .CompilerOptions ().Watch .IsTrue () {
194
- return ExitStatusSuccess , createWatcher (sys , configForCompilation , reportDiagnostic )
189
+ return ExitStatusSuccess , nil , createWatcher (sys , configForCompilation , reportDiagnostic , testing )
195
190
} else if configForCompilation .CompilerOptions ().IsIncremental () {
196
- return performIncrementalCompilation (
191
+ exitStatus , program := performIncrementalCompilation (
197
192
sys ,
198
193
configForCompilation ,
199
194
reportDiagnostic ,
200
195
& extendedConfigCache ,
201
196
configTime ,
202
- ), nil
197
+ testing ,
198
+ )
199
+ return exitStatus , program , nil
203
200
}
204
201
return performCompilation (
205
202
sys ,
206
203
configForCompilation ,
207
204
reportDiagnostic ,
208
205
& extendedConfigCache ,
209
206
configTime ,
210
- ), nil
207
+ ), nil , nil
211
208
}
212
209
213
210
func findConfigFile (searchPath string , fileExists func (string ) bool , configName string ) string {
@@ -230,7 +227,8 @@ func performIncrementalCompilation(
230
227
reportDiagnostic diagnosticReporter ,
231
228
extendedConfigCache * collections.SyncMap [tspath.Path , * tsoptions.ExtendedConfigCacheEntry ],
232
229
configTime time.Duration ,
233
- ) ExitStatus {
230
+ testing bool ,
231
+ ) (ExitStatus , * incremental.Program ) {
234
232
host := compiler .NewCachedFSCompilerHost (config .CompilerOptions (), sys .GetCurrentDirectory (), sys .FS (), sys .DefaultLibraryPath (), extendedConfigCache )
235
233
oldProgram := incremental .ReadBuildInfoProgram (config , incremental .NewBuildInfoReader (host ))
236
234
// todo: cache, statistics, tracing
@@ -241,7 +239,7 @@ func performIncrementalCompilation(
241
239
JSDocParsingMode : ast .JSDocParsingModeParseForTypeErrors ,
242
240
})
243
241
parseTime := sys .Now ().Sub (parseStart )
244
- incrementalProgram := incremental .NewProgram (program , oldProgram )
242
+ incrementalProgram := incremental .NewProgram (program , oldProgram , testing )
245
243
return emitAndReportStatistics (
246
244
sys ,
247
245
incrementalProgram ,
@@ -250,7 +248,7 @@ func performIncrementalCompilation(
250
248
reportDiagnostic ,
251
249
configTime ,
252
250
parseTime ,
253
- )
251
+ ), incrementalProgram
254
252
}
255
253
256
254
func performCompilation (
0 commit comments