Skip to content

Commit fb3042c

Browse files
Merge branch 'master' into testPerf
Conflicts: src/harness/harness.ts tests/baselines/reference/noDefaultLib.errors.txt tests/baselines/reference/typeCheckTypeArgument.errors.txt
2 parents ca884d4 + 22a1f02 commit fb3042c

22 files changed

Lines changed: 388 additions & 250 deletions

src/compiler/checker.ts

Lines changed: 66 additions & 72 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ module ts {
349349

350350
return {
351351
options: getCompilerOptions(),
352-
fileNames: getFiles(),
352+
fileNames: getFileNames(),
353353
errors
354354
};
355355

@@ -395,23 +395,24 @@ module ts {
395395
return options;
396396
}
397397

398-
function getFiles(): string[] {
399-
var files: string[] = [];
398+
function getFileNames(): string[] {
399+
var fileNames: string[] = [];
400400
if (hasProperty(json, "files")) {
401401
if (json["files"] instanceof Array) {
402-
var files = map(<string[]>json["files"], s => combinePaths(basePath, s));
402+
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
403403
}
404404
}
405405
else {
406-
var sysFiles = host.readDirectory(basePath, ".ts");
406+
var exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
407+
var sysFiles = host.readDirectory(basePath, ".ts", exclude);
407408
for (var i = 0; i < sysFiles.length; i++) {
408409
var name = sysFiles[i];
409410
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
410-
files.push(name);
411+
fileNames.push(name);
411412
}
412413
}
413414
}
414-
return files;
415+
return fileNames;
415416
}
416417
}
417418
}

src/compiler/sys.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module ts {
1515
createDirectory(path: string): void;
1616
getExecutingFilePath(): string;
1717
getCurrentDirectory(): string;
18-
readDirectory(path: string, extension?: string): string[];
18+
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
1919
getMemoryUsage?(): number;
2020
exit(exitCode?: number): void;
2121
}
@@ -109,29 +109,38 @@ module ts {
109109
}
110110
}
111111

112-
function getNames(collection: any): string[] {
112+
function getCanonicalPath(path: string): string {
113+
return path.toLowerCase();
114+
}
115+
116+
function getNames(collection: any): string[]{
113117
var result: string[] = [];
114118
for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
115119
result.push(e.item().Name);
116120
}
117121
return result.sort();
118122
}
119123

