Skip to content

Commit ce2d704

Browse files
committed
Consistently use '...args' for diagnostic args
1 parent 29c4b5e commit ce2d704

File tree

7 files changed

+107
-106
lines changed

7 files changed

+107
-106
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
556556
* If so, the node _must_ be in the current file (as that's the only way anything could have traversed to it to yield it as the error node)
557557
* This version of `createDiagnosticForNode` uses the binder's context to account for this, and always yields correct diagnostics even in these situations.
558558
*/
559-
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): DiagnosticWithLocation {
560-
return createDiagnosticForNodeInSourceFile(getSourceFileOfNode(node) || file, node, message, arg0, arg1, arg2);
559+
function createDiagnosticForNode(node: Node, message: DiagnosticMessage, ...args: (string | number | undefined)[]): DiagnosticWithLocation {
560+
return createDiagnosticForNodeInSourceFile(getSourceFileOfNode(node) || file, node, message, ...args);
561561
}
562562

563563
function bindSourceFile(f: SourceFile, opts: CompilerOptions) {
@@ -2613,9 +2613,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
26132613
}
26142614
}
26152615

2616-
function errorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any) {
2616+
function errorOnFirstToken(node: Node, message: DiagnosticMessage, ...args: (string | number | undefined)[]) {
26172617
const span = getSpanOfTokenAtPosition(file, node.pos);
2618-
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
2618+
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, ...args));
26192619
}
26202620

26212621
function errorOrSuggestionOnNode(isError: boolean, node: Node, message: DiagnosticMessage): void {

src/compiler/checker.ts

Lines changed: 48 additions & 48 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,9 +3094,9 @@ function parseJsonConfigFileContentWorker(
30943094
return "no-prop";
30953095
}
30963096

3097-
function createCompilerDiagnosticOnlyIfJson(message: DiagnosticMessage, arg0?: string, arg1?: string) {
3097+
function createCompilerDiagnosticOnlyIfJson(message: DiagnosticMessage, ...args: (string | number | undefined)[]) {
30983098
if (!sourceFile) {
3099-
errors.push(createCompilerDiagnostic(message, arg0, arg1));
3099+
errors.push(createCompilerDiagnostic(message, ...args));
31003100
}
31013101
}
31023102
}

src/compiler/parser.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ import {
379379
TypeQueryNode,
380380
TypeReferenceNode,
381381
UnaryExpression,
382+
unescapeLeadingUnderscores,
382383
UnionOrIntersectionTypeNode,
383384
UnionTypeNode,
384385
UpdateExpression,
@@ -2095,16 +2096,16 @@ namespace Parser {
20952096
return inContext(NodeFlags.AwaitContext);
20962097
}
20972098

2098-
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
2099-
return parseErrorAt(scanner.getTokenStart(), scanner.getTokenEnd(), message, arg0);
2099+
function parseErrorAtCurrentToken(message: DiagnosticMessage, ...args: (string | number | undefined)[]): DiagnosticWithDetachedLocation | undefined {
2100+
return parseErrorAt(scanner.getTokenStart(), scanner.getTokenEnd(), message, ...args);
21002101
}
21012102

2102-
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
2103+
function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, ...args: (string | number | undefined)[]): DiagnosticWithDetachedLocation | undefined {
21032104
// Don't report another error if it would just be at the same position as the last error.
21042105
const lastError = lastOrUndefined(parseDiagnostics);
21052106
let result: DiagnosticWithDetachedLocation | undefined;
21062107
if (!lastError || start !== lastError.start) {
2107-
result = createDetachedDiagnostic(fileName, start, length, message, arg0);
2108+
result = createDetachedDiagnostic(fileName, start, length, message, ...args);
21082109
parseDiagnostics.push(result);
21092110
}
21102111

@@ -2114,12 +2115,12 @@ namespace Parser {
21142115
return result;
21152116
}
21162117

2117-
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined {
2118-
return parseErrorAtPosition(start, end - start, message, arg0);
2118+
function parseErrorAt(start: number, end: number, message: DiagnosticMessage, ...args: (string | number | undefined)[]): DiagnosticWithDetachedLocation | undefined {
2119+
return parseErrorAtPosition(start, end - start, message, ...args);
21192120
}
21202121

2121-
function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, arg0?: any): void {
2122-
parseErrorAt(range.pos, range.end, message, arg0);
2122+
function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, ...args: (string | number | undefined)[]): void {
2123+
parseErrorAt(range.pos, range.end, message, ...args);
21232124
}
21242125

21252126
function scanError(message: DiagnosticMessage, length: number): void {
@@ -2564,14 +2565,14 @@ namespace Parser {
25642565
return node;
25652566
}
25662567

2567-
function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: false, diagnosticMessage?: DiagnosticMessage, arg0?: any): T;
2568-
function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): T;
2569-
function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage?: DiagnosticMessage, arg0?: any): T {
2568+
function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: false, diagnosticMessage?: DiagnosticMessage, ...args: (string | number | undefined)[]): T;
2569+
function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, ...args: (string | number | undefined)[]): T;
2570+
function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage?: DiagnosticMessage, ...args: (string | number | undefined)[]): T {
25702571
if (reportAtCurrentPosition) {
2571-
parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, arg0);
2572+
parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, ...args);
25722573
}
25732574
else if (diagnosticMessage) {
2574-
parseErrorAtCurrentToken(diagnosticMessage, arg0);
2575+
parseErrorAtCurrentToken(diagnosticMessage, ...args);
25752576
}
25762577

25772578
const pos = getNodePos();
@@ -9118,7 +9119,7 @@ namespace Parser {
91189119

91199120
function parseReturnTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocReturnTag {
91209121
if (some(tags, isJSDocReturnTag)) {
9121-
parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, tagName.escapedText);
9122+
parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.escapedText));
91229123
}
91239124

91249125
const typeExpression = tryParseTypeExpression();
@@ -9127,7 +9128,7 @@ namespace Parser {
91279128

91289129
function parseTypeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocTypeTag {
91299130
if (some(tags, isJSDocTypeTag)) {
9130-
parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, tagName.escapedText);
9131+
parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores(tagName.escapedText));
91319132
}
91329133

91339134
const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true);

0 commit comments

Comments
 (0)