@@ -63,6 +63,7 @@ import {
63
63
DefaultClause,
64
64
DeleteExpression,
65
65
Diagnostic,
66
+ DiagnosticArguments,
66
67
DiagnosticMessage,
67
68
Diagnostics,
68
69
DiagnosticWithDetachedLocation,
@@ -149,6 +150,7 @@ import {
149
150
isJsxOpeningElement,
150
151
isJsxOpeningFragment,
151
152
isKeyword,
153
+ isKeywordOrPunctuation,
152
154
isLeftHandSideExpression,
153
155
isLiteralKind,
154
156
isMetaProperty,
@@ -306,6 +308,8 @@ import {
306
308
PropertyDeclaration,
307
309
PropertyName,
308
310
PropertySignature,
311
+ PunctuationOrKeywordSyntaxKind,
312
+ PunctuationSyntaxKind,
309
313
QualifiedName,
310
314
QuestionDotToken,
311
315
QuestionToken,
@@ -380,6 +384,7 @@ import {
380
384
TypeQueryNode,
381
385
TypeReferenceNode,
382
386
UnaryExpression,
387
+ unescapeLeadingUnderscores,
383
388
UnionOrIntersectionTypeNode,
384
389
UnionTypeNode,
385
390
UpdateExpression,
@@ -2096,16 +2101,16 @@ namespace Parser {
2096
2101
return inContext(NodeFlags.AwaitContext);
2097
2102
}
2098
2103
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 );
2101
2106
}
2102
2107
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 {
2104
2109
// Don't report another error if it would just be at the same position as the last error.
2105
2110
const lastError = lastOrUndefined(parseDiagnostics);
2106
2111
let result: DiagnosticWithDetachedLocation | undefined;
2107
2112
if (!lastError || start !== lastError.start) {
2108
- result = createDetachedDiagnostic(fileName, start, length, message, arg0 );
2113
+ result = createDetachedDiagnostic(fileName, start, length, message, ...args );
2109
2114
parseDiagnostics.push(result);
2110
2115
}
2111
2116
@@ -2115,12 +2120,12 @@ namespace Parser {
2115
2120
return result;
2116
2121
}
2117
2122
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 );
2120
2125
}
2121
2126
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 );
2124
2129
}
2125
2130
2126
2131
function scanError(message: DiagnosticMessage, length: number): void {
@@ -2289,7 +2294,7 @@ namespace Parser {
2289
2294
return token() > SyntaxKind.LastReservedWord;
2290
2295
}
2291
2296
2292
- function parseExpected(kind: SyntaxKind , diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): boolean {
2297
+ function parseExpected(kind: PunctuationOrKeywordSyntaxKind , diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): boolean {
2293
2298
if (token() === kind) {
2294
2299
if (shouldAdvance) {
2295
2300
nextToken();
@@ -2444,11 +2449,12 @@ namespace Parser {
2444
2449
nextTokenJSDoc();
2445
2450
return true;
2446
2451
}
2452
+ Debug.assert(isKeywordOrPunctuation(kind));
2447
2453
parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind));
2448
2454
return false;
2449
2455
}
2450
2456
2451
- function parseExpectedMatchingBrackets(openKind: SyntaxKind , closeKind: SyntaxKind , openParsed: boolean, openPosition: number) {
2457
+ function parseExpectedMatchingBrackets(openKind: PunctuationSyntaxKind , closeKind: PunctuationSyntaxKind , openParsed: boolean, openPosition: number) {
2452
2458
if (token() === closeKind) {
2453
2459
nextToken();
2454
2460
return;
@@ -2489,16 +2495,18 @@ namespace Parser {
2489
2495
return undefined;
2490
2496
}
2491
2497
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 {
2494
2500
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)! );
2496
2502
}
2497
2503
2498
2504
function parseExpectedTokenJSDoc<TKind extends JSDocSyntaxKind>(t: TKind): Token<TKind>;
2499
2505
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));
2502
2510
}
2503
2511
2504
2512
function parseTokenNode<T extends Node>(): T {
@@ -2565,14 +2573,14 @@ namespace Parser {
2565
2573
return node;
2566
2574
}
2567
2575
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 {
2571
2579
if (reportAtCurrentPosition) {
2572
- parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, arg0 );
2580
+ parseErrorAtPosition(scanner.getTokenFullStart(), 0, diagnosticMessage!, ...args );
2573
2581
}
2574
2582
else if (diagnosticMessage) {
2575
- parseErrorAtCurrentToken(diagnosticMessage, arg0 );
2583
+ parseErrorAtCurrentToken(diagnosticMessage, ...args );
2576
2584
}
2577
2585
2578
2586
const pos = getNodePos();
@@ -3356,7 +3364,7 @@ namespace Parser {
3356
3364
case ParsingContext.HeritageClauseElement: return parseErrorAtCurrentToken(Diagnostics.Expression_expected);
3357
3365
case ParsingContext.VariableDeclarations:
3358
3366
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())! )
3360
3368
: parseErrorAtCurrentToken(Diagnostics.Variable_declaration_expected);
3361
3369
case ParsingContext.ObjectBindingElements: return parseErrorAtCurrentToken(Diagnostics.Property_destructuring_pattern_expected);
3362
3370
case ParsingContext.ArrayBindingElements: return parseErrorAtCurrentToken(Diagnostics.Array_element_destructuring_pattern_expected);
@@ -3366,7 +3374,7 @@ namespace Parser {
3366
3374
case ParsingContext.JSDocParameters: return parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
3367
3375
case ParsingContext.Parameters:
3368
3376
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())! )
3370
3378
: parseErrorAtCurrentToken(Diagnostics.Parameter_declaration_expected);
3371
3379
case ParsingContext.TypeParameters: return parseErrorAtCurrentToken(Diagnostics.Type_parameter_declaration_expected);
3372
3380
case ParsingContext.TypeArguments: return parseErrorAtCurrentToken(Diagnostics.Type_argument_expected);
@@ -3471,7 +3479,7 @@ namespace Parser {
3471
3479
return !!(arr as MissingList<Node>).isMissingList;
3472
3480
}
3473
3481
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> {
3475
3483
if (parseExpected(open)) {
3476
3484
const result = parseDelimitedList(kind, parseElement);
3477
3485
parseExpected(close);
@@ -5653,6 +5661,7 @@ namespace Parser {
5653
5661
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);
5654
5662
}
5655
5663
else {
5664
+ Debug.assert(isKeywordOrPunctuation(unaryOperator));
5656
5665
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));
5657
5666
}
5658
5667
}
@@ -9119,7 +9128,7 @@ namespace Parser {
9119
9128
9120
9129
function parseReturnTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocReturnTag {
9121
9130
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) );
9123
9132
}
9124
9133
9125
9134
const typeExpression = tryParseTypeExpression();
@@ -9128,7 +9137,7 @@ namespace Parser {
9128
9137
9129
9138
function parseTypeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocTypeTag {
9130
9139
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) );
9132
9141
}
9133
9142
9134
9143
const typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true);
0 commit comments