From 76d83ee6242c0af71752d64671a155cf1f637cd5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 23 Nov 2014 13:23:44 -0800 Subject: [PATCH 1/2] Don't explicitly make diagnostics in the parser. --- src/services/syntax/parser.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/services/syntax/parser.ts b/src/services/syntax/parser.ts index 54ca007fe46..ee5a03253cb 100644 --- a/src/services/syntax/parser.ts +++ b/src/services/syntax/parser.ts @@ -2889,13 +2889,10 @@ module TypeScript.Parser { // we'll bail out here and give a poor error message when we try to parse this // as an arithmetic expression. if (isDot) { - // A parameter list must follow a generic type argument list. - var diagnostic = new Diagnostic(fileName, source.text.lineMap(), start(token0, source.text), width(token0), - DiagnosticCode.A_parameter_list_must_follow_a_generic_type_argument_list_expected, undefined); - addDiagnostic(diagnostic); - return new ArgumentListSyntax(parseNodeData, typeArgumentList, - createEmptyToken(SyntaxKind.OpenParenToken), [], createEmptyToken(SyntaxKind.CloseParenToken)); + createMissingToken(SyntaxKind.OpenParenToken, undefined, DiagnosticCode.A_parameter_list_must_follow_a_generic_type_argument_list_expected), + [], + eatToken(SyntaxKind.CloseParenToken)); } else { Debug.assert(token0.kind === SyntaxKind.OpenParenToken); From 71a1f13226a6491e6974c33140a8e6f7c6cec9ec Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 23 Nov 2014 13:31:20 -0800 Subject: [PATCH 2/2] Don't report a diagnostic explicitly. --- src/services/syntax/parser.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/services/syntax/parser.ts b/src/services/syntax/parser.ts index ee5a03253cb..d9ae5891642 100644 --- a/src/services/syntax/parser.ts +++ b/src/services/syntax/parser.ts @@ -563,8 +563,8 @@ module TypeScript.Parser { return Syntax.emptyToken(kind, fullStart); } - function createMissingToken(expectedKind: SyntaxKind, actual: ISyntaxToken, diagnosticCode?: string): ISyntaxToken { - var diagnostic = getExpectedTokenDiagnostic(expectedKind, actual, diagnosticCode); + function createMissingToken(expectedKind: SyntaxKind, actual: ISyntaxToken, diagnosticCode?: string, args?: any[]): ISyntaxToken { + var diagnostic = getExpectedTokenDiagnostic(expectedKind, actual, diagnosticCode, args); addDiagnostic(diagnostic); // The missing token will be at the full start of the current token. That way empty tokens @@ -572,10 +572,9 @@ module TypeScript.Parser { return createEmptyToken(expectedKind); } - function getExpectedTokenDiagnostic(expectedKind: SyntaxKind, actual?: ISyntaxToken, diagnosticCode?: string): Diagnostic { + function getExpectedTokenDiagnostic(expectedKind: SyntaxKind, actual?: ISyntaxToken, diagnosticCode?: string, args?: any[]): Diagnostic { var token = currentToken(); - var args: any[] = undefined; // If a specialized diagnostic message was provided, just use that. if (!diagnosticCode) { // They wanted something specific, just report that that token was missing. @@ -3094,9 +3093,7 @@ module TypeScript.Parser { token = consumeToken(token); } else { - var diagnostic = getExpectedTokenDiagnostic(SyntaxKind.CloseBraceToken); - addDiagnostic(diagnostic); - token = createEmptyToken(SyntaxKind.TemplateEndToken); + token = createMissingToken(SyntaxKind.TemplateEndToken, undefined, DiagnosticCode._0_expected, ["{"]); } return new TemplateClauseSyntax(parseNodeData, expression, token);