Skip to content

Commit 5ffcc42

Browse files
author
Andy
authored
Simplify setting constEnumOnlyModule (microsoft#19735)
1 parent 5c23f59 commit 5ffcc42

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/compiler/binder.ts

+8-17
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ namespace ts {
15701570
else {
15711571
let pattern: Pattern | undefined;
15721572
if (node.name.kind === SyntaxKind.StringLiteral) {
1573-
const text = (<StringLiteral>node.name).text;
1573+
const { text } = node.name;
15741574
if (hasZeroOrOneAsteriskCharacter(text)) {
15751575
pattern = tryParsePattern(text);
15761576
}
@@ -1589,22 +1589,13 @@ namespace ts {
15891589
else {
15901590
const state = declareModuleSymbol(node);
15911591
if (state !== ModuleInstanceState.NonInstantiated) {
1592-
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
1593-
// if module was already merged with some function, class or non-const enum
1594-
// treat is a non-const-enum-only
1595-
node.symbol.constEnumOnlyModule = false;
1596-
}
1597-
else {
1598-
const currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
1599-
if (node.symbol.constEnumOnlyModule === undefined) {
1600-
// non-merged case - use the current state
1601-
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
1602-
}
1603-
else {
1604-
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
1605-
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
1606-
}
1607-
}
1592+
const { symbol } = node;
1593+
// if module was already merged with some function, class or non-const enum, treat it as non-const-enum-only
1594+
symbol.constEnumOnlyModule = (!(symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)))
1595+
// Current must be `const enum` only
1596+
&& state === ModuleInstanceState.ConstEnumOnly
1597+
// Can't have been set to 'false' in a previous merged symbol. ('undefined' OK)
1598+
&& symbol.constEnumOnlyModule !== false;
16081599
}
16091600
}
16101601
}

0 commit comments

Comments
 (0)