@@ -63,6 +63,7 @@ import {
6363 DefaultClause,
6464 DeleteExpression,
6565 Diagnostic,
66+ DiagnosticArguments,
6667 DiagnosticMessage,
6768 Diagnostics,
6869 DiagnosticWithDetachedLocation,
@@ -149,6 +150,7 @@ import {
149150 isJsxOpeningElement,
150151 isJsxOpeningFragment,
151152 isKeyword,
153+ isKeywordOrPunctuation,
152154 isLeftHandSideExpression,
153155 isLiteralKind,
154156 isMetaProperty,
@@ -306,6 +308,8 @@ import {
306308 PropertyDeclaration,
307309 PropertyName,
308310 PropertySignature,
311+ PunctuationOrKeywordSyntaxKind,
312+ PunctuationSyntaxKind,
309313 QualifiedName,
310314 QuestionDotToken,
311315 QuestionToken,
@@ -380,6 +384,7 @@ import {
380384 TypeQueryNode,
381385 TypeReferenceNode,
382386 UnaryExpression,
387+ unescapeLeadingUnderscores,
383388 UnionOrIntersectionTypeNode,
384389 UnionTypeNode,
385390 UpdateExpression,
@@ -2096,16 +2101,16 @@ namespace Parser {
20962101 return inContext(NodeFlags.AwaitContext);
20972102 }
20982103
2099- function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any ): DiagnosticWithDetachedLocation | undefined {
2100- return parseErrorAt(scanner.getTokenStart(), scanner.getTokenEnd(), message, arg0 );
2104+ function parseErrorAtCurrentToken(message: DiagnosticMessage, ...args: DiagnosticArguments ): DiagnosticWithDetachedLocation | undefined {
2105+ return parseErrorAt(scanner.getTokenStart(), scanner.getTokenEnd(), message, ...args );
21012106 }
21022107
2103- function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any ): DiagnosticWithDetachedLocation | undefined {
2108+ function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, ...args: DiagnosticArguments ): DiagnosticWithDetachedLocation | undefined {
21042109 // Don't report another error if it would just be at the same position as the last error.
21052110 const lastError = lastOrUndefined(parseDiagnostics);
21062111 let result: DiagnosticWithDetachedLocation | undefined;
21072112 if (!lastError || start !== lastError.start) {
2108- result = createDetachedDiagnostic(fileName, start, length, message, arg0 );
2113+ result = createDetachedDiagnostic(fileName, start, length, message, ...args );
21092114 parseDiagnostics.push(result);
21102115 }
21112116
@@ -2115,12 +2120,12 @@ namespace Parser {
21152120 return result;
21162121 }
21172122
2118- function parseErrorAt(start: number, end: number, message: DiagnosticMessage, arg0?: any ): DiagnosticWithDetachedLocation | undefined {
2119- return parseErrorAtPosition(start, end - start, message, arg0 );
2123+ function parseErrorAt(start: number, end: number, message: DiagnosticMessage, ...args: DiagnosticArguments ): DiagnosticWithDetachedLocation | undefined {
2124+ return parseErrorAtPosition(start, end - start, message, ...args );
21202125 }
21212126
2122- function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, arg0?: any ): void {
2123- parseErrorAt(range.pos, range.end, message, arg0 );
2127+ function parseErrorAtRange(range: TextRange, message: DiagnosticMessage, ...args: DiagnosticArguments ): void {
2128+ parseErrorAt(range.pos, range.end, message, ...args );
21242129 }
21252130
21262131 function scanError(message: DiagnosticMessage, length: number): void {
@@ -2289,7 +2294,7 @@ namespace Parser {
22892294 return token() > SyntaxKind.LastReservedWord;
22902295 }
22912296
2292- function parseExpected(kind: SyntaxKind , diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): boolean {
2297+ function parseExpected(kind: PunctuationOrKeywordSyntaxKind , diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): boolean {
22932298 if (token() === kind) {
22942299 if (shouldAdvance) {
22952300 nextToken();
@@ -2444,11 +2449,12 @@ namespace Parser {
24442449 nextTokenJSDoc();
24452450 return true;
24462451 }
2452+ Debug.assert(isKeywordOrPunctuation(kind));
24472453 parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind));
24482454 return false;
24492455 }
24502456
2451- function parseExpectedMatchingBrackets(openKind: SyntaxKind , closeKind: SyntaxKind , openParsed: boolean, openPosition: number) {
2457+ function parseExpectedMatchingBrackets(openKind: PunctuationSyntaxKind , closeKind: PunctuationSyntaxKind , openParsed: boolean, openPosition: number) {
24522458 if (token() === closeKind) {
24532459 nextToken();
24542460 return;
@@ -2489,16 +2495,18 @@ namespace Parser {
24892495 return undefined;
24902496 }
24912497
2492- function parseExpectedToken<TKind extends SyntaxKind>(t: TKind, diagnosticMessage?: DiagnosticMessage, arg0?: any ): Token<TKind>;
2493- function parseExpectedToken(t: SyntaxKind, diagnosticMessage?: DiagnosticMessage, arg0?: any ): Node {
2498+ function parseExpectedToken<TKind extends SyntaxKind>(t: TKind, diagnosticMessage?: DiagnosticMessage, arg0?: string ): Token<TKind>;
2499+ function parseExpectedToken(t: SyntaxKind, diagnosticMessage?: DiagnosticMessage, arg0?: string ): Node {
24942500 return parseOptionalToken(t) ||
2495- createMissingNode(t, /*reportAtCurrentPosition*/ false, diagnosticMessage || Diagnostics._0_expected, arg0 || tokenToString(t));
2501+ createMissingNode(t, /*reportAtCurrentPosition*/ false, diagnosticMessage || Diagnostics._0_expected, arg0 || tokenToString(t)! );
24962502 }
24972503
24982504 function parseExpectedTokenJSDoc<TKind extends JSDocSyntaxKind>(t: TKind): Token<TKind>;
24992505 function parseExpectedTokenJSDoc(t: JSDocSyntaxKind): Node {
2500- return parseOptionalTokenJSDoc(t) ||
2501- createMissingNode(t, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(t));
2506+ const optional = parseOptionalTokenJSDoc(t);
2507+ if (optional) return optional;
2508+ Debug.assert(isKeywordOrPunctuation(t));
2509+ return createMissingNode(t, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(t));
25022510 }
25032511
25042512 function parseTokenNode<T extends Node>(): T {
@@ -2565,14 +2573,14 @@ namespace Parser {
25652573 return node;
25662574 }
25672575
2568- function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: false, diagnosticMessage?: DiagnosticMessage, arg0?: any ): T;
2569- function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any ): T;
2570- function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage?: DiagnosticMessage, arg0?: any ): T {
2576+ function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: false, diagnosticMessage?: DiagnosticMessage, ...args: DiagnosticArguments ): T;
2577+ function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, ...args: DiagnosticArguments ): T;
2578+ function createMissingNode<T extends Node>(kind: T["kind"], reportAtCurrentPosition: boolean, diagnosticMessage?: DiagnosticMessage, ...args: DiagnosticArguments ): T {
25712579 if (reportAtCurrentPosition) {
2572- parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, arg0 );
2580+ parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, ...args );
25732581 }
25742582 else if (diagnosticMessage) {
2575- parseErrorAtCurrentToken(diagnosticMessage, arg0 );
2583+ parseErrorAtCurrentToken(diagnosticMessage, ...args );
25762584 }
25772585
25782586 const pos = getNodePos();
@@ -3356,7 +3364,7 @@ namespace Parser {
33563364 case ParsingContext.HeritageClauseElement: return parseErrorAtCurrentToken(Diagnostics.Expression_expected);
33573365 case ParsingContext.VariableDeclarations:
33583366 return isKeyword(token())
3359- ? parseErrorAtCurrentToken(Diagnostics._0_is_not_allowed_as_a_variable_declaration_name, tokenToString(token()))
3367+ ? parseErrorAtCurrentToken(Diagnostics._0_is_not_allowed_as_a_variable_declaration_name, tokenToString(token())! )
33603368 : parseErrorAtCurrentToken(Diagnostics.Variable_declaration_expected);
33613369 case ParsingContext.ObjectBindingElements: return parseErrorAtCurrentToken(Diagnostics.Property_destructuring_pattern_expected);
33623370 case ParsingContext.ArrayBindingElements: return parseErrorAtCurrentToken(Diagnostics.Array_element_destructuring_pattern_expected);
@@ -3366,7 +3374,7 @@ namespace Parser {
33663374 case ParsingContext.JSDocParameters: return parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
33673375 case ParsingContext.Parameters:
33683376 return isKeyword(token())
3369- ? parseErrorAtCurrentToken(Diagnostics._0_is_not_allowed_as_a_parameter_name, tokenToString(token()))
3377+ ? parseErrorAtCurrentToken(Diagnostics._0_is_not_allowed_as_a_parameter_name, tokenToString(token())! )
33703378 : parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
33713379 case ParsingContext.TypeParameters: return parseErrorAtCurrentToken(Diagnostics.Type_parameter_declaration_expected);
33723380 case ParsingContext.TypeArguments: return parseErrorAtCurrentToken(Diagnostics.Type_argument_expected);
@@ -3471,7 +3479,7 @@ namespace Parser {
34713479 return !!(arr as MissingList<Node>).isMissingList;
34723480 }
34733481
3474- function parseBracketedList<T extends Node>(kind: ParsingContext, parseElement: () => T, open: SyntaxKind , close: SyntaxKind ): NodeArray<T> {
3482+ function parseBracketedList<T extends Node>(kind: ParsingContext, parseElement: () => T, open: PunctuationSyntaxKind , close: PunctuationSyntaxKind ): NodeArray<T> {
34753483 if (parseExpected(open)) {
34763484 const result = parseDelimitedList(kind, parseElement);
34773485 parseExpected(close);
@@ -5653,6 +5661,7 @@ namespace Parser {
56535661 parseErrorAt(pos, end, Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses);
56545662 }
56555663 else {
5664+ Debug.assert(isKeywordOrPunctuation(unaryOperator));
56565665 parseErrorAt(pos, end, Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, tokenToString(unaryOperator));
56575666 }
56585667 }
@@ -9119,7 +9128,7 @@ namespace Parser {
91199128
91209129 function parseReturnTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocReturnTag {
91219130 if (some(tags, isJSDocReturnTag)) {
9122- 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) );
91239132 }
91249133
91259134 const typeExpression = tryParseTypeExpression();
@@ -9128,7 +9137,7 @@ namespace Parser {
91289137
91299138 function parseTypeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocTypeTag {
91309139 if (some(tags, isJSDocTypeTag)) {
9131- parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, tagName.escapedText);
9140+ parseErrorAt(tagName.pos, scanner.getTokenStart(), Diagnostics._0_tag_already_specified, unescapeLeadingUnderscores( tagName.escapedText) );
91329141 }
91339142
91349143 const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true);
0 commit comments