mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
gracefully handle default function
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
}
|
||||
@@ -4,5 +4,5 @@ default function () {
|
||||
}
|
||||
|
||||
//// [defaultKeywordWithoutExport2.js]
|
||||
function () {
|
||||
default function () {
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user