-
Notifications
You must be signed in to change notification settings - Fork 12.9k
exported declarations now don't take the exclusive slot #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
39ba2ed
746632a
d61d50f
eecee5a
af7b0ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,40 +125,47 @@ module ts { | |
function declareModuleMember(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { | ||
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue, | ||
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set | ||
// on it. There are 2 main reasons: | ||
// | ||
// 1. We treat locals and exports of the same name as mutually exclusive within a container. | ||
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports | ||
// with the same name in the same container. | ||
// TODO: Make this a more specific error and decouple it from the exclusion logic. | ||
// on it. Reasons: | ||
// 1. During name resolution i.e for types we need to distingush local and exported symbols. | ||
// All members are added to the exported one so local should never be returned. | ||
// 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, | ||
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way | ||
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. | ||
// Exported members will share local symbol with non-exported members | ||
var exportKind = 0; | ||
var exportExcludes = 0; | ||
if (symbolKind & SymbolFlags.Value) { | ||
exportKind |= SymbolFlags.ExportValue; | ||
exportExcludes |= SymbolFlags.Value; | ||
} | ||
if (symbolKind & SymbolFlags.Type) { | ||
exportKind |= SymbolFlags.ExportType; | ||
exportExcludes |= SymbolFlags.Type; | ||
} | ||
if (symbolKind & SymbolFlags.Namespace) { | ||
exportKind |= SymbolFlags.ExportNamespace; | ||
exportExcludes |= SymbolFlags.Namespace; | ||
} | ||
if (node.flags & NodeFlags.Export || (node.kind !== SyntaxKind.ImportDeclaration && isAmbientContext(container))) { | ||
if (exportKind) { | ||
var local = declareSymbol(container.locals, undefined, node, exportKind, exportExcludes); | ||
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); | ||
var exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); | ||
var localSymbol = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); | ||
node.symbol = exportSymbol; | ||
// export function foo(); // 1 | ||
// export function foo() {} // 2 | ||
// at (1) we'll create two symbols: local and exported and link then together | ||
// at (2) the same symbols will be returned as exported and local. | ||
// make sure that local symbol is added to the list of local symbols just once. | ||
if (!localSymbol.exportSymbol) { | ||
if (!exportSymbol.localSymbols) { | ||
exportSymbol.localSymbols = []; | ||
} | ||
exportSymbol.localSymbols.push(localSymbol); | ||
localSymbol.exportSymbol = exportSymbol; | ||
} | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this else block for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is for import aliases. An exported import alias doesn't have a local symbol. |
||
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); | ||
} | ||
} | ||
else { | ||
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes | exportKind); | ||
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); | ||
} | ||
} | ||
|
||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need to set the symbol explicitly if you swap the order of the previous two lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to be explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes