mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Merge pull request #2949 from Microsoft/cleanupAndSpeedupFourslash
Cleanup and speedup fourslash
This commit is contained in:
commit
f988a11cfc
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -20,9 +20,6 @@
|
||||
/// <reference path='rwcRunner.ts' />
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user