diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8a6743090f9..ffcd1b1255e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5986,6 +5986,9 @@ namespace ts { case SyntaxKind.FunctionKeyword: case SyntaxKind.ClassKeyword: case SyntaxKind.EnumKeyword: + // Include 'default' for error recovery. + // falls through + case SyntaxKind.DefaultKeyword: return true; // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; @@ -6084,9 +6087,10 @@ namespace ts { case SyntaxKind.ThrowKeyword: case SyntaxKind.TryKeyword: case SyntaxKind.DebuggerKeyword: - // 'catch' and 'finally' do not actually indicate that the code is part of a statement, + // 'default', 'catch' and 'finally' do not actually indicate that the code is part of a statement, // however, we say they are here so that we may gracefully parse them and error later. // falls through + case SyntaxKind.DefaultKeyword: case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: return true; @@ -6197,6 +6201,9 @@ namespace ts { case SyntaxKind.StaticKeyword: case SyntaxKind.ReadonlyKeyword: case SyntaxKind.GlobalKeyword: + // Include 'default' for error recovery. + // falls through + case SyntaxKind.DefaultKeyword: if (isStartOfDeclaration()) { return parseDeclaration(); } diff --git a/tests/baselines/reference/defaultKeywordWithoutExport2.errors.txt b/tests/baselines/reference/defaultKeywordWithoutExport2.errors.txt index 2ba3b55eb26..237cf648a1a 100644 --- a/tests/baselines/reference/defaultKeywordWithoutExport2.errors.txt +++ b/tests/baselines/reference/defaultKeywordWithoutExport2.errors.txt @@ -1,12 +1,9 @@ -tests/cases/compiler/defaultKeywordWithoutExport2.ts(1,1): error TS1128: Declaration or statement expected. -tests/cases/compiler/defaultKeywordWithoutExport2.ts(1,18): error TS1003: Identifier expected. +tests/cases/compiler/defaultKeywordWithoutExport2.ts(1,1): error TS1029: 'export' modifier must precede 'default' modifier. -==== tests/cases/compiler/defaultKeywordWithoutExport2.ts (2 errors) ==== +==== tests/cases/compiler/defaultKeywordWithoutExport2.ts (1 errors) ==== default function () { ~~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~ -!!! error TS1003: Identifier expected. +!!! error TS1029: 'export' modifier must precede 'default' modifier. } \ No newline at end of file diff --git a/tests/baselines/reference/defaultKeywordWithoutExport2.js b/tests/baselines/reference/defaultKeywordWithoutExport2.js index 0f5dfe5d2a7..bc0315744b9 100644 --- a/tests/baselines/reference/defaultKeywordWithoutExport2.js +++ b/tests/baselines/reference/defaultKeywordWithoutExport2.js @@ -4,5 +4,5 @@ default function () { } //// [defaultKeywordWithoutExport2.js] -function () { +default function () { } diff --git a/tests/baselines/reference/defaultKeywordWithoutExport2.symbols b/tests/baselines/reference/defaultKeywordWithoutExport2.symbols index fb8a0ec6ce7..b4470abfe26 100644 --- a/tests/baselines/reference/defaultKeywordWithoutExport2.symbols +++ b/tests/baselines/reference/defaultKeywordWithoutExport2.symbols @@ -1,5 +1,5 @@ === tests/cases/compiler/defaultKeywordWithoutExport2.ts === default function () { -> : Symbol((Missing), Decl(defaultKeywordWithoutExport2.ts, 0, 7)) - -} +No type information for this code. +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/defaultKeywordWithoutExport2.types b/tests/baselines/reference/defaultKeywordWithoutExport2.types index 3272127383e..b4470abfe26 100644 --- a/tests/baselines/reference/defaultKeywordWithoutExport2.types +++ b/tests/baselines/reference/defaultKeywordWithoutExport2.types @@ -1,5 +1,5 @@ === tests/cases/compiler/defaultKeywordWithoutExport2.ts === default function () { -> : () => void - -} +No type information for this code. +No type information for this code.} +No type information for this code. \ No newline at end of file