@@ -1515,6 +1515,49 @@ module ts {
15151515 var diagnostics : Diagnostic [ ] = [ ] ;
15161516 var newLine = host . getNewLine ( ) ;
15171517
1518+ if ( targetSourceFile === undefined ) {
1519+ forEach ( host . getSourceFiles ( ) , sourceFile => {
1520+ if ( shouldEmitToOwnFile ( sourceFile , compilerOptions ) ) {
1521+ var jsFilePath = getOwnEmitOutputFilePath ( sourceFile , host , ".js" ) ;
1522+ emitFile ( jsFilePath , sourceFile ) ;
1523+ }
1524+ } ) ;
1525+
1526+ if ( compilerOptions . out ) {
1527+ emitFile ( compilerOptions . out ) ;
1528+ }
1529+ }
1530+ else {
1531+ // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
1532+ if ( shouldEmitToOwnFile ( targetSourceFile , compilerOptions ) ) {
1533+ var jsFilePath = getOwnEmitOutputFilePath ( targetSourceFile , host , ".js" ) ;
1534+ emitFile ( jsFilePath , targetSourceFile ) ;
1535+ }
1536+ else if ( ! isDeclarationFile ( targetSourceFile ) && compilerOptions . out ) {
1537+ emitFile ( compilerOptions . out ) ;
1538+ }
1539+ }
1540+
1541+ // Sort and make the unique list of diagnostics
1542+ diagnostics = sortAndDeduplicateDiagnostics ( diagnostics ) ;
1543+
1544+ // Update returnCode if there is any EmitterError
1545+ var hasEmitterError = forEach ( diagnostics , diagnostic => diagnostic . category === DiagnosticCategory . Error ) ;
1546+
1547+ // Check and update returnCode for syntactic and semantic
1548+ var emitResultStatus : EmitReturnStatus ;
1549+ if ( hasEmitterError ) {
1550+ emitResultStatus = EmitReturnStatus . EmitErrorsEncountered ;
1551+ } else {
1552+ emitResultStatus = EmitReturnStatus . Succeeded ;
1553+ }
1554+
1555+ return {
1556+ emitResultStatus,
1557+ diagnostics,
1558+ sourceMaps : sourceMapDataList
1559+ } ;
1560+
15181561 function emitJavaScript ( jsFilePath : string , root ?: SourceFile ) {
15191562 var writer = createTextWriter ( newLine ) ;
15201563 var write = writer . write ;
@@ -4395,29 +4438,6 @@ module ts {
43954438 writeFile ( host , diagnostics , removeFileExtension ( jsFilePath ) + ".d.ts" , declarationOutput , compilerOptions . emitBOM ) ;
43964439 }
43974440 }
4398-
4399- if ( targetSourceFile === undefined ) {
4400- forEach ( host . getSourceFiles ( ) , sourceFile => {
4401- if ( shouldEmitToOwnFile ( sourceFile , compilerOptions ) ) {
4402- var jsFilePath = getOwnEmitOutputFilePath ( sourceFile , host , ".js" ) ;
4403- emitFile ( jsFilePath , sourceFile ) ;
4404- }
4405- } ) ;
4406-
4407- if ( compilerOptions . out ) {
4408- emitFile ( compilerOptions . out ) ;
4409- }
4410- }
4411- else {
4412- // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
4413- if ( shouldEmitToOwnFile ( targetSourceFile , compilerOptions ) ) {
4414- var jsFilePath = getOwnEmitOutputFilePath ( targetSourceFile , host , ".js" ) ;
4415- emitFile ( jsFilePath , targetSourceFile ) ;
4416- }
4417- else if ( ! isDeclarationFile ( targetSourceFile ) && compilerOptions . out ) {
4418- emitFile ( compilerOptions . out ) ;
4419- }
4420- }
44214441
44224442 function emitFile ( jsFilePath : string , sourceFile ?: SourceFile ) {
44234443 emitJavaScript ( jsFilePath , sourceFile ) ;
@@ -4426,25 +4446,5 @@ module ts {
44264446 writeDeclarationFile ( jsFilePath , sourceFile ) ;
44274447 }
44284448 }
4429-
4430- // Sort and make the unique list of diagnostics
4431- diagnostics = sortAndDeduplicateDiagnostics ( diagnostics ) ;
4432-
4433- // Update returnCode if there is any EmitterError
4434- var hasEmitterError = forEach ( diagnostics , diagnostic => diagnostic . category === DiagnosticCategory . Error ) ;
4435-
4436- // Check and update returnCode for syntactic and semantic
4437- var emitResultStatus : EmitReturnStatus ;
4438- if ( hasEmitterError ) {
4439- emitResultStatus = EmitReturnStatus . EmitErrorsEncountered ;
4440- } else {
4441- emitResultStatus = EmitReturnStatus . Succeeded ;
4442- }
4443-
4444- return {
4445- emitResultStatus,
4446- diagnostics,
4447- sourceMaps : sourceMapDataList
4448- } ;
44494449 }
44504450}
0 commit comments