@@ -20,26 +20,26 @@ module.exports = class TypeScriptCompiler extends JSCompiler
2020 @prettyName = " TypeScript - http://www.typescriptlang.org"
2121 @defaultExtensions = [" ts" ]
2222
23- constructor : (config , @extensions ) ->
23+ constructor : (@ config , @extensions ) ->
2424 super ()
2525
2626 @defaultLibPath = path .join __dirname , " assets" , " lib.d.ts"
2727
2828 @compilationSettings = new TypeScript.CompilationSettings ()
2929 @compilationSettings .codeGenTarget = TypeScript .CodeGenTarget .ES5
30- @compilationSettings .errorRecovery = true
30+ @compilationSettings .errorRecovery = true
3131
32- if config .typescript ? .module ?
33- if config .typescript .module is " commonjs"
32+ if @ config .typescript ? .module ?
33+ if @ config .typescript .module is " commonjs"
3434 TypeScript .moduleGenTarget = TypeScript .ModuleGenTarget .Synchronous
35- else if config .typescript .module is " amd"
35+ else if @ config .typescript .module is " amd"
3636 TypeScript .moduleGenTarget = TypeScript .ModuleGenTarget .Asynchronous
3737
3838 compile : (file , cb ) ->
3939
40- targetJsFile = file .inputFileName . substr ( 0 , file . inputFileName . length - 3 ) + ' .js ' ;
41- targetJsFile = io .resolvePath (targetJsFile);
42- targetJsFile = TypeScript .switchToForwardSlashes (targetJsFile);
40+ targetJsFile = file .outputFileName . replace ( @config . watch . compiledDir , @config . watch . sourceDir )
41+ targetJsFile = io .resolvePath (targetJsFile)
42+ targetJsFile = TypeScript .switchToForwardSlashes (targetJsFile)
4343
4444 outText = " "
4545 targetScriptAssembler =
@@ -59,23 +59,23 @@ module.exports = class TypeScriptCompiler extends JSCompiler
5959 Close : ->
6060
6161 emitterIOHost =
62- createFile : (fileName , useUTF8 ) ->
63- if fileName is targetJsFile
64- return targetScriptAssembler
65- else
66- return depScriptWriter
67- directoryExists : io .directoryExists
68- fileExists : io .fileExists
69- resolvePath : io .resolvePath
62+ createFile : (fileName , useUTF8 ) ->
63+ if fileName is targetJsFile
64+ targetScriptAssembler
65+ else
66+ depScriptWriter
67+ directoryExists : io .directoryExists
68+ fileExists : io .fileExists
69+ resolvePath : io .resolvePath
7070
7171 preEnv = new TypeScript.CompilationEnvironment (@compilationSettings , io)
7272 resolver = new TypeScript.CodeResolver (preEnv)
7373 resolvedEnv = new TypeScript.CompilationEnvironment (@compilationSettings , io)
7474 compiler = new TypeScript.TypeScriptCompiler (stderr, new TypeScript.NullLogger (), @compilationSettings )
7575 compiler .setErrorOutput (stderr)
76-
76+
7777 if @compilationSettings .errorRecovery
78- compiler .parser .setErrorRecovery (stderr)
78+ compiler .parser .setErrorRecovery (stderr)
7979
8080 code = new TypeScript.SourceUnit (@defaultLibPath , null )
8181 preEnv .code .push (code)
@@ -86,38 +86,38 @@ module.exports = class TypeScriptCompiler extends JSCompiler
8686 resolvedPaths = {}
8787
8888 resolutionDispatcher =
89- postResolutionError : (errorFile , line , col , errorMessage ) ->
90- stderr .WriteLine (errorFile + " ( " + line + " , " + col + " ) " + (errorMessage == " " ? " " : " : " + errorMessage))
91- postResolution : (path , code ) ->
92- if ( ! resolvedPaths[path])
93- resolvedEnv .code .push (code)
94- resolvedPaths[path] = true
89+ postResolutionError : (errorFile , line , col , errorMessage ) ->
90+ stderr .WriteLine (" #{ errorFile} ( #{ line} , #{ col} ) " + (errorMessage == " " ? " " : " : " + errorMessage))
91+ postResolution : (path , code ) ->
92+ if ! resolvedPaths[path]
93+ resolvedEnv .code .push (code)
94+ resolvedPaths[path] = true
9595
9696 for i in [0 .. preEnv .code .length - 1 ] by 1
97- path = TypeScript .switchToForwardSlashes (io .resolvePath (preEnv .code [i].path ))
98- resolver .resolveCode (path, " " , false , resolutionDispatcher)
99-
97+ path = TypeScript .switchToForwardSlashes (io .resolvePath (preEnv .code [i].path ))
98+ resolver .resolveCode (path, " " , false , resolutionDispatcher)
99+
100100 for iCode in [0 .. resolvedEnv .code .length - 1 ] by 1
101- code = resolvedEnv .code [iCode];
102- if ( code .content != null )
103- compiler .addUnit (code .content , code .path , false , code .referencedFiles )
101+ code = resolvedEnv .code [iCode];
102+ unless code .content is null
103+ compiler .addUnit (code .content , code .path , false , code .referencedFiles )
104104
105105 try
106106 compiler .typeCheck ()
107107 mapInputToOutput = (unitIndex , outFile ) ->
108- preEnv .inputOutputMap [unitIndex] = outFile
108+ preEnv .inputOutputMap [unitIndex] = outFile
109109 compiler .emit emitterIOHost, mapInputToOutput
110110 catch err
111- compiler .errorReporter .hasErrors = true ;
112-
113- error = if errorMessage .length > 0
111+ compiler .errorReporter .hasErrors = true
112+
113+ error = if errorMessage .length > 0
114114 new Error (errorMessage)
115115 else
116116 null
117117
118118 if / . d. ts$ / .test (file .inputFileName ) and outText is " "
119- outText = undefined
120- unless error
121- logger .success " Compiled [[ " + file .inputFileName + " ]]"
122-
119+ outText = undefined
120+ unless error
121+ logger .success " Compiled [[ " + file .inputFileName + " ]]"
122+
123123 cb (error, outText)
0 commit comments