@@ -183,19 +183,40 @@ class CompilerBaselineRunner extends RunnerBase {
183
183
184
184
// if the .d.ts is non-empty, confirm it compiles correctly as well
185
185
if ( options . declaration && result . errors . length === 0 && result . declFilesCode . length > 0 ) {
186
- function getDtsFile ( file : { unitName : string ; content : string } ) {
186
+ function addDtsFile ( file : { unitName : string ; content : string } , dtsFiles : { unitName : string ; content : string } [ ] ) {
187
187
if ( Harness . Compiler . isDTS ( file . unitName ) ) {
188
- return file ;
189
- } else {
190
- var declFile = ts . forEach ( result . declFilesCode ,
191
- declFile => declFile . fileName === ( file . unitName . substr ( 0 , file . unitName . length - ".ts" . length ) + ".d.ts" )
188
+ dtsFiles . push ( file ) ;
189
+ }
190
+ else {
191
+ var declFile = findResultCodeFile ( file . unitName ) ;
192
+ // Look if there is --out file corresponding to this ts file
193
+ if ( ! declFile && options . out ) {
194
+ declFile = findResultCodeFile ( options . out ) ;
195
+ if ( ! declFile || findUnit ( declFile . fileName , declToBeCompiled ) ||
196
+ findUnit ( declFile . fileName , declOtherFiles ) ) {
197
+ return ;
198
+ }
199
+ }
200
+
201
+ if ( declFile ) {
202
+ dtsFiles . push ( { unitName : declFile . fileName , content : declFile . code } ) ;
203
+ return ;
204
+ }
205
+ }
206
+
207
+ function findResultCodeFile ( fileName : string ) {
208
+ return ts . forEach ( result . declFilesCode ,
209
+ declFile => declFile . fileName === ( fileName . substr ( 0 , fileName . length - ".ts" . length ) + ".d.ts" )
192
210
? declFile : undefined ) ;
193
- return { unitName : declFile . fileName , content : declFile . code } ;
211
+ }
212
+
213
+ function findUnit ( fileName : string , units : { unitName : string ; content : string } [ ] ) {
214
+ return ts . forEach ( units , unit => unit . unitName === fileName ? unit : undefined ) ;
194
215
}
195
216
}
196
217
197
- ts . forEach ( toBeCompiled , file => { declToBeCompiled . push ( getDtsFile ( file ) ) ; } ) ;
198
- ts . forEach ( otherFiles , file => { declOtherFiles . push ( getDtsFile ( file ) ) ; } ) ;
218
+ ts . forEach ( toBeCompiled , file => addDtsFile ( file , declToBeCompiled ) ) ;
219
+ ts . forEach ( otherFiles , file => addDtsFile ( file , declOtherFiles ) ) ;
199
220
harnessCompiler . compileFiles ( declToBeCompiled , declOtherFiles , function ( compileResult ) {
200
221
declResult = compileResult ;
201
222
} , function ( settings ) {
0 commit comments