Skip to content

Commit 27179b4

Browse files
committed
Adding some comments
1 parent 61167b6 commit 27179b4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ module ts {
129129
function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
130130
Debug.assert(!hasDynamicName(node));
131131

132+
// The exported symbol for an export default function/class node is always named "default"
132133
var name = node.flags & NodeFlags.Default && parent ? "default" : getDeclarationName(node);
134+
133135
if (name !== undefined) {
134136
var symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name));
135137
if (symbol.flags & excludes) {
@@ -495,9 +497,11 @@ module ts {
495497
break;
496498
case SyntaxKind.ExportAssignment:
497499
if ((<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
500+
// An export default clause with an identifier exports all meanings of that identifier
498501
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes);
499502
}
500503
else {
504+
// An export default clause with an expression exports a value
501505
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
502506
}
503507
bindChildren(node, 0, /*isBlockScopeContainer*/ false);

src/compiler/checker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,18 +571,24 @@ module ts {
571571
}
572572
}
573573

574+
// When an import symbol (i.e. an alias) is referenced, we need to mark the entity it references as referenced and in turn
575+
// repeat that until we reach a non-alias or an exported entity (which is always considered referenced). We do this by checking
576+
// the target of the alias as an expression (which recursively takes us back here if the target references another alias).
574577
function markImportSymbolAsReferenced(symbol: Symbol) {
575578
var links = getSymbolLinks(symbol);
576579
if (!links.referenced) {
577580
links.referenced = true;
578581
var node = getDeclarationOfImportSymbol(symbol);
579582
if (node.kind === SyntaxKind.ExportAssignment) {
583+
// export default <symbol>
580584
checkExpressionCached((<ExportAssignment>node).expression);
581585
}
582586
else if (node.kind === SyntaxKind.ExportSpecifier) {
587+
// export { <symbol> } or export { <symbol> as foo }
583588
checkExpressionCached((<ExportSpecifier>node).propertyName || (<ExportSpecifier>node).name);
584589
}
585590
else if (isInternalModuleImportEqualsDeclaration(node)) {
591+
// import foo = <symbol>
586592
checkExpressionCached(<Expression>(<ImportEqualsDeclaration>node).moduleReference);
587593
}
588594
}
@@ -717,6 +723,7 @@ module ts {
717723

718724
function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
719725
if (compilerOptions.target < ScriptTarget.ES6) {
726+
// A default export hides all other exports in CommonJS and AMD modules
720727
var defaultSymbol = getExportAssignmentSymbol(moduleSymbol);
721728
if (defaultSymbol) {
722729
return {
@@ -729,6 +736,8 @@ module ts {
729736
visit(moduleSymbol);
730737
return result || moduleSymbol.exports;
731738

739+
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
740+
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
732741
function visit(symbol: Symbol) {
733742
if (!contains(visitedSymbols, symbol)) {
734743
visitedSymbols.push(symbol);
@@ -738,6 +747,7 @@ module ts {
738747
}
739748
extendSymbolTable(result, symbol.exports);
740749
}
750+
// All export * declarations are collected in an __export symbol by the binder
741751
var exportStars = symbol.exports["__export"];
742752
if (exportStars) {
743753
forEach(exportStars.declarations, node => {

0 commit comments

Comments
 (0)