@@ -129,7 +129,7 @@ namespace ts {
129129 }
130130
131131 export function listFiles ( program : ProgramToEmitFilesAndReportErrors , writeFileName : ( s : string ) => void ) {
132- if ( program . getCompilerOptions ( ) . listFiles ) {
132+ if ( program . getCompilerOptions ( ) . listFiles || program . getCompilerOptions ( ) . listFilesOnly ) {
133133 forEach ( program . getSourceFiles ( ) , file => {
134134 writeFileName ( file . fileName ) ;
135135 } ) ;
@@ -149,6 +149,8 @@ namespace ts {
149149 emitOnlyDtsFiles ?: boolean ,
150150 customTransformers ?: CustomTransformers
151151 ) {
152+ const isListFilesOnly = ! ! program . getCompilerOptions ( ) . listFilesOnly ;
153+
152154 // First get and report any syntactic errors.
153155 const diagnostics = program . getConfigFileParsingDiagnostics ( ) . slice ( ) ;
154156 const configFileParsingDiagnosticsLength = diagnostics . length ;
@@ -158,15 +160,20 @@ namespace ts {
158160 // semantic errors.
159161 if ( diagnostics . length === configFileParsingDiagnosticsLength ) {
160162 addRange ( diagnostics , program . getOptionsDiagnostics ( cancellationToken ) ) ;
161- addRange ( diagnostics , program . getGlobalDiagnostics ( cancellationToken ) ) ;
162163
163- if ( diagnostics . length === configFileParsingDiagnosticsLength ) {
164- addRange ( diagnostics , program . getSemanticDiagnostics ( /*sourceFile*/ undefined , cancellationToken ) ) ;
164+ if ( ! isListFilesOnly ) {
165+ addRange ( diagnostics , program . getGlobalDiagnostics ( cancellationToken ) ) ;
166+
167+ if ( diagnostics . length === configFileParsingDiagnosticsLength ) {
168+ addRange ( diagnostics , program . getSemanticDiagnostics ( /*sourceFile*/ undefined , cancellationToken ) ) ;
169+ }
165170 }
166171 }
167172
168173 // Emit and report any errors we ran into.
169- const emitResult = program . emit ( /*targetSourceFile*/ undefined , writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers ) ;
174+ const emitResult = isListFilesOnly
175+ ? { emitSkipped : true , diagnostics : emptyArray }
176+ : program . emit ( /*targetSourceFile*/ undefined , writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers ) ;
170177 const { emittedFiles, diagnostics : emitDiagnostics } = emitResult ;
171178 addRange ( diagnostics , emitDiagnostics ) ;
172179
0 commit comments