@@ -35,60 +35,73 @@ var ProjectCompiler = (function () {
3535 var currentDirectory = utils . getCommonBasePathOfArray ( rootFilenames . map ( function ( fileName ) { return _this . project . input . getFile ( fileName ) . gulp . cwd ; } ) ) ;
3636 this . host = new host_1 . Host ( this . project . typescript , currentDirectory , this . project . input , this . project . options ) ;
3737 this . program = this . project . typescript . createProgram ( rootFilenames , this . project . options , this . host , this . program ) ;
38- var preEmitDiagnostics = this . project . typescript . getPreEmitDiagnostics ( this . program ) ;
3938 var result = reporter_1 . emptyCompilationResult ( ) ;
40- result . optionsErrors = this . program . getOptionsDiagnostics ( ) . length ;
41- result . syntaxErrors = this . program . getSyntacticDiagnostics ( ) . length ;
42- result . globalErrors = this . program . getGlobalDiagnostics ( ) . length ;
43- result . semanticErrors = this . program . getSemanticDiagnostics ( ) . length ;
39+ result . optionsErrors = this . reportDiagnostics ( this . program . getOptionsDiagnostics ( ) ) ;
40+ result . syntaxErrors = this . reportDiagnostics ( this . program . getSyntacticDiagnostics ( ) ) ;
41+ result . globalErrors = this . reportDiagnostics ( this . program . getGlobalDiagnostics ( ) ) ;
42+ result . semanticErrors = this . reportDiagnostics ( this . program . getSemanticDiagnostics ( ) ) ;
4443 if ( this . project . options . declaration ) {
4544 result . declarationErrors = this . program . getDeclarationDiagnostics ( ) . length ;
4645 }
47- this . reportDiagnostics ( preEmitDiagnostics ) ;
48- var emitOutput = this . program . emit ( ) ;
49- result . emitErrors = emitOutput . diagnostics . length ;
50- result . emitSkipped = emitOutput . emitSkipped ;
5146 if ( this . project . singleOutput ) {
52- this . emitFile ( result , currentDirectory ) ;
47+ var output_1 = {
48+ file : undefined
49+ } ;
50+ this . emit ( result , function ( fileName , content ) {
51+ _this . attachContentToFile ( output_1 , fileName , content ) ;
52+ } ) ;
53+ this . emitFile ( output_1 , currentDirectory ) ;
5354 }
5455 else {
55- // Emit files one by one
56- for ( var _i = 0 , _a = this . host . input . getFileNames ( true ) ; _i < _a . length ; _i ++ ) {
57- var fileName = _a [ _i ] ;
56+ var output_2 = { } ;
57+ var input = this . host . input . getFileNames ( true ) ;
58+ for ( var i = 0 ; i < input . length ; i ++ ) {
59+ var fileName = utils . normalizePath ( input [ i ] ) ;
5860 var file = this . project . input . getFile ( fileName ) ;
59- this . emitFile ( result , currentDirectory , file ) ;
61+ output_2 [ fileName ] = { file : file } ;
62+ }
63+ this . emit ( result , function ( fileName , content , writeByteOrderMark , onError , sourceFiles ) {
64+ if ( sourceFiles . length !== 1 ) {
65+ throw new Error ( "Failure: sourceFiles in WriteFileCallback should have length 1, got " + sourceFiles . length ) ;
66+ }
67+ var fileNameOriginal = utils . normalizePath ( sourceFiles [ 0 ] . fileName ) ;
68+ var file = output_2 [ fileNameOriginal ] ;
69+ if ( ! file )
70+ return ;
71+ _this . attachContentToFile ( file , fileName , content ) ;
72+ } ) ;
73+ for ( var i = 0 ; i < input . length ; i ++ ) {
74+ var fileName = utils . normalizePath ( input [ i ] ) ;
75+ this . emitFile ( output_2 [ fileName ] , currentDirectory ) ;
6076 }
6177 }
6278 this . project . output . finish ( result ) ;
6379 } ;
64- ProjectCompiler . prototype . emitFile = function ( result , currentDirectory , file ) {
65- var jsFileName ;
66- var dtsFileName ;
67- var jsContent ;
68- var dtsContent ;
69- var jsMapContent ;
70- var emitOutput = this . program . emit ( file && file . ts , function ( fileName , content ) {
71- var _a = utils . splitExtension ( fileName , [ 'd.ts' ] ) , extension = _a [ 1 ] ;
72- switch ( extension ) {
73- case 'js' :
74- case 'jsx' :
75- jsFileName = fileName ;
76- jsContent = content ;
77- break ;
78- case 'd.ts' :
79- dtsFileName = fileName ;
80- dtsContent = content ;
81- break ;
82- case 'map' :
83- jsMapContent = content ;
84- break ;
85- }
86- } ) ;
80+ ProjectCompiler . prototype . attachContentToFile = function ( file , fileName , content ) {
81+ var _a = utils . splitExtension ( fileName , [ 'd.ts' ] ) , extension = _a [ 1 ] ;
82+ switch ( extension ) {
83+ case 'js' :
84+ case 'jsx' :
85+ file . jsFileName = fileName ;
86+ file . jsContent = content ;
87+ break ;
88+ case 'd.ts' :
89+ file . dtsFileName = fileName ;
90+ file . dtsContent = content ;
91+ break ;
92+ case 'map' :
93+ file . jsMapContent = content ;
94+ break ;
95+ }
96+ } ;
97+ ProjectCompiler . prototype . emit = function ( result , callback ) {
98+ var emitOutput = this . program . emit ( undefined , callback ) ;
8799 result . emitErrors += emitOutput . diagnostics . length ;
88100 this . reportDiagnostics ( emitOutput . diagnostics ) ;
89- if ( emitOutput . emitSkipped ) {
90- result . emitSkipped = true ;
91- }
101+ result . emitSkipped = emitOutput . emitSkipped ;
102+ } ;
103+ ProjectCompiler . prototype . emitFile = function ( _a , currentDirectory ) {
104+ var file = _a . file , jsFileName = _a . jsFileName , dtsFileName = _a . dtsFileName , jsContent = _a . jsContent , dtsContent = _a . dtsContent , jsMapContent = _a . jsMapContent ;
92105 if ( ! jsFileName )
93106 return ;
94107 var base ;
@@ -129,6 +142,7 @@ var ProjectCompiler = (function () {
129142 var error = diagnostics_1 [ _i ] ;
130143 this . project . output . diagnostic ( error ) ;
131144 }
145+ return diagnostics . length ;
132146 } ;
133147 ProjectCompiler . prototype . removeSourceMapComment = function ( content ) {
134148 // By default the TypeScript automaticly inserts a source map comment.
0 commit comments