mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
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:
@@ -41139,6 +41139,9 @@ namespace ts {
|
||||
if (container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container)) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module);
|
||||
}
|
||||
else if (!(flags & ModifierFlags.Export)) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "export", "default");
|
||||
}
|
||||
|
||||
flags |= ModifierFlags.Default;
|
||||
break;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user