Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dfee3de
Add test case for #8229
sheetalkamat Apr 21, 2016
90d347e
Do not report errors during contextual typecheck
sheetalkamat Apr 21, 2016
34f7f2c
Handle the scenario when let [a=undefined]=[]
sheetalkamat Apr 22, 2016
448a480
Don't allow `.ts` to appear in an import
Jul 12, 2016
a8c05a9
Add specific error message for unwanted '.ts' extension
Jul 12, 2016
95e391e
Allow `await` in a simple unary expression
Jul 22, 2016
bc5c7b6
More tests
Jul 22, 2016
275dbc7
Forbid `await await`
Jul 22, 2016
52fd033
Allow `await await`
Jul 25, 2016
2821d98
Merge branch 'master' into no_ts_extension
Aug 2, 2016
0f134ed
Improve error message
Aug 2, 2016
359c8b1
Don't allow ".d.ts" extension in an import either.
Aug 3, 2016
3de8c22
Merge branch 'master' into no_ts_extension
Aug 15, 2016
2eb159e
Rename 'find' functions
Aug 15, 2016
02f908a
Merge branch 'master' into noImplicitAnyDestructuring
sheetalkamat Aug 16, 2016
8fc17af
Move supportedTypescriptExtensionsWithDtsFirst next to supportedTypeS…
Aug 18, 2016
952d2fe
Fix comment
Aug 18, 2016
a621c09
Merge pull request #8241 from Microsoft/noImplicitAnyDestructuring
mhegazy Aug 18, 2016
03dcdda
Treat special property access symbol differently
Aug 19, 2016
297cb50
Merge branch 'master' into no_ts_extension
Aug 19, 2016
b452469
Fix tests
Aug 19, 2016
b482fa5
Merge branch 'master' into cast_of_await
Aug 19, 2016
19cde06
Merge pull request #9890 from Microsoft/cast_of_await
Aug 19, 2016
d2d5d42
Merge pull request #9646 from Microsoft/no_ts_extension
Aug 19, 2016
7f6e36c
Update shim version to be 2.1 (#10424)
yuit Aug 19, 2016
0168ab2
Check return code paths on getters (#10102)
weswigham Aug 19, 2016
da6d951
Remove extraneous arguments from harness's runBaseline (#10419)
weswigham Aug 19, 2016
6c60e5b
Remove needless call to basename
RyanCavanaugh Aug 19, 2016
def29f6
Merge pull request #10439 from RyanCavanaugh/fixJakeBaselineAccept
RyanCavanaugh Aug 19, 2016
8ad2744
Refactor baseliners out of compiler runner (#10440)
weswigham Aug 19, 2016
057357b
CR feedback
Aug 19, 2016
a5bb13f
fix broken tests
Aug 19, 2016
a531b87
Pass in baselineOpts into types baselines so that RWC baselines can b…
yuit Aug 20, 2016
d8ab098
Merge pull request #10426 from zhengbli/9518
zhengbli Aug 20, 2016
5732908
Merge branch 'master' into release-2.0
Aug 20, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor baseliners out of compiler runner (#10440)
  • Loading branch information
weswigham authored Aug 19, 2016
commit 8ad2744e9a7d0d7eb30286f0b6718b7b5f6cc4f9
222 changes: 7 additions & 215 deletions src/harness/compilerRunner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference path="harness.ts" />
/// <reference path="runnerbase.ts" />
/// <reference path="typeWriter.ts" />
// In harness baselines, null is different than undefined. See `generateActual` in `harness.ts`.
/* tslint:disable:no-null-keyword */

const enum CompilerTestType {
Conformance,
Expand Down Expand Up @@ -136,21 +134,10 @@ class CompilerBaselineRunner extends RunnerBase {
otherFiles = undefined;
});

function getByteOrderMarkText(file: Harness.Compiler.GeneratedFile): string {
return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "";
}

function getErrorBaseline(toBeCompiled: Harness.Compiler.TestFile[], otherFiles: Harness.Compiler.TestFile[], result: Harness.Compiler.CompilerResult) {
return Harness.Compiler.getErrorBaseline(toBeCompiled.concat(otherFiles), result.errors);
}

// check errors
it("Correct errors for " + fileName, () => {
if (this.errors) {
Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".errors.txt"), (): string => {
if (result.errors.length === 0) return null;
return getErrorBaseline(toBeCompiled, otherFiles, result);
});
Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors);
}
});

Expand All @@ -168,8 +155,10 @@ class CompilerBaselineRunner extends RunnerBase {
Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => {
const record = result.getSourceMapRecord();
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn"t required.
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required.
/* tslint:disable:no-null-keyword */
return null;
/* tslint:enable:no-null-keyword */
}
return record;
});
Expand All @@ -178,217 +167,20 @@ class CompilerBaselineRunner extends RunnerBase {

it("Correct JS output for " + fileName, () => {
if (hasNonDtsFiles && this.emit) {
if (!options.noEmit && result.files.length === 0 && result.errors.length === 0) {
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");
}

// check js output
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, ".js"), () => {
let tsCode = "";
const tsSources = otherFiles.concat(toBeCompiled);
if (tsSources.length > 1) {
tsCode += "//// [" + fileName + "] ////\r\n\r\n";
}
for (let i = 0; i < tsSources.length; i++) {
tsCode += "//// [" + Harness.Path.getFileName(tsSources[i].unitName) + "]\r\n";
tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? "\r\n" : "");
}

let jsCode = "";
for (let i = 0; i < result.files.length; i++) {
jsCode += "//// [" + Harness.Path.getFileName(result.files[i].fileName) + "]\r\n";
jsCode += getByteOrderMarkText(result.files[i]);
jsCode += result.files[i].code;
}

if (result.declFilesCode.length > 0) {
jsCode += "\r\n\r\n";
for (let i = 0; i < result.declFilesCode.length; i++) {
jsCode += "//// [" + Harness.Path.getFileName(result.declFilesCode[i].fileName) + "]\r\n";
jsCode += getByteOrderMarkText(result.declFilesCode[i]);
jsCode += result.declFilesCode[i].code;
}
}

const declFileCompilationResult =
Harness.Compiler.compileDeclarationFiles(
toBeCompiled, otherFiles, result, harnessSettings, options, /*currentDirectory*/ undefined);

if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) {
jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n";
jsCode += "\r\n\r\n";
jsCode += getErrorBaseline(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles, declFileCompilationResult.declResult);
}

if (jsCode.length > 0) {
return tsCode + "\r\n\r\n" + jsCode;
}
else {
return null;
}
});
Harness.Compiler.doJsEmitBaseline(justName, fileName, options, result, toBeCompiled, otherFiles, harnessSettings);
}
});

