mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Split symbol baselines from type baselines.
This commit is contained in:
@@ -270,29 +270,53 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
// These types are equivalent, but depend on what order the compiler observed
|
||||
// certain parts of the program.
|
||||
|
||||
var fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
|
||||
var pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
|
||||
let allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
|
||||
|
||||
var fullTypes = generateTypes(fullWalker);
|
||||
var pullTypes = generateTypes(pullWalker);
|
||||
let fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
|
||||
let pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
|
||||
|
||||
if (fullTypes !== pullTypes) {
|
||||
Harness.Baseline.runBaseline('Correct full expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
|
||||
Harness.Baseline.runBaseline('Correct pull expression types for ' + fileName, justName.replace(/\.ts/, '.types.pull'), () => pullTypes);
|
||||
}
|
||||
else {
|
||||
Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
|
||||
let fullResults: ts.Map<TypeWriterResult[]> = {};
|
||||
let pullResults: ts.Map<TypeWriterResult[]> = {};
|
||||
|
||||
for (let sourceFile of allFiles) {
|
||||
fullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
|
||||
pullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
|
||||
}
|
||||
|
||||
function generateTypes(walker: TypeWriterWalker): string {
|
||||
var allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
|
||||
var typeLines: string[] = [];
|
||||
var typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
|
||||
// Produce baselines. The first gives the types for all expressions.
|
||||
// The second gives symbols for all identifiers.
|
||||
checkBaseLines(/*isSymbolBaseLine:*/ false);
|
||||
checkBaseLines(/*isSymbolBaseLine:*/ true);
|
||||
|
||||
function checkBaseLines(isSymbolBaseLine: boolean) {
|
||||
let fullBaseLine = generateBaseLine(fullResults, isSymbolBaseLine);
|
||||
let pullBaseLine = generateBaseLine(pullResults, isSymbolBaseLine);
|
||||
|
||||
let fullExtension = isSymbolBaseLine ? '.symbols' : '.types';
|
||||
let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull';
|
||||
|
||||
if (fullBaseLine !== pullBaseLine) {
|
||||
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
|
||||
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.ts/, pullExtension), () => pullBaseLine);
|
||||
}
|
||||
else {
|
||||
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
|
||||
}
|
||||
}
|
||||
|
||||
function generateBaseLine(typeWriterResults: ts.Map<TypeWriterResult[]>, isSymbolBaseline: boolean): string {
|
||||
let typeLines: string[] = [];
|
||||
let typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
|
||||
|
||||
allFiles.forEach(file => {
|
||||
var codeLines = file.content.split('\n');
|
||||
walker.getTypes(file.unitName).forEach(result => {
|
||||
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + result.type;
|
||||
typeWriterResults[file.unitName].forEach(result => {
|
||||
if (isSymbolBaseline && !result.symbol) {
|
||||
return;
|
||||
}
|
||||
|
||||
var typeOrSymbolString = isSymbolBaseline ? result.symbol : result.type;
|
||||
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + typeOrSymbolString;
|
||||
if (!typeMap[file.unitName]) {
|
||||
typeMap[file.unitName] = {};
|
||||
}
|
||||
@@ -316,11 +340,13 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
typeLines.push('>' + ty + '\r\n');
|
||||
});
|
||||
if (i + 1 < codeLines.length && (codeLines[i + 1].match(/^\s*[{|}]\s*$/) || codeLines[i + 1].trim() === '')) {
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
typeLines.push('\r\n');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
typeLines.push('No type information for this code.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ interface TypeWriterResult {
|
||||
syntaxKind: number;
|
||||
sourceText: string;
|
||||
type: string;
|
||||
symbol: string;
|
||||
}
|
||||
|
||||
class TypeWriterWalker {
|
||||
@@ -19,7 +20,7 @@ class TypeWriterWalker {
|
||||
: program.getTypeChecker();
|
||||
}
|
||||
|
||||
public getTypes(fileName: string): TypeWriterResult[] {
|
||||
public getTypeAndSymbols(fileName: string): TypeWriterResult[] {
|
||||
var sourceFile = this.program.getSourceFile(fileName);
|
||||
this.currentSourceFile = sourceFile;
|
||||
this.results = [];
|
||||
@@ -45,8 +46,9 @@ class TypeWriterWalker {
|
||||
var symbol = this.checker.getSymbolAtLocation(node);
|
||||
|
||||
var typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation);
|
||||
var symbolString: string;
|
||||
if (symbol) {
|
||||
var symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
|
||||
symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
|
||||
if (symbol.declarations) {
|
||||
for (let declaration of symbol.declarations) {
|
||||
symbolString += ", ";
|
||||
@@ -56,15 +58,14 @@ class TypeWriterWalker {
|
||||
}
|
||||
}
|
||||
symbolString += ")";
|
||||
|
||||
typeString += ", " + symbolString;
|
||||
}
|
||||
|
||||
this.results.push({
|
||||
line: lineAndCharacter.line,
|
||||
syntaxKind: node.kind,
|
||||
sourceText: sourceText,
|
||||
type: typeString
|
||||
type: typeString,
|
||||
symbol: symbolString
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user