Skip to content

Commit 8594005

Browse files
author
Andy Hanson
committed
Remove unneeded ExportType and ExportNamespace flags
1 parent aeb5264 commit 8594005

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

src/compiler/binder.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,8 @@ namespace ts {
414414
}
415415
}
416416
else {
417-
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
418-
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
419-
// on it. There are 2 main reasons:
417+
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue flag,
418+
// and an associated export symbol with all the correct flags set on it. There are 2 main reasons:
420419
//
421420
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
422421
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports
@@ -436,10 +435,7 @@ namespace ts {
436435
(node as JSDocTypedefTag).name.kind === SyntaxKind.Identifier &&
437436
((node as JSDocTypedefTag).name as Identifier).isInJSDocNamespace;
438437
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
439-
const exportKind =
440-
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
441-
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
442-
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
438+
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
443439
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
444440
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
445441
node.localSymbol = local;
@@ -2306,7 +2302,7 @@ namespace ts {
23062302
// When we create a property via 'exports.foo = bar', the 'exports.foo' property access
23072303
// expression is the declaration
23082304
setCommonJsModuleIndicator(node);
2309-
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.Export, SymbolFlags.None);
2305+
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None);
23102306
}
23112307

23122308
function isExportsOrModuleExportsOrAlias(node: Node): boolean {
@@ -2347,7 +2343,7 @@ namespace ts {
23472343

23482344
// 'module.exports = expr' assignment
23492345
setCommonJsModuleIndicator(node);
2350-
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.Export | SymbolFlags.ValueModule, SymbolFlags.None);
2346+
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule, SymbolFlags.None);
23512347
}
23522348

23532349
function bindThisPropertyAssignment(node: BinaryExpression) {

src/compiler/checker.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18750,7 +18750,7 @@ namespace ts {
1875018750
// local symbol is undefined => this declaration is non-exported.
1875118751
// however symbol might contain other declarations that are exported
1875218752
symbol = getSymbolOfNode(node);
18753-
if (!(symbol.flags & SymbolFlags.Export)) {
18753+
if (!symbol.exportSymbol) {
1875418754
// this is a pure local symbol (all declarations are non-exported) - no need to check anything
1875518755
return;
1875618756
}
@@ -18761,11 +18761,9 @@ namespace ts {
1876118761
return;
1876218762
}
1876318763

18764-
// we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
18765-
// to denote disjoint declarationSpaces (without making new enum type).
18766-
let exportedDeclarationSpaces = SymbolFlags.None;
18767-
let nonExportedDeclarationSpaces = SymbolFlags.None;
18768-
let defaultExportedDeclarationSpaces = SymbolFlags.None;
18764+
let exportedDeclarationSpaces = DeclarationSpaces.None;
18765+
let nonExportedDeclarationSpaces = DeclarationSpaces.None;
18766+
let defaultExportedDeclarationSpaces = DeclarationSpaces.None;
1876918767
for (const d of symbol.declarations) {
1877018768
const declarationSpaces = getDeclarationSpaces(d);
1877118769
const effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, ModifierFlags.Export | ModifierFlags.Default);
@@ -18805,24 +18803,30 @@ namespace ts {
1880518803
}
1880618804
}
1880718805

18808-
function getDeclarationSpaces(d: Declaration): SymbolFlags {
18806+
const enum DeclarationSpaces {
18807+
None = 0,
18808+
ExportValue = 1 << 0,
18809+
ExportType = 1 << 1,
18810+
ExportNamespace = 1 << 2,
18811+
}
18812+
function getDeclarationSpaces(d: Declaration): DeclarationSpaces {
1880918813
switch (d.kind) {
1881018814
case SyntaxKind.InterfaceDeclaration:
18811-
return SymbolFlags.ExportType;
18815+
return DeclarationSpaces.ExportType;
1881218816
case SyntaxKind.ModuleDeclaration:
1881318817
return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated
18814-
? SymbolFlags.ExportNamespace | SymbolFlags.ExportValue
18815-
: SymbolFlags.ExportNamespace;
18818+
? DeclarationSpaces.ExportNamespace | DeclarationSpaces.ExportValue
18819+
: DeclarationSpaces.ExportNamespace;
1881618820
case SyntaxKind.ClassDeclaration:
1881718821
case SyntaxKind.EnumDeclaration:
18818-
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
18822+
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
1881918823
case SyntaxKind.ImportEqualsDeclaration:
18820-
let result: SymbolFlags = 0;
18824+
let result = DeclarationSpaces.None;
1882118825
const target = resolveAlias(getSymbolOfNode(d));
1882218826
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
1882318827
return result;
1882418828
default:
18825-
return SymbolFlags.ExportValue;
18829+
return DeclarationSpaces.ExportValue;
1882618830
}
1882718831
}
1882818832
}

src/compiler/types.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,13 +2863,11 @@ namespace ts {
28632863
TypeParameter = 1 << 18, // Type parameter
28642864
TypeAlias = 1 << 19, // Type alias
28652865
ExportValue = 1 << 20, // Exported value marker (see comment in declareModuleMember in binder)
2866-
ExportType = 1 << 21, // Exported type marker (see comment in declareModuleMember in binder)
2867-
ExportNamespace = 1 << 22, // Exported namespace marker (see comment in declareModuleMember in binder)
2868-
Alias = 1 << 23, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker)
2869-
Prototype = 1 << 24, // Prototype property (no source representation)
2870-
ExportStar = 1 << 25, // Export * declaration
2871-
Optional = 1 << 26, // Optional property
2872-
Transient = 1 << 27, // Transient symbol (created during type check)
2866+
Alias = 1 << 21, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker)
2867+
Prototype = 1 << 22, // Prototype property (no source representation)
2868+
ExportStar = 1 << 23, // Export * declaration
2869+
Optional = 1 << 24, // Optional property
2870+
Transient = 1 << 25, // Transient symbol (created during type check)
28732871

28742872
Enum = RegularEnum | ConstEnum,
28752873
Variable = FunctionScopedVariable | BlockScopedVariable,
@@ -2914,7 +2912,6 @@ namespace ts {
29142912
BlockScoped = BlockScopedVariable | Class | Enum,
29152913

29162914
PropertyOrAccessor = Property | Accessor,
2917-
Export = ExportNamespace | ExportType | ExportValue,
29182915

29192916
ClassMember = Method | Accessor | Property,
29202917

src/services/importTracker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ namespace ts.FindAllReferences {
440440

441441
function getExport(): ExportedSymbol | ImportedSymbol | undefined {
442442
const parent = node.parent!;
443-
if (symbol.flags & SymbolFlags.Export) {
443+
if (symbol.exportSymbol) {
444444
if (parent.kind === SyntaxKind.PropertyAccessExpression) {
445445
// When accessing an export of a JS module, there's no alias. The symbol will still be flagged as an export even though we're at the use.
446446
// So check that we are at the declaration.
@@ -449,9 +449,7 @@ namespace ts.FindAllReferences {
449449
: undefined;
450450
}
451451
else {
452-
const { exportSymbol } = symbol;
453-
Debug.assert(!!exportSymbol);
454-
return exportInfo(exportSymbol, getExportKindForDeclaration(parent));
452+
return exportInfo(symbol.exportSymbol, getExportKindForDeclaration(parent));
455453
}
456454
}
457455
else {

0 commit comments

Comments
 (0)