Skip to content

Commit f988a11

Browse files
Merge pull request #2949 from Microsoft/cleanupAndSpeedupFourslash
Cleanup and speedup fourslash
2 parents 4016206 + 97cd07d commit f988a11

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

Jakefile renamed to Jakefile.js

File renamed without changes.

src/compiler/program.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ module ts {
102102
};
103103
}
104104

105-
export function getPreEmitDiagnostics(program: Program): Diagnostic[] {
106-
let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics());
105+
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] {
106+
let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
107107

108108
if (program.getCompilerOptions().declaration) {
109-
diagnostics.concat(program.getDeclarationDiagnostics());
109+
diagnostics.concat(program.getDeclarationDiagnostics(sourceFile));
110110
}
111111

112112
return sortAndDeduplicateDiagnostics(diagnostics);

src/harness/fourslash.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,38 +2192,62 @@ module FourSlash {
21922192
xmlData.push(xml);
21932193
}
21942194

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+
21952210
export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): TestXmlData {
21962211
// Parse out the files and their metadata
2197-
var testData = parseTestData(basePath, content, fileName);
2212+
let testData = parseTestData(basePath, content, fileName);
21982213

21992214
currentTestState = new TestState(basePath, testType, testData);
22002215

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+
],
22042222
(fn, contents) => result = contents,
22052223
ts.ScriptTarget.Latest,
22062224
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);
22092225

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);
22112231
if (diagnostics.length > 0) {
22122232
throw new Error('Error compiling ' + fileName + ': ' +
22132233
diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n'));
22142234
}
2215-
program.emit();
2235+
2236+
program.emit(sourceFile);
22162237
result = result || ''; // Might have an empty fourslash file
22172238

2239+
result = fourslashJsOutput + "\r\n" + result;
2240+
22182241
// Compile and execute the test
22192242
try {
22202243
eval(result);
2221-
} catch (err) {
2244+
}
2245+
catch (err) {
22222246
// Debugging: FourSlash.currentTestState.printCurrentFileState();
22232247
throw err;
22242248
}
22252249

2226-
var xmlData = currentTestState.getTestXmlData();
2250+
let xmlData = currentTestState.getTestXmlData();
22272251
xmlData.originalName = fileName;
22282252
return xmlData;
22292253
}

src/harness/runner.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
/// <reference path='rwcRunner.ts' />
2121

2222
function runTests(runners: RunnerBase[]) {
23-
if (reverse) {
24-
runners = runners.reverse();
25-
}
2623
for (var i = iterations; i > 0; i--) {
2724
for (var j = 0; j < runners.length; j++) {
2825
runners[j].initializeTests();
@@ -31,8 +28,6 @@ function runTests(runners: RunnerBase[]) {
3128
}
3229

3330
var runners: RunnerBase[] = [];
34-
global.runners = runners;
35-
var reverse: boolean = false;
3631
var iterations: number = 1;
3732

3833
// 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 !== '') {
7873
case 'test262':
7974
runners.push(new Test262BaselineRunner());
8075
break;
81-
case 'reverse':
82-
reverse = true;
83-
break;
8476
}
8577
}
8678
}

0 commit comments

Comments
 (0)