Merge branch 'master' into octal

This commit is contained in:
Jason Freeman
2014-08-07 12:11:13 -07:00
23 changed files with 240 additions and 99 deletions

View File

@@ -3844,21 +3844,40 @@ module ts {
}
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
// A nit here is that we reorder only signatures that belong to the same symbol,
// so order how inherited signatures are processed is still preserved.
// interface A { (x: string): void }
// interface B extends A { (x: 'foo'): string }
// var b: B;
// b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
function collectCandidates(node: CallExpression, signatures: Signature[]): Signature[]{
var result: Signature[] = [];
var lastParent: Node;
var lastSymbol: Symbol;
var cutoffPos: number = 0;
var pos: number;
for (var i = 0; i < signatures.length; i++) {
var signature = signatures[i];
if (isCandidateSignature(node, signature)) {
var parent = signature.declaration ? signature.declaration.parent : undefined;
if (lastParent && parent === lastParent) {
pos++;
var symbol = signature.declaration && getSymbolOfNode(signature.declaration);
var parent = signature.declaration && signature.declaration.parent;
if (!lastSymbol || symbol === lastSymbol) {
if (lastParent && parent === lastParent) {
pos++;
}
else {
lastParent = parent;
pos = cutoffPos;
}
}
else {
// current declaration belongs to a different symbol
// set cutoffPos so reorderings in the future won't change result set from 0 to cutoffPos
pos = cutoffPos = result.length;
lastParent = parent;
pos = 0;
}
lastSymbol = symbol;
for (var j = result.length; j > pos; j--) {
result[j] = result[j - 1];
}

View File

@@ -23,6 +23,10 @@ module ts {
name: "diagnostics",
type: "boolean",
},
{
name: "emitBOM",
type: "boolean"
},
{
name: "help",
shortName: "h",

View File

@@ -157,8 +157,8 @@ module ts {
return text.substring(skipTrivia(text, node.pos), node.end);
}
function writeFile(filename: string, data: string) {
compilerHost.writeFile(filename, data, hostErrorMessage => {
function writeFile(filename: string, data: string, writeByteOrderMark: boolean) {
compilerHost.writeFile(filename, data, writeByteOrderMark, hostErrorMessage => {
diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
});
}
@@ -426,7 +426,7 @@ module ts {
sourceMapNameIndices.pop();
};
function writeJavaScriptAndSourceMapFile(emitOutput: string) {
function writeJavaScriptAndSourceMapFile(emitOutput: string, writeByteOrderMark: boolean) {
// Write source map file
encodeLastRecordedSourceMapSpan();
writeFile(sourceMapData.sourceMapFilePath, JSON.stringify({
@@ -436,11 +436,11 @@ module ts {
sources: sourceMapData.sourceMapSources,
names: sourceMapData.sourceMapNames,
mappings: sourceMapData.sourceMapMappings
}));
}), /*writeByteOrderMark*/ false);
sourceMapDataList.push(sourceMapData);
// Write sourcemap url to the js file and write the js file
writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL);
writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark);
}
// Initialize source map data
@@ -513,8 +513,8 @@ module ts {
scopeEmitEnd = recordScopeNameEnd;
}
function writeJavaScriptFile(emitOutput: string) {
writeFile(jsFilePath, emitOutput);
function writeJavaScriptFile(emitOutput: string, writeByteOrderMark: boolean) {
writeFile(jsFilePath, emitOutput, writeByteOrderMark);
}
function emitTokenText(tokenKind: SyntaxKind, startPos: number, emitFn?: () => void) {
@@ -1854,7 +1854,7 @@ module ts {
}
writeLine();
writeEmittedFiles(writer.getText());
writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM);
}
function emitDeclarations(jsFilePath: string, root?: SourceFile) {
@@ -2448,7 +2448,7 @@ module ts {
// TODO(shkamat): Should we not write any declaration file if any of them can produce error,
// or should we just not write this file like we are doing now
if (!reportedDeclarationError) {
writeFile(getModuleNameFromFilename(jsFilePath) + ".d.ts", referencePathsOutput + writer.getText());
writeFile(getModuleNameFromFilename(jsFilePath) + ".d.ts", referencePathsOutput + writer.getText(), compilerOptions.emitBOM);
}
}

View File

@@ -417,7 +417,7 @@ module ts {
nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext;
}
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, byteOrderMark: ByteOrderMark, version: number = 0, isOpen: boolean = false): SourceFile {
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: number = 0, isOpen: boolean = false): SourceFile {
var file: SourceFile;
var scanner: Scanner;
var token: SyntaxKind;
@@ -3556,7 +3556,6 @@ module ts {
file.nodeCount = nodeCount;
file.identifierCount = identifierCount;
file.version = version;
file.byteOrderMark = byteOrderMark;
file.isOpen = isOpen;
file.languageVersion = languageVersion;
return file;

View File

@@ -6,7 +6,7 @@ interface System {
useCaseSensitiveFileNames: boolean;
write(s: string): void;
readFile(fileName: string, encoding?: string): string;
writeFile(fileName: string, data: string): void;
writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void;
watchFile?(fileName: string, callback: (fileName: string) => void): FileWatcher;
resolvePath(path: string): string;
fileExists(path: string): boolean;
@@ -75,15 +75,21 @@ var sys: System = (function () {
}
}
function writeFile(fileName: string, data: string): void {
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
fileStream.Open();
binaryStream.Open();
try {
// Write characters in UTF-8 encoding
fileStream.Charset = "utf-8";
fileStream.WriteText(data);
// Skip byte order mark and copy remaining data to binary stream
fileStream.Position = 3;
// If we don't want the BOM, then skip it by setting the starting location to 3 (size of BOM).
// If not, start from position 0, as the BOM will be added automatically when charset==utf8.
if (writeByteOrderMark) {
fileStream.Position = 0;
}
else {
fileStream.Position = 3;
}
fileStream.CopyTo(binaryStream);
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
}
@@ -175,7 +181,12 @@ var sys: System = (function () {
return buffer.toString("utf8");
}
function writeFile(fileName: string, data: string): void {
function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
// If a BOM is required, emit one
if (writeByteOrderMark) {
data = '\uFEFF' + data;
}
_fs.writeFileSync(fileName, data, "utf8");
}

View File

@@ -142,10 +142,10 @@ module ts {
}
text = "";
}
return text !== undefined ? createSourceFile(filename, text, languageVersion, ByteOrderMark.None) : undefined;
return text !== undefined ? createSourceFile(filename, text, languageVersion) : undefined;
}
function writeFile(fileName: string, data: string, onError?: (message: string) => void) {
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
function directoryExists(directoryPath: string): boolean {
if (hasProperty(existingDirectories, directoryPath)) {
@@ -168,7 +168,7 @@ module ts {
try {
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
sys.writeFile(fileName, data);
sys.writeFile(fileName, data, writeByteOrderMark);
}
catch (e) {
if (onError) onError(e.message);

View File

@@ -525,7 +525,6 @@ module ts {
nodeCount: number;
identifierCount: number;
symbolCount: number;
byteOrderMark: ByteOrderMark;
isOpen: boolean;
version: number;
languageVersion: ScriptTarget;
@@ -940,6 +939,7 @@ module ts {
codepage?: number;
declaration?: boolean;
diagnostics?: boolean;
emitBOM?: boolean;
help?: boolean;
locale?: string;
mapRoot?: string;
@@ -1131,17 +1131,10 @@ module ts {
getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
getDefaultLibFilename(): string;
getCancellationToken? (): CancellationToken;
writeFile(filename: string, data: string, onError?: (message: string) => void): void;
writeFile(filename: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
useCaseSensitiveFileNames(): boolean;
getNewLine(): string;
}
export enum ByteOrderMark {
None = 0,
Utf8 = 1,
Utf16BigEndian = 2,
Utf16LittleEndian = 3,
}
}