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:
parent
837ed96697
commit
813ddf7909
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(3,1): error TS1128: Declaration or statement expected.
|
||||
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(3,1): error TS1005: 'export' expected.
|
||||
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractManyKeywords.ts(4,17): error TS1005: '=' expected.
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
|
|||
export abstract class B {}
|
||||
default abstract class C {}
|
||||
~~~~~~~
|
||||
!!! error TS1128: Declaration or statement expected.
|
||||
!!! error TS1005: 'export' expected.
|
||||
import abstract class D {}
|
||||
~~~~~
|
||||
!!! error TS1005: '=' expected.
|
|
@ -0,0 +1,10 @@
|
|||
tests/cases/compiler/defaultKeywordWithoutExport1.ts(4,1): error TS1029: 'export' modifier must precede 'default' modifier.
|
||||
|
||||
|
||||
==== tests/cases/compiler/defaultKeywordWithoutExport1.ts (1 errors) ====
|
||||
declare function decorator(constructor: any): any;
|
||||
|
||||
@decorator
|
||||
default class {}
|
||||
~~~~~~~
|
||||
!!! error TS1029: 'export' modifier must precede 'default' modifier.
|
21
tests/baselines/reference/defaultKeywordWithoutExport1.js
Normal file
21
tests/baselines/reference/defaultKeywordWithoutExport1.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
//// [defaultKeywordWithoutExport1.ts]
|
||||
declare function decorator(constructor: any): any;
|
||||
|
||||
@decorator
|
||||
default class {}
|
||||
|
||||
//// [defaultKeywordWithoutExport1.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var default_1 = /** @class */ (function () {
|
||||
function default_1() {
|
||||
}
|
||||
default_1 = __decorate([
|
||||
decorator
|
||||
], default_1);
|
||||
return default_1;
|
||||
}());
|
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/compiler/defaultKeywordWithoutExport1.ts ===
|
||||
declare function decorator(constructor: any): any;
|
||||
>decorator : Symbol(decorator, Decl(defaultKeywordWithoutExport1.ts, 0, 0))
|
||||
>constructor : Symbol(constructor, Decl(defaultKeywordWithoutExport1.ts, 0, 27))
|
||||
|
||||
@decorator
|
||||
>decorator : Symbol(decorator, Decl(defaultKeywordWithoutExport1.ts, 0, 0))
|
||||
|
||||
default class {}
|
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/compiler/defaultKeywordWithoutExport1.ts ===
|
||||
declare function decorator(constructor: any): any;
|
||||
>decorator : (constructor: any) => any
|
||||
>constructor : any
|
||||
|
||||
@decorator
|
||||
>decorator : (constructor: any) => any
|
||||
|
||||
default class {}
|
|
@ -0,0 +1,12 @@
|
|||
tests/cases/compiler/defaultKeywordWithoutExport2.ts(1,1): error TS1005: 'export' expected.
|
||||
tests/cases/compiler/defaultKeywordWithoutExport2.ts(1,18): error TS1003: Identifier expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/defaultKeywordWithoutExport2.ts (2 errors) ====
|
||||
default function () {
|
||||
~~~~~~~
|
||||
!!! error TS1005: 'export' expected.
|
||||
~
|
||||
!!! error TS1003: Identifier expected.
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
//// [defaultKeywordWithoutExport2.ts]
|
||||
default function () {
|
||||
|
||||
}
|
||||
|
||||
//// [defaultKeywordWithoutExport2.js]
|
||||
function () {
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
=== tests/cases/compiler/defaultKeywordWithoutExport2.ts ===
|
||||
default function () {
|
||||
> : Symbol((Missing), Decl(defaultKeywordWithoutExport2.ts, 0, 7))
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
=== tests/cases/compiler/defaultKeywordWithoutExport2.ts ===
|
||||
default function () {
|
||||
> : () => void
|
||||
|
||||
}
|
6
tests/cases/compiler/defaultKeywordWithoutExport1.ts
Normal file
6
tests/cases/compiler/defaultKeywordWithoutExport1.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @experimentaldecorators: true
|
||||
|
||||
declare function decorator(constructor: any): any;
|
||||
|
||||
@decorator
|
||||
default class {}
|
3
tests/cases/compiler/defaultKeywordWithoutExport2.ts
Normal file
3
tests/cases/compiler/defaultKeywordWithoutExport2.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
default function () {
|
||||
|
||||
}
|
Loading…
Reference in a new issue