mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-08 22:29:37 -05:00
Simplify setting constEnumOnlyModule (#19735)
This commit is contained in:
@@ -1570,7 +1570,7 @@ namespace ts {
|
||||
else {
|
||||
let pattern: Pattern | undefined;
|
||||
if (node.name.kind === SyntaxKind.StringLiteral) {
|
||||
const text = (<StringLiteral>node.name).text;
|
||||
const { text } = node.name;
|
||||
if (hasZeroOrOneAsteriskCharacter(text)) {
|
||||
pattern = tryParsePattern(text);
|
||||
}
|
||||
@@ -1589,22 +1589,13 @@ namespace ts {
|
||||
else {
|
||||
const state = declareModuleSymbol(node);
|
||||
if (state !== ModuleInstanceState.NonInstantiated) {
|
||||
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
|
||||
// if module was already merged with some function, class or non-const enum
|
||||
// treat is a non-const-enum-only
|
||||
node.symbol.constEnumOnlyModule = false;
|
||||
}
|
||||
else {
|
||||
const currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
|
||||
if (node.symbol.constEnumOnlyModule === undefined) {
|
||||
// non-merged case - use the current state
|
||||
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
|
||||
}
|
||||
else {
|
||||
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
|
||||
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
|
||||
}
|
||||
}
|
||||
const { symbol } = node;
|
||||
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
|
||||
symbol.constEnumOnlyModule = (!(symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)))
|
||||
// Current must be `const enum` only
|
||||
&& state === ModuleInstanceState.ConstEnumOnly
|
||||
// Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
|
||||
&& symbol.constEnumOnlyModule !== false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user