If there is an export default x;
alias declaration, disallow other default exports (#19872)
This commit is contained in:
parent
a1014b2b13
commit
90ae9ffe6e
|
@ -2205,15 +2205,14 @@ namespace ts {
|
||||||
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
|
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// An export default clause with an expression exports a value
|
const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node)
|
||||||
// We want to exclude both class and function here, this is necessary to issue an error when there are both
|
|
||||||
// default export-assignment and default export function and class declaration.
|
|
||||||
const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(<ExportAssignment>node)
|
|
||||||
// An export default clause with an EntityNameExpression exports all meanings of that identifier
|
// An export default clause with an EntityNameExpression exports all meanings of that identifier
|
||||||
? SymbolFlags.Alias
|
? SymbolFlags.Alias
|
||||||
// An export default clause with any other expression exports a value
|
// An export default clause with any other expression exports a value
|
||||||
: SymbolFlags.Property;
|
: SymbolFlags.Property;
|
||||||
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.Property | SymbolFlags.AliasExcludes | SymbolFlags.Class | SymbolFlags.Function);
|
// If there is an `export default x;` alias declaration, can't `export default` anything else.
|
||||||
|
// (In contrast, you can still have `export default function f() {}` and `export default interface I {}`.)
|
||||||
|
declareSymbol(container.symbol.exports, container.symbol, node, flags, SymbolFlags.All);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3021,6 +3021,10 @@ namespace ts {
|
||||||
Optional = 1 << 24, // Optional property
|
Optional = 1 << 24, // Optional property
|
||||||
Transient = 1 << 25, // Transient symbol (created during type check)
|
Transient = 1 << 25, // Transient symbol (created during type check)
|
||||||
|
|
||||||
|
/* @internal */
|
||||||
|
All = FunctionScopedVariable | BlockScopedVariable | Property | EnumMember | Function | Class | Interface | ConstEnum | RegularEnum | ValueModule | NamespaceModule | TypeLiteral
|
||||||
|
| ObjectLiteral | Method | Constructor | GetAccessor | SetAccessor | Signature | TypeParameter | TypeAlias | ExportValue | Alias | Prototype | ExportStar | Optional | Transient,
|
||||||
|
|
||||||
Enum = RegularEnum | ConstEnum,
|
Enum = RegularEnum | ConstEnum,
|
||||||
Variable = FunctionScopedVariable | BlockScopedVariable,
|
Variable = FunctionScopedVariable | BlockScopedVariable,
|
||||||
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
|
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
tests/cases/compiler/exportDefaultAlias_excludesEverything.ts(1,26): error TS2528: A module cannot have multiple default exports.
|
||||||
|
tests/cases/compiler/exportDefaultAlias_excludesEverything.ts(3,16): error TS2528: A module cannot have multiple default exports.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/exportDefaultAlias_excludesEverything.ts (2 errors) ====
|
||||||
|
export default interface A {}
|
||||||
|
~
|
||||||
|
!!! error TS2528: A module cannot have multiple default exports.
|
||||||
|
interface B {}
|
||||||
|
export default B;
|
||||||
|
~
|
||||||
|
!!! error TS2528: A module cannot have multiple default exports.
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
//// [exportDefaultAlias_excludesEverything.ts]
|
||||||
|
export default interface A {}
|
||||||
|
interface B {}
|
||||||
|
export default B;
|
||||||
|
|
||||||
|
|
||||||
|
//// [exportDefaultAlias_excludesEverything.js]
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
|
@ -0,0 +1,10 @@
|
||||||
|
=== tests/cases/compiler/exportDefaultAlias_excludesEverything.ts ===
|
||||||
|
export default interface A {}
|
||||||
|
>A : Symbol(A, Decl(exportDefaultAlias_excludesEverything.ts, 0, 0))
|
||||||
|
|
||||||
|
interface B {}
|
||||||
|
>B : Symbol(B, Decl(exportDefaultAlias_excludesEverything.ts, 0, 29))
|
||||||
|
|
||||||
|
export default B;
|
||||||
|
>B : Symbol(B, Decl(exportDefaultAlias_excludesEverything.ts, 0, 29))
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
=== tests/cases/compiler/exportDefaultAlias_excludesEverything.ts ===
|
||||||
|
export default interface A {}
|
||||||
|
>A : A
|
||||||
|
|
||||||
|
interface B {}
|
||||||
|
>B : B
|
||||||
|
|
||||||
|
export default B;
|
||||||
|
>B : B
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default interface A {}
|
||||||
|
interface B {}
|
||||||
|
export default B;
|
Loading…
Reference in a new issue