it("Correct Sourcemap output for " + fileName, () => {
if (options.inlineSourceMap) {
if (result.sourceMaps.length > 0) {
throw new Error("No sourcemap files should be generated if inlineSourceMaps was set.");
}
return null;
}
else if (options.sourceMap) {
if (result.sourceMaps.length !== result.files.length) {
throw new Error("Number of sourcemap files should be same as js files.");
}

Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, ".js.map"), () => {
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
// We need to return null here or the runBaseLine will actually create a empty file.
// Baselining isn't required here because there is no output.
return null;
}

let sourceMapCode = "";
for (let i = 0; i < result.sourceMaps.length; i++) {
sourceMapCode += "//// [" + Harness.Path.getFileName(result.sourceMaps[i].fileName) + "]\r\n";
sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]);
sourceMapCode += result.sourceMaps[i].code;
}

return sourceMapCode;
});
}
Harness.Compiler.doSourcemapBaseline(justName, options, result);
});

it("Correct type/symbol baselines for " + fileName, () => {
if (fileName.indexOf("APISample") >= 0) {
return;
}

// NEWTODO: Type baselines
if (result.errors.length !== 0) {
return;
}

// The full walker simulates the types that you would get from doing a full
// compile. The pull walker simulates the types you get when you just do
// a type query for a random node (like how the LS would do it). Most of the
// time, these will be the same. However, occasionally, they can be different.
// Specifically, when the compiler internally depends on symbol IDs to order
// things, then we may see different results because symbols can be created in a
// different order with 'pull' operations, and thus can produce slightly differing
// output.
//
// For example, with a full type check, we may see a type displayed as: number | string
// But with a pull type check, we may see it as: string | number
//
// These types are equivalent, but depend on what order the compiler observed
// certain parts of the program.

const program = result.program;
const allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));

const fullWalker = new TypeWriterWalker(program, /*fullTypeCheck*/ true);

const fullResults = ts.createMap<TypeWriterResult[]>();
const pullResults = ts.createMap<TypeWriterResult[]>();

for (const sourceFile of allFiles) {
fullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
pullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
}

// Produce baselines. The first gives the types for all expressions.
// The second gives symbols for all identifiers.
let e1: Error, e2: Error;
try {
checkBaseLines(/*isSymbolBaseLine*/ false);
}
catch (e) {
e1 = e;
}

try {
checkBaseLines(/*isSymbolBaseLine*/ true);
}
catch (e) {
e2 = e;
}

if (e1 || e2) {
throw e1 || e2;
}

return;

function checkBaseLines(isSymbolBaseLine: boolean) {
const fullBaseLine = generateBaseLine(fullResults, isSymbolBaseLine);
const pullBaseLine = generateBaseLine(pullResults, isSymbolBaseLine);

const fullExtension = isSymbolBaseLine ? ".symbols" : ".types";
const pullExtension = isSymbolBaseLine ? ".symbols.pull" : ".types.pull";

if (fullBaseLine !== pullBaseLine) {
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine);
}
else {
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
}
}

function generateBaseLine(typeWriterResults: ts.Map<TypeWriterResult[]>, isSymbolBaseline: boolean): string {
const typeLines: string[] = [];
const typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};

allFiles.forEach(file => {
const codeLines = file.content.split("\n");
typeWriterResults[file.unitName].forEach(result => {
if (isSymbolBaseline && !result.symbol) {
return;
}

const typeOrSymbolString = isSymbolBaseline ? result.symbol : result.type;
const formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + typeOrSymbolString;
if (!typeMap[file.unitName]) {
typeMap[file.unitName] = {};
}

let typeInfo = [formattedLine];
const existingTypeInfo = typeMap[file.unitName][result.line];
if (existingTypeInfo) {
typeInfo = existingTypeInfo.concat(typeInfo);
}
typeMap[file.unitName][result.line] = typeInfo;
});

typeLines.push("=== " + file.unitName + " ===\r\n");
for (let i = 0; i < codeLines.length; i++) {
const currentCodeLine = codeLines[i];
typeLines.push(currentCodeLine + "\r\n");
if (typeMap[file.unitName]) {
const typeInfo = typeMap[file.unitName][i];
if (typeInfo) {
typeInfo.forEach(ty => {
typeLines.push(">" + ty + "\r\n");
});
if (i + 1 < codeLines.length && (codeLines[i + 1].match(/^\s*[{|}]\s*$/) || codeLines[i + 1].trim() === "")) {
}
else {
typeLines.push("\r\n");
}
}
}
else {
typeLines.push("No type information for this code.");
}
}
});

return typeLines.join("");
}

Harness.Compiler.doTypeAndSymbolBaseline(justName, result, toBeCompiled.concat(otherFiles).filter(file => !!result.program.getSourceFile(file.unitName)));
});
});
}
Expand Down
Loading