@@ -15,6 +15,13 @@ module ts {
15
15
getIndent ( ) : number ;
16
16
}
17
17
18
+ interface aliasDeclaration {
19
+ declaration : ImportDeclaration ;
20
+ outputPos : number ;
21
+ indent : number ;
22
+ asynchronousOutput ?: string ; // If the output for alias was written asynchronously, the corresponding output
23
+ }
24
+
18
25
var indentStrings : string [ ] = [ "" , " " ] ;
19
26
export function getIndentString ( level : number ) {
20
27
if ( indentStrings [ level ] === undefined ) {
@@ -326,12 +333,7 @@ module ts {
326
333
327
334
var emitJsDocComments = compilerOptions . removeComments ? function ( declaration : Declaration ) { } : writeJsDocComments ;
328
335
329
- var aliasDeclarationEmitInfo : {
330
- declaration : ImportDeclaration ;
331
- outputPos : number ;
332
- indent : number ;
333
- asynchronousOutput ?: string ; // If the output for alias was written asynchronously, the corresponding output
334
- } [ ] = [ ] ;
336
+ var aliasDeclarationEmitInfo : aliasDeclaration [ ] = [ ] ;
335
337
336
338
var getSymbolVisibilityDiagnosticMessage : ( symbolAccesibilityResult : SymbolAccessiblityResult ) => {
337
339
errorNode : Node ;
@@ -1213,26 +1215,29 @@ module ts {
1213
1215
}
1214
1216
} ) ;
1215
1217
}
1216
-
1217
- // TODO(shkamat): Should we not write any declaration file if any of them can produce error,
1218
- // or should we just not write this file like we are doing now
1219
- if ( ! reportedDeclarationError ) {
1220
- var declarationOutput = referencePathsOutput ;
1221
- var synchronousDeclarationOutput = writer . getText ( ) ;
1222
- // apply additions
1223
- var appliedSyncOutputPos = 0 ;
1224
- forEach ( aliasDeclarationEmitInfo , aliasEmitInfo => {
1225
- if ( aliasEmitInfo . asynchronousOutput ) {
1226
- declarationOutput += synchronousDeclarationOutput . substring ( appliedSyncOutputPos , aliasEmitInfo . outputPos ) ;
1227
- declarationOutput += aliasEmitInfo . asynchronousOutput ;
1228
- appliedSyncOutputPos = aliasEmitInfo . outputPos ;
1229
- }
1230
- } ) ;
1231
- declarationOutput += synchronousDeclarationOutput . substring ( appliedSyncOutputPos ) ;
1232
- writeFile ( compilerHost , diagnostics , removeFileExtension ( jsFilePath ) + ".d.ts" , declarationOutput , compilerOptions . emitBOM ) ;
1218
+ return {
1219
+ reportedDeclarationError : reportedDeclarationError ,
1220
+ aliasDeclarationEmitInfo : aliasDeclarationEmitInfo ,
1221
+ synchronousDeclarationOutput : writer . getText ( ) ,
1222
+ declarationOutput : referencePathsOutput ,
1233
1223
}
1234
1224
}
1235
1225
1226
+ function writeDeclarationToFile ( compilerHost : CompilerHost , compilerOptions : CompilerOptions , diagnostics : Diagnostic [ ] , aliasDeclarationEmitInfo : aliasDeclaration [ ] ,
1227
+ synchronousDeclarationOutput : string , jsFilePath : string , declarationOutput : string ) {
1228
+ // apply additions
1229
+ var appliedSyncOutputPos = 0 ;
1230
+ forEach ( aliasDeclarationEmitInfo , aliasEmitInfo => {
1231
+ if ( aliasEmitInfo . asynchronousOutput ) {
1232
+ declarationOutput += synchronousDeclarationOutput . substring ( appliedSyncOutputPos , aliasEmitInfo . outputPos ) ;
1233
+ declarationOutput += aliasEmitInfo . asynchronousOutput ;
1234
+ appliedSyncOutputPos = aliasEmitInfo . outputPos ;
1235
+ }
1236
+ } ) ;
1237
+ declarationOutput += synchronousDeclarationOutput . substring ( appliedSyncOutputPos ) ;
1238
+ writeFile ( compilerHost , diagnostics , removeFileExtension ( jsFilePath ) + ".d.ts" , declarationOutput , compilerOptions . emitBOM ) ;
1239
+ }
1240
+
1236
1241
export function getDeclarationDiagnostics ( program : Program , resolver : EmitResolver , targetSourceFile : SourceFile ) : Diagnostic [ ] {
1237
1242
var diagnostics : Diagnostic [ ] = [ ] ;
1238
1243
var jsFilePath = getOwnEmitOutputFilePath ( targetSourceFile , program , ".js" ) ;
@@ -3252,7 +3257,13 @@ module ts {
3252
3257
function emitFile ( jsFilePath : string , sourceFile ?: SourceFile ) {
3253
3258
emitJavaScript ( jsFilePath , sourceFile ) ;
3254
3259
if ( ! hasSemanticErrors && compilerOptions . declaration ) {
3255
- emitDeclarations ( program , resolver , diagnostics , jsFilePath , sourceFile ) ;
3260
+ var emitDeclarationResult = emitDeclarations ( program , resolver , diagnostics , jsFilePath , sourceFile ) ;
3261
+ // TODO(shkamat): Should we not write any declaration file if any of them can produce error,
3262
+ // or should we just not write this file like we are doing now
3263
+ if ( ! emitDeclarationResult . reportedDeclarationError ) {
3264
+ writeDeclarationToFile ( compilerHost , compilerOptions , diagnostics , emitDeclarationResult . aliasDeclarationEmitInfo , emitDeclarationResult . synchronousDeclarationOutput ,
3265
+ jsFilePath , emitDeclarationResult . declarationOutput ) ;
3266
+ }
3256
3267
}
3257
3268
}
3258
3269
0 commit comments