Skip to content

Commit 348d0fc

Browse files
Addressed code review feedback.
1 parent a64db42 commit 348d0fc

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

scripts/processDiagnosticMessages.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function main(): void {
3939
function buildUniqueNameMap(names: string[]): IIndexable<string> {
4040
var nameMap: IIndexable<string> = {};
4141

42-
var uniqueNames = NameGenerator.ensureUniqueness(names, /*isFixed */ undefined, /* isCaseSensitive */ false);
42+
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
4343

4444
for (var i = 0; i < names.length; i++) {
4545
nameMap[names[i]] = uniqueNames[i];
@@ -94,14 +94,17 @@ function convertPropertyName(origName: string): string {
9494
}
9595

9696
module NameGenerator {
97-
export function ensureUniqueness(names: string[], isFixed: boolean[] = names.map(() => false), isCaseSensitive: boolean = false): string[] {
97+
export function ensureUniqueness(names: string[], isCaseSensitive: boolean, isFixed?: boolean[]): string[]{
98+
if (!isFixed) {
99+
isFixed = names.map(() => false)
100+
}
98101

99-
var names = names.map(x => x);
100-
ensureUniquenessInPlace(names, isFixed, isCaseSensitive);
102+
var names = names.slice();
103+
ensureUniquenessInPlace(names, isCaseSensitive, isFixed);
101104
return names;
102105
}
103106

104-
function ensureUniquenessInPlace(names: string[], isFixed: boolean[], isCaseSensitive: boolean): void {
107+
function ensureUniquenessInPlace(names: string[], isCaseSensitive: boolean, isFixed: boolean[]): void {
105108
for (var i = 0; i < names.length; i++) {
106109
var name = names[i];
107110
var collisionIndices = Utilities.collectMatchingIndices(name, names, isCaseSensitive);
@@ -128,9 +131,12 @@ module NameGenerator {
128131
}
129132

130133
while (true) {
131-
var newName = name + suffix++;
134+
var newName = name + suffix;
135+
suffix++;
132136

133-
if (!proposedNames.some((name) => Utilities.stringEquals(name, newName, isCaseSensitive))) {
137+
// Check if we've synthesized a unique name, and if so
138+
// replace the conflicting name with the new one.
139+
if (!proposedNames.some(name => Utilities.stringEquals(name, newName, isCaseSensitive))) {
134140
proposedNames[collisionIndex] = newName;
135141
break;
136142
}
@@ -141,7 +147,7 @@ module NameGenerator {
141147

142148
module Utilities {
143149
/// Return a list of all indices where a string occurs.
144-
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean = false): number[] {
150+
export function collectMatchingIndices(name: string, proposedNames: string[], isCaseSensitive: boolean): number[] {
145151
var matchingIndices: number[] = [];
146152

147153
for (var i = 0; i < proposedNames.length; i++) {
@@ -153,7 +159,7 @@ module Utilities {
153159
return matchingIndices;
154160
}
155161

156-
export function stringEquals(s1: string, s2: string, caseSensitive: boolean = false): boolean {
162+
export function stringEquals(s1: string, s2: string, caseSensitive: boolean): boolean {
157163
if (caseSensitive) {
158164
s1 = s1.toLowerCase();
159165
s2 = s2.toLowerCase();

src/compiler/tc.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,33 +186,28 @@ module ts {
186186
}
187187

188188
export function executeCommandLine(args: string[]): void {
189-
var exitCode = 0;
190189
var commandLine = parseCommandLine(args);
191190

192191
if (commandLine.options.locale) {
193192
validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors);
194193
}
195194

196-
// Report all errors at this point, even if there are none.
195+
// If there are any errors due to command line parsing and/or
196+
// setting up localization, report them and quit.
197197
if (commandLine.errors.length > 0) {
198198
reportDiagnostics(commandLine.errors);
199-
exitCode = 1;
199+
sys.exit(1);
200200
}
201201

202202
if (commandLine.options.version) {
203203
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version));
204-
sys.exit(exitCode);
204+
sys.exit(0);
205205
}
206206

207207
if (commandLine.options.help || commandLine.filenames.length === 0) {
208208
printVersion();
209209
printHelp();
210-
sys.exit(exitCode);
211-
}
212-
213-
// If we encountered an error before we even started compiling, just bail out.
214-
if (exitCode !== 0) {
215-
sys.exit(exitCode);
210+
sys.exit(0);
216211
}
217212

218213
var defaultCompilerHost = createCompilerHost(commandLine.options);
@@ -411,18 +406,14 @@ module ts {
411406
descriptionColumn.push(getDiagnosticText(option.description));
412407

413408
// Set the new margin for the description column if necessary.
414-
if (usageText.length > marginLength) {
415-
marginLength = usageText.length;
416-
}
409+
marginLength = Math.max(usageText.length, marginLength);
417410
}
418411

419412
// Special case that can't fit in the loop.
420413
var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">";
421414
usageColumn.push(usageText);
422415
descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file));
423-
if (usageText.length > marginLength) {
424-
marginLength = usageText.length;
425-
}
416+
marginLength = Math.max(usageText.length, marginLength);
426417

427418
// Print out each row, aligning all the descriptions on the same column.
428419
for (var i = 0; i < usageColumn.length; i++) {

0 commit comments

Comments
 (0)