@@ -312,17 +312,17 @@ module ts {
312312 } ;
313313 }
314314
315- function getSourceFilePathInNewDir ( sourceFile : SourceFile , program : Program , newDirPath : string ) {
316- var compilerHost = program . getCompilerHost ( ) ;
315+ function getSourceFilePathInNewDir ( sourceFile : SourceFile , host : EmitHost , newDirPath : string ) {
316+ var compilerHost = host . getCompilerHost ( ) ;
317317 var sourceFilePath = getNormalizedAbsolutePath ( sourceFile . filename , compilerHost . getCurrentDirectory ( ) ) ;
318- sourceFilePath = sourceFilePath . replace ( program . getCommonSourceDirectory ( ) , "" ) ;
318+ sourceFilePath = sourceFilePath . replace ( host . getCommonSourceDirectory ( ) , "" ) ;
319319 return combinePaths ( newDirPath , sourceFilePath ) ;
320320 }
321321
322- function getOwnEmitOutputFilePath ( sourceFile : SourceFile , program : Program , extension : string ) {
323- var compilerOptions = program . getCompilerOptions ( ) ;
322+ function getOwnEmitOutputFilePath ( sourceFile : SourceFile , host : EmitHost , extension : string ) {
323+ var compilerOptions = host . getCompilerOptions ( ) ;
324324 if ( compilerOptions . outDir ) {
325- var emitOutputFilePathWithoutExtension = removeFileExtension ( getSourceFilePathInNewDir ( sourceFile , program , compilerOptions . outDir ) ) ;
325+ var emitOutputFilePathWithoutExtension = removeFileExtension ( getSourceFilePathInNewDir ( sourceFile , host , compilerOptions . outDir ) ) ;
326326 }
327327 else {
328328 var emitOutputFilePathWithoutExtension = removeFileExtension ( sourceFile . filename ) ;
@@ -337,10 +337,10 @@ module ts {
337337 } ) ;
338338 }
339339
340- function emitDeclarations ( program : Program , resolver : EmitResolver , diagnostics : Diagnostic [ ] , jsFilePath : string , root ?: SourceFile ) : DeclarationEmit {
341- var newLine = program . getCompilerHost ( ) . getNewLine ( ) ;
342- var compilerOptions = program . getCompilerOptions ( ) ;
343- var compilerHost = program . getCompilerHost ( ) ;
340+ function emitDeclarations ( host : EmitHost , resolver : EmitResolver , diagnostics : Diagnostic [ ] , jsFilePath : string , root ?: SourceFile ) : DeclarationEmit {
341+ var newLine = host . getCompilerHost ( ) . getNewLine ( ) ;
342+ var compilerOptions = host . getCompilerOptions ( ) ;
343+ var compilerHost = host . getCompilerHost ( ) ;
344344
345345 var write : ( s : string ) => void ;
346346 var writeLine : ( ) => void ;
@@ -1396,8 +1396,8 @@ module ts {
13961396 var declFileName = referencedFile . flags & NodeFlags . DeclarationFile
13971397 ? referencedFile . filename // Declaration file, use declaration file name
13981398 : shouldEmitToOwnFile ( referencedFile , compilerOptions )
1399- ? getOwnEmitOutputFilePath ( referencedFile , program , ".d.ts" ) // Own output file so get the .d.ts file
1400- : removeFileExtension ( compilerOptions . out ) + ".d.ts" ; // Global out file
1399+ ? getOwnEmitOutputFilePath ( referencedFile , host , ".d.ts" ) // Own output file so get the .d.ts file
1400+ : removeFileExtension ( compilerOptions . out ) + ".d.ts" ; // Global out file
14011401
14021402 declFileName = getRelativePathToDirectoryOrUrl (
14031403 getDirectoryPath ( normalizeSlashes ( jsFilePath ) ) ,
@@ -1414,7 +1414,7 @@ module ts {
14141414 if ( ! compilerOptions . noResolve ) {
14151415 var addedGlobalFileReference = false ;
14161416 forEach ( root . referencedFiles , fileReference => {
1417- var referencedFile = tryResolveScriptReference ( program , root , fileReference ) ;
1417+ var referencedFile = tryResolveScriptReference ( host , root , fileReference ) ;
14181418
14191419 // All the references that are not going to be part of same file
14201420 if ( referencedFile && ( ( referencedFile . flags & NodeFlags . DeclarationFile ) || // This is a declare file reference
@@ -1434,12 +1434,12 @@ module ts {
14341434 else {
14351435 // Emit references corresponding to this file
14361436 var emittedReferencedFiles : SourceFile [ ] = [ ] ;
1437- forEach ( program . getSourceFiles ( ) , sourceFile => {
1437+ forEach ( host . getSourceFiles ( ) , sourceFile => {
14381438 if ( ! isExternalModuleOrDeclarationFile ( sourceFile ) ) {
14391439 // Check what references need to be added
14401440 if ( ! compilerOptions . noResolve ) {
14411441 forEach ( sourceFile . referencedFiles , fileReference => {
1442- var referencedFile = tryResolveScriptReference ( program , sourceFile , fileReference ) ;
1442+ var referencedFile = tryResolveScriptReference ( host , sourceFile , fileReference ) ;
14431443
14441444 // If the reference file is a declaration file or an external module, emit that reference
14451445 if ( referencedFile && ( isExternalModuleOrDeclarationFile ( referencedFile ) &&
@@ -1472,13 +1472,13 @@ module ts {
14721472 }
14731473
14741474 // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
1475- export function emitFiles ( resolver : EmitResolver , targetSourceFile ?: SourceFile ) : EmitResult {
1476- var program = resolver . getProgram ( ) ;
1477- var compilerHost = program . getCompilerHost ( ) ;
1478- var compilerOptions = program . getCompilerOptions ( ) ;
1475+ export function emitFiles ( resolver : EmitResolver , host : EmitHost , targetSourceFile ?: SourceFile ) : EmitResult {
1476+ // var program = resolver.getProgram();
1477+ var compilerHost = host . getCompilerHost ( ) ;
1478+ var compilerOptions = host . getCompilerOptions ( ) ;
14791479 var sourceMapDataList : SourceMapData [ ] = compilerOptions . sourceMap ? [ ] : undefined ;
14801480 var diagnostics : Diagnostic [ ] = [ ] ;
1481- var newLine = program . getCompilerHost ( ) . getNewLine ( ) ;
1481+ var newLine = compilerHost . getNewLine ( ) ;
14821482
14831483 function emitJavaScript ( jsFilePath : string , root ?: SourceFile ) {
14841484 var writer = createTextWriter ( newLine ) ;
@@ -1700,7 +1700,7 @@ module ts {
17001700 // Add the file to tsFilePaths
17011701 // If sourceroot option: Use the relative path corresponding to the common directory path
17021702 // otherwise source locations relative to map file location
1703- var sourcesDirectoryPath = compilerOptions . sourceRoot ? program . getCommonSourceDirectory ( ) : sourceMapDir ;
1703+ var sourcesDirectoryPath = compilerOptions . sourceRoot ? host . getCommonSourceDirectory ( ) : sourceMapDir ;
17041704
17051705 sourceMapData . sourceMapSources . push ( getRelativePathToDirectoryOrUrl ( sourcesDirectoryPath ,
17061706 node . filename ,
@@ -1840,12 +1840,12 @@ module ts {
18401840 if ( root ) { // emitting single module file
18411841 // For modules or multiple emit files the mapRoot will have directory structure like the sources
18421842 // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map
1843- sourceMapDir = getDirectoryPath ( getSourceFilePathInNewDir ( root , program , sourceMapDir ) ) ;
1843+ sourceMapDir = getDirectoryPath ( getSourceFilePathInNewDir ( root , host , sourceMapDir ) ) ;
18441844 }
18451845
18461846 if ( ! isRootedDiskPath ( sourceMapDir ) && ! isUrl ( sourceMapDir ) ) {
18471847 // The relative paths are relative to the common directory
1848- sourceMapDir = combinePaths ( program . getCommonSourceDirectory ( ) , sourceMapDir ) ;
1848+ sourceMapDir = combinePaths ( host . getCommonSourceDirectory ( ) , sourceMapDir ) ;
18491849 sourceMapData . jsSourceMappingURL = getRelativePathToDirectoryOrUrl (
18501850 getDirectoryPath ( normalizePath ( jsFilePath ) ) , // get the relative sourceMapDir path based on jsFilePath
18511851 combinePaths ( sourceMapDir , sourceMapData . jsSourceMappingURL ) , // this is where user expects to see sourceMap
@@ -4101,7 +4101,7 @@ module ts {
41014101 emit ( root ) ;
41024102 }
41034103 else {
4104- forEach ( program . getSourceFiles ( ) , sourceFile => {
4104+ forEach ( host . getSourceFiles ( ) , sourceFile => {
41054105 if ( ! isExternalModuleOrDeclarationFile ( sourceFile ) ) {
41064106 emit ( sourceFile ) ;
41074107 }
@@ -4113,7 +4113,7 @@ module ts {
41134113 }
41144114
41154115 function writeDeclarationFile ( jsFilePath : string , sourceFile : SourceFile ) {
4116- var emitDeclarationResult = emitDeclarations ( program , resolver , diagnostics , jsFilePath , sourceFile ) ;
4116+ var emitDeclarationResult = emitDeclarations ( host , resolver , diagnostics , jsFilePath , sourceFile ) ;
41174117 // TODO(shkamat): Should we not write any declaration file if any of them can produce error,
41184118 // or should we just not write this file like we are doing now
41194119 if ( ! emitDeclarationResult . reportedDeclarationError ) {
@@ -4140,9 +4140,9 @@ module ts {
41404140 hasSemanticErrors = resolver . hasSemanticErrors ( ) ;
41414141 isEmitBlocked = resolver . isEmitBlocked ( ) ;
41424142
4143- forEach ( program . getSourceFiles ( ) , sourceFile => {
4143+ forEach ( host . getSourceFiles ( ) , sourceFile => {
41444144 if ( shouldEmitToOwnFile ( sourceFile , compilerOptions ) ) {
4145- var jsFilePath = getOwnEmitOutputFilePath ( sourceFile , program , ".js" ) ;
4145+ var jsFilePath = getOwnEmitOutputFilePath ( sourceFile , host , ".js" ) ;
41464146 emitFile ( jsFilePath , sourceFile ) ;
41474147 }
41484148 } ) ;
@@ -4158,13 +4158,13 @@ module ts {
41584158 hasSemanticErrors = resolver . hasSemanticErrors ( targetSourceFile ) ;
41594159 isEmitBlocked = resolver . isEmitBlocked ( targetSourceFile ) ;
41604160
4161- var jsFilePath = getOwnEmitOutputFilePath ( targetSourceFile , program , ".js" ) ;
4161+ var jsFilePath = getOwnEmitOutputFilePath ( targetSourceFile , host , ".js" ) ;
41624162 emitFile ( jsFilePath , targetSourceFile ) ;
41634163 }
41644164 else if ( ! isDeclarationFile ( targetSourceFile ) && compilerOptions . out ) {
41654165 // Otherwise, if --out is specified and targetSourceFile is not a declaration file,
41664166 // Emit all, non-external-module file, into one single output file
4167- forEach ( program . getSourceFiles ( ) , sourceFile => {
4167+ forEach ( host . getSourceFiles ( ) , sourceFile => {
41684168 if ( ! shouldEmitToOwnFile ( sourceFile , compilerOptions ) ) {
41694169 hasSemanticErrors = hasSemanticErrors || resolver . hasSemanticErrors ( sourceFile ) ;
41704170 isEmitBlocked = isEmitBlocked || resolver . isEmitBlocked ( sourceFile ) ;
0 commit comments