mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 21:07:52 -05:00
Merge branch 'master' into bom
This commit is contained in:
@@ -152,7 +152,31 @@ module ts {
|
||||
|
||||
export function mapToArray<T>(map: Map<T>): T[] {
|
||||
var result: T[] = [];
|
||||
for (var id in map) result.push(map[id]);
|
||||
|
||||
for (var id in map) {
|
||||
result.push(map[id]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a map from the elements of an array.
|
||||
*
|
||||
* @param array the array of input elements.
|
||||
* @param makeKey a function that produces a key for a given element.
|
||||
*
|
||||
* This function makes no effort to avoid collisions; if any two elements produce
|
||||
* the same key with the given 'makeKey' function, then the element with the higher
|
||||
* index in the array will be the one associated with the produced key.
|
||||
*/
|
||||
export function arrayToMap<T>(array: T[], makeKey: (value: T) => string): Map<T> {
|
||||
var result: Map<T> = {};
|
||||
|
||||
forEach(array, value => {
|
||||
result[makeKey(value)] = value
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -245,14 +245,14 @@ module ts {
|
||||
|
||||
function addWatchers(program: Program) {
|
||||
forEach(program.getSourceFiles(), f => {
|
||||
var filename = f.filename;
|
||||
var filename = getCanonicalName(f.filename);
|
||||
watchers[filename] = sys.watchFile(filename, fileUpdated);
|
||||
});
|
||||
}
|
||||
|
||||
function removeWatchers(program: Program) {
|
||||
forEach(program.getSourceFiles(), f => {
|
||||
var filename = f.filename;
|
||||
var filename = getCanonicalName(f.filename);
|
||||
if (hasProperty(watchers, filename)) {
|
||||
watchers[filename].close();
|
||||
}
|
||||
@@ -264,8 +264,7 @@ module ts {
|
||||
// Fired off whenever a file is changed.
|
||||
function fileUpdated(filename: string) {
|
||||
var firstNotification = isEmpty(updatedFiles);
|
||||
|
||||
updatedFiles[filename] = true;
|
||||
updatedFiles[getCanonicalName(filename)] = true;
|
||||
|
||||
// Only start this off when the first file change comes in,
|
||||
// so that we can batch up all further changes.
|
||||
@@ -285,8 +284,10 @@ module ts {
|
||||
// specified since the last compilation cycle.
|
||||
removeWatchers(program);
|
||||
|
||||
// Gets us syntactically correct files from the last compilation.
|
||||
var getUnmodifiedSourceFile = program.getSourceFile;
|
||||
// Reuse source files from the last compilation so long as they weren't changed.
|
||||
var oldSourceFiles = arrayToMap(
|
||||
filter(program.getSourceFiles(), file => !hasProperty(changedFiles, getCanonicalName(file.filename))),
|
||||
file => getCanonicalName(file.filename));
|
||||
|
||||
// We create a new compiler host for this compilation cycle.
|
||||
// This new host is effectively the same except that 'getSourceFile'
|
||||
@@ -294,11 +295,11 @@ module ts {
|
||||
// so long as they were not modified.
|
||||
var newCompilerHost = clone(compilerHost);
|
||||
newCompilerHost.getSourceFile = (fileName, languageVersion, onError) => {
|
||||
if (!hasProperty(changedFiles, fileName)) {
|
||||
var sourceFile = getUnmodifiedSourceFile(fileName);
|
||||
if (sourceFile) {
|
||||
return sourceFile;
|
||||
}
|
||||
fileName = getCanonicalName(fileName);
|
||||
|
||||
var sourceFile = lookUp(oldSourceFiles, fileName);
|
||||
if (sourceFile) {
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
return compilerHost.getSourceFile(fileName, languageVersion, onError);
|
||||
@@ -308,6 +309,10 @@ module ts {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
|
||||
addWatchers(program);
|
||||
}
|
||||
|
||||
function getCanonicalName(fileName: string) {
|
||||
return compilerHost.getCanonicalFileName(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) {
|
||||
|
||||
@@ -8,13 +8,11 @@ module perftest {
|
||||
|
||||
export interface IO {
|
||||
getOut(): string;
|
||||
getErr(): string;
|
||||
}
|
||||
|
||||
export var readFile = sys.readFile;
|
||||
var writeFile = sys.writeFile;
|
||||
export var write = sys.write;
|
||||
export var writeErr = sys.writeErr;
|
||||
var resolvePath = sys.resolvePath;
|
||||
export var getExecutingFilePath = sys.getExecutingFilePath;
|
||||
export var getCurrentDirectory = sys.getCurrentDirectory;
|
||||
@@ -22,12 +20,12 @@ module perftest {
|
||||
var args = sys.args;
|
||||
|
||||
// augment sys so first ts.executeCommandLine call will be finish silently
|
||||
sys.writeErr = (s: string) => { };
|
||||
sys.write = (s: string) => { };
|
||||
sys.args = []
|
||||
|
||||
export function restoreSys() {
|
||||
sys.args = args;
|
||||
sys.writeErr = writeErr;
|
||||
sys.write = write;
|
||||
}
|
||||
|
||||
export function hasLogIOFlag() {
|
||||
@@ -96,11 +94,9 @@ module perftest {
|
||||
var err: string = "";
|
||||
|
||||
sys.write = (s: string) => { out += s; };
|
||||
sys.writeErr = (s: string) => { err += s; };
|
||||
|
||||
return {
|
||||
getOut: () => out,
|
||||
getErr: () => err
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,14 @@ if (perftest.hasLogIOFlag()) {
|
||||
var compilerHost: ts.CompilerHost = {
|
||||
getSourceFile: (s, v) => {
|
||||
var content = perftest.readFile(s);
|
||||
return content !== undefined ? ts.createSourceFile(s, content, v) : undefined;
|
||||
return content !== undefined ? ts.createSourceFile(s, content, v, ts.ByteOrderMark.Utf8) : undefined;
|
||||
},
|
||||
getDefaultLibFilename: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"),
|
||||
writeFile: (f: string, content: string) => { throw new Error("Unexpected operation: writeFile"); },
|
||||
getCurrentDirectory: () => perftest.getCurrentDirectory(),
|
||||
getCanonicalFileName: getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames
|
||||
getCanonicalFileName: ts.getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
getNewLine: () => sys.newLine
|
||||
};
|
||||
|
||||
var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag());
|
||||
@@ -26,5 +27,4 @@ else {
|
||||
var io = perftest.prepare();
|
||||
ts.executeCommandLine(perftest.getArgsWithoutIOLogFile());
|
||||
perftest.write(io.getOut());
|
||||
perftest.writeErr(io.getErr());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user