mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-11 17:41:26 -06:00
Add funcitonality to warn on duplicate codes.
This commit is contained in:
parent
92f5f59a07
commit
2e5b6fec7c
@ -10,10 +10,6 @@ interface InputDiagnosticMessageTable {
|
||||
[msg: string]: DiagnosticDetails;
|
||||
}
|
||||
|
||||
interface IIndexable<V> {
|
||||
[key: string]: V;
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
var sys = ts.sys;
|
||||
if (sys.args.length < 1) {
|
||||
@ -25,21 +21,42 @@ function main(): void {
|
||||
var inputFilePath = sys.args[0].replace(/\\/g, "/");
|
||||
var inputStr = sys.readFile(inputFilePath);
|
||||
|
||||
var diagnosticMesages: InputDiagnosticMessageTable = JSON.parse(inputStr);
|
||||
var diagnosticMessages: InputDiagnosticMessageTable = JSON.parse(inputStr);
|
||||
|
||||
var names = Utilities.getObjectKeys(diagnosticMesages);
|
||||
var names = Utilities.getObjectKeys(diagnosticMessages);
|
||||
var nameMap = buildUniqueNameMap(names);
|
||||
|
||||
var infoFileOutput = buildInfoFileOutput(diagnosticMesages, nameMap);
|
||||
|
||||
var infoFileOutput = buildInfoFileOutput(diagnosticMessages, nameMap);
|
||||
checkForUniqueCodes(names, diagnosticMessages);
|
||||
|
||||
// TODO: Fix path joining
|
||||
var inputDirectory = inputFilePath.substr(0,inputFilePath.lastIndexOf("/"));
|
||||
var fileOutputPath = inputDirectory + "/diagnosticInformationMap.generated.ts";
|
||||
sys.writeFile(fileOutputPath, infoFileOutput);
|
||||
}
|
||||
|
||||
function buildUniqueNameMap(names: string[]): IIndexable<string> {
|
||||
var nameMap: IIndexable<string> = {};
|
||||
function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosticMessageTable) {
|
||||
const originalMessageForCode: string[] = [];
|
||||
|
||||
for (const currentMessage of messages) {
|
||||
const code = diagnosticTable[currentMessage].code;
|
||||
|
||||
if (code in originalMessageForCode) {
|
||||
const originalMessage = originalMessageForCode[code];
|
||||
ts.sys.write("\x1b[93m"); // High intensity yellow.
|
||||
ts.sys.write("Warning");
|
||||
ts.sys.write("\x1b[0m"); // Reset formatting.
|
||||
ts.sys.write(`: Diagnostic code '${code}' conflicts between "${originalMessage}" and "${currentMessage}".`);
|
||||
ts.sys.write(ts.sys.newLine + ts.sys.newLine);
|
||||
}
|
||||
else {
|
||||
originalMessageForCode[code] = currentMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buildUniqueNameMap(names: string[]): ts.Map<string> {
|
||||
var nameMap: ts.Map<string> = {};
|
||||
|
||||
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);
|
||||
|
||||
@ -50,7 +67,7 @@ function buildUniqueNameMap(names: string[]): IIndexable<string> {
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: IIndexable<string>): string {
|
||||
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string>): string {
|
||||
var result =
|
||||
'// <auto-generated />\r\n' +
|
||||
'/// <reference path="types.ts" />\r\n' +
|
||||
@ -172,7 +189,7 @@ module Utilities {
|
||||
}
|
||||
|
||||
// Like Object.keys
|
||||
export function getObjectKeys(obj: any): string[]{
|
||||
export function getObjectKeys(obj: any): string[] {
|
||||
var result: string[] = [];
|
||||
|
||||
for (var name in obj) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user