@@ -2192,38 +2192,62 @@ module FourSlash {
2192
2192
xmlData . push ( xml ) ;
2193
2193
}
2194
2194
2195
+ // We don't want to recompile 'fourslash.ts' for every test, so
2196
+ // here we cache the JS output and reuse it for every test.
2197
+ let fourslashJsOutput : string ;
2198
+ {
2199
+ let host = Harness . Compiler . createCompilerHost ( [ { unitName : Harness . Compiler . fourslashFileName , content : undefined } ] ,
2200
+ ( fn , contents ) => fourslashJsOutput = contents ,
2201
+ ts . ScriptTarget . Latest ,
2202
+ ts . sys . useCaseSensitiveFileNames ) ;
2203
+
2204
+ let program = ts . createProgram ( [ Harness . Compiler . fourslashFileName ] , { noResolve : true , target : ts . ScriptTarget . ES3 } , host ) ;
2205
+
2206
+ program . emit ( host . getSourceFile ( Harness . Compiler . fourslashFileName , ts . ScriptTarget . ES3 ) ) ;
2207
+ }
2208
+
2209
+
2195
2210
export function runFourSlashTestContent ( basePath : string , testType : FourSlashTestType , content : string , fileName : string ) : TestXmlData {
2196
2211
// Parse out the files and their metadata
2197
- var testData = parseTestData ( basePath , content , fileName ) ;
2212
+ let testData = parseTestData ( basePath , content , fileName ) ;
2198
2213
2199
2214
currentTestState = new TestState ( basePath , testType , testData ) ;
2200
2215
2201
- var result = '' ;
2202
- var host = Harness . Compiler . createCompilerHost ( [ { unitName : Harness . Compiler . fourslashFileName , content : undefined } ,
2203
- { unitName : fileName , content : content } ] ,
2216
+ let result = '' ;
2217
+ let host = Harness . Compiler . createCompilerHost (
2218
+ [
2219
+ { unitName : Harness . Compiler . fourslashFileName , content : undefined } ,
2220
+ { unitName : fileName , content : content }
2221
+ ] ,
2204
2222
( fn , contents ) => result = contents ,
2205
2223
ts . ScriptTarget . Latest ,
2206
2224
ts . sys . useCaseSensitiveFileNames ) ;
2207
- // TODO (drosen): We need to enforce checking on these tests.
2208
- var program = ts . createProgram ( [ Harness . Compiler . fourslashFileName , fileName ] , { out : "fourslashTestOutput.js" , noResolve : true , target : ts . ScriptTarget . ES3 } , host ) ;
2209
2225
2210
- var diagnostics = ts . getPreEmitDiagnostics ( program ) ;
2226
+ let program = ts . createProgram ( [ Harness . Compiler . fourslashFileName , fileName ] , { out : "fourslashTestOutput.js" , noResolve : true , target : ts . ScriptTarget . ES3 } , host ) ;
2227
+
2228
+ let sourceFile = host . getSourceFile ( fileName , ts . ScriptTarget . ES3 ) ;
2229
+
2230
+ let diagnostics = ts . getPreEmitDiagnostics ( program , sourceFile ) ;
2211
2231
if ( diagnostics . length > 0 ) {
2212
2232
throw new Error ( 'Error compiling ' + fileName + ': ' +
2213
2233
diagnostics . map ( e => ts . flattenDiagnosticMessageText ( e . messageText , ts . sys . newLine ) ) . join ( '\r\n' ) ) ;
2214
2234
}
2215
- program . emit ( ) ;
2235
+
2236
+ program . emit ( sourceFile ) ;
2216
2237
result = result || '' ; // Might have an empty fourslash file
2217
2238
2239
+ result = fourslashJsOutput + "\r\n" + result ;
2240
+
2218
2241
// Compile and execute the test
2219
2242
try {
2220
2243
eval ( result ) ;
2221
- } catch ( err ) {
2244
+ }
2245
+ catch ( err ) {
2222
2246
// Debugging: FourSlash.currentTestState.printCurrentFileState();
2223
2247
throw err ;
2224
2248
}
2225
2249
2226
- var xmlData = currentTestState . getTestXmlData ( ) ;
2250
+ let xmlData = currentTestState . getTestXmlData ( ) ;
2227
2251
xmlData . originalName = fileName ;
2228
2252
return xmlData ;
2229
2253
}
0 commit comments