From e69b9e6362aeb8a8fa3cf1ae076e5b7618d26543 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 17 Sep 2014 15:28:41 -0700 Subject: [PATCH] Fixed issue where parser improperly parses a function declaration with no identifier. --- src/compiler/checker.ts | 4 ++++ src/compiler/parser.ts | 5 ++++- .../parserEqualsGreaterThanAfterFunction1.errors.txt | 6 ++---- .../parserEqualsGreaterThanAfterFunction2.errors.txt | 6 ++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b99d6d27d20..db876da3b9f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5379,6 +5379,10 @@ module ts { var isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0; function reportImplementationExpectedError(node: FunctionDeclaration): void { + if (node.name && node.name.kind === SyntaxKind.Missing) { + return; + } + var seen = false; var subsequentNode = forEachChild(node.parent, c => { if (seen) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 25ca24ae61b..6fa2cdd244a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -953,7 +953,10 @@ module ts { return finishNode(node); } error(Diagnostics.Identifier_expected); - return createMissingNode(); + + var node = createMissingNode(); + node.text = ""; + return node; } function parseIdentifier(): Identifier { diff --git a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt index 9f428d7fea7..fd3e1c42779 100644 --- a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt +++ b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction1.errors.txt @@ -1,6 +1,4 @@ -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEqualsGreaterThanAfterFunction1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEqualsGreaterThanAfterFunction1.ts (1 errors) ==== function => ~~ -!!! Identifier expected. - -!!! Function implementation is missing or not immediately following the declaration. \ No newline at end of file +!!! Identifier expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt index 4e9b5fbaa86..0d81cd7f35d 100644 --- a/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt +++ b/tests/baselines/reference/parserEqualsGreaterThanAfterFunction2.errors.txt @@ -1,4 +1,4 @@ -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEqualsGreaterThanAfterFunction2.ts (5 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserEqualsGreaterThanAfterFunction2.ts (4 errors) ==== function (a => b; ~ !!! Identifier expected. @@ -7,6 +7,4 @@ ~ !!! ',' expected. -!!! ')' expected. - -!!! Function implementation is missing or not immediately following the declaration. \ No newline at end of file +!!! ')' expected. \ No newline at end of file