ensure export modifier is used before default modifier (#44570)

* ensure export modifier is used before default modifier

* gracefully handle `default function`

* Revert "gracefully handle `default function`"

This reverts commit 1d8e288754.

* give better error message on default without leading export
This commit is contained in:
Zzzen
2021-07-01 00:43:14 +08:00
committed by GitHub
parent 837ed96697
commit 813ddf7909
13 changed files with 97 additions and 3 deletions

View File

@@ -2429,7 +2429,10 @@ namespace ts {
function parsingContextErrors(context: ParsingContext) {
switch (context) {
case ParsingContext.SourceElements: return parseErrorAtCurrentToken(Diagnostics.Declaration_or_statement_expected);
case ParsingContext.SourceElements:
return token() === SyntaxKind.DefaultKeyword
? parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.ExportKeyword))
: parseErrorAtCurrentToken(Diagnostics.Declaration_or_statement_expected);
case ParsingContext.BlockStatements: return parseErrorAtCurrentToken(Diagnostics.Declaration_or_statement_expected);
case ParsingContext.SwitchClauses: return parseErrorAtCurrentToken(Diagnostics.case_or_default_expected);
case ParsingContext.SwitchClauseStatements: return parseErrorAtCurrentToken(Diagnostics.Statement_expected);