120-
function readDirectory(path: string, extension?: string): string[] {
124+
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
121125
var result: string[] = [];
126+
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
122127
visitDirectory(path);
123128
return result;
124129
function visitDirectory(path: string) {
125130
var folder = fso.GetFolder(path || ".");
126131
var files = getNames(folder.files);
127-
for (let name of files) {
128-
if (!extension || fileExtensionIs(name, extension)) {
129-
result.push(combinePaths(path, name));
132+
for (let current of files) {
133+
let name = combinePaths(path, current);
134+
if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) {
135+
result.push(name);
130136
}
131137
}
132138
var subfolders = getNames(folder.subfolders);
133139
for (let current of subfolders) {
134-
visitDirectory(combinePaths(path, current));
140+
let name = combinePaths(path, current);
141+
if (!contains(exclude, getCanonicalPath(name))) {
142+
visitDirectory(name);
143+
}
135144
}
136145
}
137146
}
@@ -222,23 +231,30 @@ module ts {
222231
_fs.writeFileSync(fileName, data, "utf8");
223232
}
224233

225-
function readDirectory(path: string, extension?: string): string[] {
234+
function getCanonicalPath(path: string): string {
235+
return useCaseSensitiveFileNames ? path.toLowerCase() : path;
236+
}
237+
238+
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
226239
var result: string[] = [];
240+
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
227241
visitDirectory(path);
228242
return result;
229243
function visitDirectory(path: string) {
230244
var files = _fs.readdirSync(path || ".").sort();
231245
var directories: string[] = [];
232246
for (let current of files) {
233247
var name = combinePaths(path, current);
234-
var stat = _fs.statSync(name);
235-
if (stat.isFile()) {
236-
if (!extension || fileExtensionIs(name, extension)) {
237-
result.push(name);
248+
if (!contains(exclude, getCanonicalPath(name))) {
249+
var stat = _fs.statSync(name);
250+
if (stat.isFile()) {
251+
if (!extension || fileExtensionIs(name, extension)) {
252+
result.push(name);
253+
}
254+
}
255+
else if (stat.isDirectory()) {
256+
directories.push(name);
238257
}
239-
}
240-
else if (stat.isDirectory()) {
241-
directories.push(name);
242258
}
243259
}
244260
for (let current of directories) {

src/compiler/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ module ts {
11761176
}
11771177

11781178
export interface ParseConfigHost {
1179-
readDirectory(rootDir: string, extension: string): string[];
1179+
readDirectory(rootDir: string, extension: string, exclude: string[]): string[];
11801180
}
11811181

11821182
export interface WriteFileCallback {
@@ -1590,14 +1590,15 @@ module ts {
15901590
Tuple = 0x00002000, // Tuple
15911591
Union = 0x00004000, // Union
15921592
Anonymous = 0x00008000, // Anonymous
1593+
Instantiated = 0x00010000, // Instantiated anonymous type
15931594
/* @internal */
1594-
FromSignature = 0x00010000, // Created for signature assignment check
1595-
ObjectLiteral = 0x00020000, // Originates in an object literal
1595+
FromSignature = 0x00020000, // Created for signature assignment check
1596+
ObjectLiteral = 0x00040000, // Originates in an object literal
15961597
/* @internal */
1597-
ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type
1598+
ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type
15981599
/* @internal */
1599-
ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type
1600-
ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6
1600+
ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type
1601+
ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6
16011602

16021603
/* @internal */
16031604
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
@@ -1739,7 +1740,6 @@ module ts {
17391740
/* @internal */
17401741
export interface TypeMapper {
17411742
(t: TypeParameter): Type;
1742-
mappings?: Map<Type>; // Type mapping cache
17431743
}
17441744

17451745
/* @internal */

src/harness/harness.ts

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ module Harness {
900900
private compileOptions: ts.CompilerOptions;
901901
private settings: Harness.TestCaseParser.CompilerSetting[] = [];
902902

903-
private lastErrors: HarnessDiagnostic[];
903+
private lastErrors: ts.Diagnostic[];
904904

905905
public reset() {
906906
this.inputFiles = [];
@@ -985,19 +985,13 @@ module Harness {
985985
// always push the default lib in *last* to normalize the type/symbol baselines.
986986
programFiles.push(defaultLibFileName);
987987
}
988-
989-
var program = ts.createProgram(programFiles, options,
990-
createCompilerHost(inputFiles.concat(includeBuiltFiles).concat(otherFiles),
988+
var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(includeBuiltFiles).concat(otherFiles),
991989
(fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }),
992990
options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine));
993991

994992
var emitResult = program.emit();
995993

996-
var errors: HarnessDiagnostic[] = [];
997-
ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => {
998-
// TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now
999-
errors.push(getMinimalDiagnostic(err));
1000-
});
994+
var errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
1001995
this.lastErrors = errors;
1002996

1003997
var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps);
@@ -1114,10 +1108,6 @@ module Harness {
11141108
}
11151109
break;
11161110

1117-
case 'normalizenewline':
1118-
newLine = setting.value;
1119-
break;
1120-
11211111
case 'comments':
11221112
options.removeComments = setting.value === 'false';
11231113
break;
@@ -1248,70 +1238,50 @@ module Harness {
12481238
return normalized;
12491239
}
12501240

1251-
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
1252-
var errorLineInfo = err.file ? err.file.getLineAndCharacterOfPosition(err.start) : { line: -1, character: -1 };
1253-
return {
1254-
fileName: err.file && err.file.fileName,
1255-
start: err.start,
1256-
end: err.start + err.length,
1257-
line: errorLineInfo.line + 1,
1258-
character: errorLineInfo.character + 1,
1259-
message: ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine),
1260-
category: ts.DiagnosticCategory[err.category].toLowerCase(),
1261-
code: err.code
1262-
};
1263-
}
1264-
1265-
export function minimalDiagnosticsToString(diagnostics: HarnessDiagnostic[]) {
1241+
export function minimalDiagnosticsToString(diagnostics: ts.Diagnostic[]) {
12661242
// This is basically copied from tsc.ts's reportError to replicate what tsc does
12671243
var errorOutput = "";
1268-
ts.forEach(diagnostics, diagnotic => {
1269-
if (diagnotic.fileName) {
1270-
errorOutput += diagnotic.fileName + "(" + diagnotic.line + "," + diagnotic.character + "): ";
1244+
ts.forEach(diagnostics, diagnostic => {
1245+
if (diagnostic.file) {
1246+
var lineAndCharacter = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
1247+
errorOutput += diagnostic.file.fileName + "(" + (lineAndCharacter.line + 1) + "," + (lineAndCharacter.character + 1) + "): ";
12711248
}
12721249

1273-
errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + ts.sys.newLine;
1250+
errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
12741251
});
12751252

12761253
return errorOutput;
12771254
}
12781255

1279-
function compareDiagnostics(d1: HarnessDiagnostic, d2: HarnessDiagnostic) {
1280-
return ts.compareValues(d1.fileName, d2.fileName) ||
1281-
ts.compareValues(d1.start, d2.start) ||
1282-
ts.compareValues(d1.end, d2.end) ||
1283-
ts.compareValues(d1.code, d2.code) ||
1284-
ts.compareValues(d1.message, d2.message) ||
1285-
0;
1286-
}
1287-
1288-
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) {
1289-
diagnostics.sort(compareDiagnostics);
1256+
export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: ts.Diagnostic[]) {
1257+
diagnostics.sort(ts.compareDiagnostics);
12901258
var outputLines: string[] = [];
12911259
// Count up all the errors we find so we don't miss any
12921260
var totalErrorsReported = 0;
12931261

1294-
function outputErrorText(error: Harness.Compiler.HarnessDiagnostic) {
1295-
var errLines = RunnerBase.removeFullPaths(error.message)
1262+
function outputErrorText(error: ts.Diagnostic) {
1263+
var message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine);
1264+
1265+
var errLines = RunnerBase.removeFullPaths(message)
12961266
.split('\n')
12971267
.map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s)
12981268
.filter(s => s.length > 0)
1299-
.map(s => '!!! ' + error.category + " TS" + error.code + ": " + s);
1269+
.map(s => '!!! ' + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s);
13001270
errLines.forEach(e => outputLines.push(e));
13011271

13021272
totalErrorsReported++;
13031273
}
13041274

13051275
// Report global errors
1306-
var globalErrors = diagnostics.filter(err => !err.fileName);
1276+
var globalErrors = diagnostics.filter(err => !err.file);
13071277
globalErrors.forEach(outputErrorText);
13081278

13091279
// 'merge' the lines of each input file with any errors associated with it
13101280
inputFiles.filter(f => f.content !== undefined).forEach(inputFile => {
13111281
// Filter down to the errors in the file
13121282
var fileErrors = diagnostics.filter(e => {
1313-
var errFn = e.fileName;
1314-
return errFn && errFn === inputFile.unitName;
1283+
var errFn = e.file;
1284+
return errFn && errFn.fileName === inputFile.unitName;
13151285
});
13161286

13171287

@@ -1347,18 +1317,19 @@ module Harness {
13471317
outputLines.push(' ' + line);
13481318
fileErrors.forEach(err => {
13491319
// Does any error start or continue on to this line? Emit squiggles
1350-
if ((err.end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) {
1320+
let end = ts.textSpanEnd(err);
1321+
if ((end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) {
13511322
// How many characters from the start of this line the error starts at (could be positive or negative)
13521323
var relativeOffset = err.start - thisLineStart;
13531324
// How many characters of the error are on this line (might be longer than this line in reality)
1354-
var length = (err.end - err.start) - Math.max(0, thisLineStart - err.start);
1325+
var length = (end - err.start) - Math.max(0, thisLineStart - err.start);
13551326
// Calculate the start of the squiggle
13561327
var squiggleStart = Math.max(0, relativeOffset);
13571328
// TODO/REVIEW: this doesn't work quite right in the browser if a multi file test has files whose names are just the right length relative to one another
13581329
outputLines.push(' ' + line.substr(0, squiggleStart).replace(/[^\s]/g, ' ') + new Array(Math.min(length, line.length - squiggleStart) + 1).join('~'));
13591330

13601331
// If the error ended here, or we're at the end of the file, emit its message
1361-
if ((lineIndex === lines.length - 1) || nextLineStart > err.end) {
1332+
if ((lineIndex === lines.length - 1) || nextLineStart > end) {
13621333
// Just like above, we need to do a split on a string instead of on a regex
13631334
// because the JS engine does regexes wrong
13641335

@@ -1374,12 +1345,12 @@ module Harness {
13741345
});
13751346

13761347
var numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => {
1377-
return diagnostic.fileName && (isLibraryFile(diagnostic.fileName) || isBuiltFile(diagnostic.fileName));
1348+
return diagnostic.file && (isLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName));
13781349
});
13791350

13801351
var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => {
13811352
// Count an error generated from tests262-harness folder.This should only apply for test262
1382-
return diagnostic.fileName && diagnostic.fileName.indexOf("test262-harness") >= 0;
1353+
return diagnostic.file && diagnostic.file.fileName.indexOf("test262-harness") >= 0;
13831354
});
13841355

13851356
// Verify we didn't miss any errors in total
@@ -1433,17 +1404,6 @@ module Harness {
14331404
//harnessCompiler.compileString(code, unitName, callback);
14341405
}
14351406

1436-
export interface HarnessDiagnostic {
1437-
fileName: string;
1438-
start: number;
1439-
end: number;
1440-
line: number;
1441-
character: number;
1442-
message: string;
1443-
category: string;
1444-
code: number;
1445-
}
1446-
14471407
export interface GeneratedFile {
14481408
fileName: string;
14491409
code: string;
@@ -1473,12 +1433,12 @@ module Harness {
14731433
/** Contains the code and errors of a compilation and some helper methods to check its status. */
14741434
export class CompilerResult {
14751435
public files: GeneratedFile[] = [];
1476-
public errors: HarnessDiagnostic[] = [];
1436+
public errors: ts.Diagnostic[] = [];
14771437
public declFilesCode: GeneratedFile[] = [];
14781438
public sourceMaps: GeneratedFile[] = [];
14791439

14801440
/** @param fileResults an array of strings for the fileName and an ITextWriter with its code */
1481-
constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program,
1441+
constructor(fileResults: GeneratedFile[], errors: ts.Diagnostic[], public program: ts.Program,
14821442
public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) {
14831443

14841444
fileResults.forEach(emittedFile => {
@@ -1503,15 +1463,6 @@ module Harness {
15031463
return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files);
15041464
}
15051465
}
1506-
1507-
public isErrorAt(line: number, column: number, message: string) {
1508-
for (var i = 0; i < this.errors.length; i++) {
1509-
if ((this.errors[i].line + 1) === line && (this.errors[i].character + 1) === column && this.errors[i].message === message)
1510-
return true;
1511-
}
1512-
1513-
return false;
1514-
}
15151466
}
15161467
}
15171468

0 commit comments

Comments
 (0)