Simplify setting constEnumOnlyModule (#19735)

This commit is contained in:
Andy
2017-11-10 09:34:20 -08:00
committed by GitHub
parent 5c23f59a0d
commit 5ffcc42169

View File

@@ -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;
}
}
}