diff --git a/Jakefile b/Jakefile.js similarity index 100% rename from Jakefile rename to Jakefile.js diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4c8daf8aa06..cc2fe7ff190 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -102,11 +102,11 @@ module ts { }; } - export function getPreEmitDiagnostics(program: Program): Diagnostic[] { - let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] { + let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile)); if (program.getCompilerOptions().declaration) { - diagnostics.concat(program.getDeclarationDiagnostics()); + diagnostics.concat(program.getDeclarationDiagnostics(sourceFile)); } return sortAndDeduplicateDiagnostics(diagnostics); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7269b2db75d..c8f20746a07 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2192,38 +2192,62 @@ module FourSlash { xmlData.push(xml); } + // We don't want to recompile 'fourslash.ts' for every test, so + // here we cache the JS output and reuse it for every test. + let fourslashJsOutput: string; + { + let host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined }], + (fn, contents) => fourslashJsOutput = contents, + ts.ScriptTarget.Latest, + ts.sys.useCaseSensitiveFileNames); + + let program = ts.createProgram([Harness.Compiler.fourslashFileName], { noResolve: true, target: ts.ScriptTarget.ES3 }, host); + + program.emit(host.getSourceFile(Harness.Compiler.fourslashFileName, ts.ScriptTarget.ES3)); + } + + export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): TestXmlData { // Parse out the files and their metadata - var testData = parseTestData(basePath, content, fileName); + let testData = parseTestData(basePath, content, fileName); currentTestState = new TestState(basePath, testType, testData); - var result = ''; - var host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined }, - { unitName: fileName, content: content }], + let result = ''; + let host = Harness.Compiler.createCompilerHost( + [ + { unitName: Harness.Compiler.fourslashFileName, content: undefined }, + { unitName: fileName, content: content } + ], (fn, contents) => result = contents, ts.ScriptTarget.Latest, ts.sys.useCaseSensitiveFileNames); - // TODO (drosen): We need to enforce checking on these tests. - var program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host); - var diagnostics = ts.getPreEmitDiagnostics(program); + let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host); + + let sourceFile = host.getSourceFile(fileName, ts.ScriptTarget.ES3); + + let diagnostics = ts.getPreEmitDiagnostics(program, sourceFile); if (diagnostics.length > 0) { throw new Error('Error compiling ' + fileName + ': ' + diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); } - program.emit(); + + program.emit(sourceFile); result = result || ''; // Might have an empty fourslash file + result = fourslashJsOutput + "\r\n" + result; + // Compile and execute the test try { eval(result); - } catch (err) { + } + catch (err) { // Debugging: FourSlash.currentTestState.printCurrentFileState(); throw err; } - var xmlData = currentTestState.getTestXmlData(); + let xmlData = currentTestState.getTestXmlData(); xmlData.originalName = fileName; return xmlData; } diff --git a/src/harness/runner.ts b/src/harness/runner.ts index e1e5429b007..37451639d75 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -20,9 +20,6 @@ /// function runTests(runners: RunnerBase[]) { - if (reverse) { - runners = runners.reverse(); - } for (var i = iterations; i > 0; i--) { for (var j = 0; j < runners.length; j++) { runners[j].initializeTests(); @@ -31,8 +28,6 @@ function runTests(runners: RunnerBase[]) { } var runners: RunnerBase[] = []; -global.runners = runners; -var reverse: boolean = false; var iterations: number = 1; // users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options @@ -78,9 +73,6 @@ if (testConfigFile !== '') { case 'test262': runners.push(new Test262BaselineRunner()); break; - case 'reverse': - reverse = true; - break; } } }