diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 31449c88e3a..6a4aaad9f93 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -39,7 +39,7 @@ function main(): void { function buildUniqueNameMap(names: string[]): IIndexable { var nameMap: IIndexable = {}; - var uniqueNames = NameGenerator.ensureUniqueness(names, /*isFixed */ undefined, /* isCaseSensitive */ false); + var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined); for (var i = 0; i < names.length; i++) { nameMap[names[i]] = uniqueNames[i]; @@ -94,14 +94,17 @@ function convertPropertyName(origName: string): string { } module NameGenerator { - export function ensureUniqueness(names: string[], isFixed: boolean[] = names.map(() => false), isCaseSensitive: boolean = false): string[] { + export function ensureUniqueness(names: string[], isCaseSensitive: boolean, isFixed?: boolean[]): string[]{ + if (!isFixed) { + isFixed = names.map(() => false) + } - var names = names.map(x => x); - ensureUniquenessInPlace(names, isFixed, isCaseSensitive); + var names = names.slice(); + ensureUniquenessInPlace(names, isCaseSensitive, isFixed); return names; } - function ensureUniquenessInPlace(names: string[], isFixed: boolean[], isCaseSensitive: boolean): void { + function ensureUniquenessInPlace(names: string[], isCaseSensitive: boolean, isFixed: boolean[]): void { for (var i = 0; i < names.length; i++) { var name = names[i]; var collisionIndices = Utilities.collectMatchingIndices(name, names, isCaseSensitive); @@ -128,9 +131,12 @@ module NameGenerator { } while (true) { - var newName = name + suffix++; + var newName = name + suffix; + suffix++; - if (!proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) { + // Check if we've synthesized a unique name, and if so + // replace the conflicting name with the new one. + if (!proposedNames.some(name => Utilities.stringEquals(name, newName, isCaseSensitive))) { proposedNames[collisionIndex] = newName; break; } @@ -141,7 +147,7 @@ module NameGenerator { module Utilities { /// Return a list of all indices where a string occurs. - export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = false): number[] { + export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] { var matchingIndices: number[] = []; for (var i = 0; i < proposedNames.length; i++) { @@ -153,7 +159,7 @@ module Utilities { return matchingIndices; } - export function stringEquals(s1: string, s2: string, caseSensitive: boolean = false): boolean { + export function stringEquals(s1: string, s2: string, caseSensitive: boolean): boolean { if (caseSensitive) { s1 = s1.toLowerCase(); s2 = s2.toLowerCase(); diff --git a/src/compiler/tc.ts b/src/compiler/tc.ts index d38aca5a055..614a20aa21a 100644 --- a/src/compiler/tc.ts +++ b/src/compiler/tc.ts @@ -186,33 +186,28 @@ module ts { } export function executeCommandLine(args: string[]): void { - var exitCode = 0; var commandLine = parseCommandLine(args); if (commandLine.options.locale) { validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } - // Report all errors at this point, even if there are none. + // If there are any errors due to command line parsing and/or + // setting up localization, report them and quit. if (commandLine.errors.length > 0) { reportDiagnostics(commandLine.errors); - exitCode = 1; + sys.exit(1); } if (commandLine.options.version) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version)); - sys.exit(exitCode); + sys.exit(0); } if (commandLine.options.help || commandLine.filenames.length === 0) { printVersion(); printHelp(); - sys.exit(exitCode); - } - - // If we encountered an error before we even started compiling, just bail out. - if (exitCode !== 0) { - sys.exit(exitCode); + sys.exit(0); } var defaultCompilerHost = createCompilerHost(commandLine.options); @@ -411,18 +406,14 @@ module ts { descriptionColumn.push(getDiagnosticText(option.description)); // Set the new margin for the description column if necessary. - if (usageText.length > marginLength) { - marginLength = usageText.length; - } + marginLength = Math.max(usageText.length, marginLength); } // Special case that can't fit in the loop. var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; usageColumn.push(usageText); descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file)); - if (usageText.length > marginLength) { - marginLength = usageText.length; - } + marginLength = Math.max(usageText.length, marginLength); // Print out each row, aligning all the descriptions on the same column. for (var i = 0; i < usageColumn.length; i++) {