Skip to content

Commit ffcb546

Browse files
author
Andy Hanson
committed
Remove unneeded ExportType and ExportNamespace flags
1 parent efc861c commit ffcb546

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
@@ -416,9 +416,8 @@ namespace ts {
416416
}
417417
}
418418
else {
419-
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
420-
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
421-
// on it. There are 2 main reasons:
419+
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue flag,
420+
// and an associated export symbol with all the correct flags set on it. There are 2 main reasons:
422421
//
423422
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
424423
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports
@@ -438,10 +437,7 @@ namespace ts {
438437
(node as JSDocTypedefTag).name.kind === SyntaxKind.Identifier &&
439438
((node as JSDocTypedefTag).name as Identifier).isInJSDocNamespace;
440439
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
441-
const exportKind =
442-
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
443-
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
444-
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
440+
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
445441
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
446442
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
447443
node.localSymbol = local;
@@ -2288,7 +2284,7 @@ namespace ts {
22882284
// When we create a property via 'exports.foo = bar', the 'exports.foo' property access
22892285
// expression is the declaration
22902286
setCommonJsModuleIndicator(node);
2291-
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.Export, SymbolFlags.None);
2287+
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None);
22922288
}
22932289

22942290
function isExportsOrModuleExportsOrAlias(node: Node): boolean {
@@ -2329,7 +2325,7 @@ namespace ts {
23292325

23302326
// 'module.exports = expr' assignment
23312327
setCommonJsModuleIndicator(node);
2332-
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.Export | SymbolFlags.ValueModule, SymbolFlags.None);
2328+
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule, SymbolFlags.None);
23332329
}
23342330

23352331
function bindThisPropertyAssignment(node: BinaryExpression) {

src/compiler/checker.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18809,7 +18809,7 @@ namespace ts {
1880918809
// local symbol is undefined => this declaration is non-exported.
1881018810
// however symbol might contain other declarations that are exported
1881118811
symbol = getSymbolOfNode(node);
18812-
if (!(symbol.flags & SymbolFlags.Export)) {
18812+
if (!symbol.exportSymbol) {
1881318813
// this is a pure local symbol (all declarations are non-exported) - no need to check anything
1881418814
return;
1881518815
}
@@ -18820,11 +18820,9 @@ namespace ts {
1882018820
return;
1882118821
}
1882218822

18823-
// we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
18824-
// to denote disjoint declarationSpaces (without making new enum type).
18825-
let exportedDeclarationSpaces = SymbolFlags.None;
18826-
let nonExportedDeclarationSpaces = SymbolFlags.None;
18827-
let defaultExportedDeclarationSpaces = SymbolFlags.None;
18823+
let exportedDeclarationSpaces = DeclarationSpaces.None;
18824+
let nonExportedDeclarationSpaces = DeclarationSpaces.None;
18825+
let defaultExportedDeclarationSpaces = DeclarationSpaces.None;
1882818826
for (const d of symbol.declarations) {
1882918827
const declarationSpaces = getDeclarationSpaces(d);
1883018828
const effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, ModifierFlags.Export | ModifierFlags.Default);
@@ -18864,28 +18862,34 @@ namespace ts {
1886418862
}
1886518863
}
1886618864

18867-
function getDeclarationSpaces(d: Declaration): SymbolFlags {
18865+
const enum DeclarationSpaces {
18866+
None = 0,
18867+
ExportValue = 1 << 0,
18868+
ExportType = 1 << 1,
18869+
ExportNamespace = 1 << 2,
18870+
}
18871+
function getDeclarationSpaces(d: Declaration): DeclarationSpaces {
1886818872
switch (d.kind) {
1886918873
case SyntaxKind.InterfaceDeclaration:
1887018874
case SyntaxKind.TypeAliasDeclaration:
18871-
return SymbolFlags.ExportType;
18875+
return DeclarationSpaces.ExportType;
1887218876
case SyntaxKind.ModuleDeclaration:
1887318877
return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated
18874-
? SymbolFlags.ExportNamespace | SymbolFlags.ExportValue
18875-
: SymbolFlags.ExportNamespace;
18878+
? DeclarationSpaces.ExportNamespace | DeclarationSpaces.ExportValue
18879+
: DeclarationSpaces.ExportNamespace;
1887618880
case SyntaxKind.ClassDeclaration:
1887718881
case SyntaxKind.EnumDeclaration:
18878-
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
18882+
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
1887918883
case SyntaxKind.ImportEqualsDeclaration:
18880-
let result = SymbolFlags.None;
18884+
let result = DeclarationSpaces.None;
1888118885
const target = resolveAlias(getSymbolOfNode(d));
1888218886
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
1888318887
return result;
1888418888
case SyntaxKind.VariableDeclaration:
1888518889
case SyntaxKind.BindingElement:
1888618890
case SyntaxKind.FunctionDeclaration:
1888718891
case SyntaxKind.ImportSpecifier: // https://github.com/Microsoft/TypeScript/pull/7591
18888-
return SymbolFlags.ExportValue;
18892+
return DeclarationSpaces.ExportValue;
1888918893
default:
1889018894
Debug.fail((ts as any).SyntaxKind[d.kind]);
1889118895
}

src/compiler/types.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,13 +2890,11 @@ namespace ts {
28902890
TypeParameter = 1 << 18, // Type parameter
28912891
TypeAlias = 1 << 19, // Type alias
28922892
ExportValue = 1 << 20, // Exported value marker (see comment in declareModuleMember in binder)
2893-
ExportType = 1 << 21, // Exported type marker (see comment in declareModuleMember in binder)
2894-
ExportNamespace = 1 << 22, // Exported namespace marker (see comment in declareModuleMember in binder)
2895-
Alias = 1 << 23, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker)
2896-
Prototype = 1 << 24, // Prototype property (no source representation)
2897-
ExportStar = 1 << 25, // Export * declaration
2898-
Optional = 1 << 26, // Optional property
2899-
Transient = 1 << 27, // Transient symbol (created during type check)
2893+
Alias = 1 << 21, // An alias for another symbol (see comment in isAliasSymbolDeclaration in checker)
2894+
Prototype = 1 << 22, // Prototype property (no source representation)
2895+
ExportStar = 1 << 23, // Export * declaration
2896+
Optional = 1 << 24, // Optional property
2897+
Transient = 1 << 25, // Transient symbol (created during type check)
29002898

29012899
Enum = RegularEnum | ConstEnum,
29022900
Variable = FunctionScopedVariable | BlockScopedVariable,
@@ -2941,7 +2939,6 @@ namespace ts {
29412939
BlockScoped = BlockScopedVariable | Class | Enum,
29422940

29432941
PropertyOrAccessor = Property | Accessor,
2944-
Export = ExportNamespace | ExportType | ExportValue,
29452942

29462943
ClassMember = Method | Accessor | Property,
29472944

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)