@@ -571,18 +571,24 @@ module ts {
571
571
}
572
572
}
573
573
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).
574
577
function markImportSymbolAsReferenced(symbol: Symbol) {
575
578
var links = getSymbolLinks(symbol);
576
579
if (!links.referenced) {
577
580
links.referenced = true;
578
581
var node = getDeclarationOfImportSymbol(symbol);
579
582
if (node.kind === SyntaxKind.ExportAssignment) {
583
+ // export default <symbol>
580
584
checkExpressionCached((<ExportAssignment>node).expression);
581
585
}
582
586
else if (node.kind === SyntaxKind.ExportSpecifier) {
587
+ // export { <symbol> } or export { <symbol> as foo }
583
588
checkExpressionCached((<ExportSpecifier>node).propertyName || (<ExportSpecifier>node).name);
584
589
}
585
590
else if (isInternalModuleImportEqualsDeclaration(node)) {
591
+ // import foo = <symbol>
586
592
checkExpressionCached(<Expression>(<ImportEqualsDeclaration>node).moduleReference);
587
593
}
588
594
}
@@ -717,6 +723,7 @@ module ts {
717
723
718
724
function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
719
725
if (compilerOptions.target < ScriptTarget.ES6) {
726
+ // A default export hides all other exports in CommonJS and AMD modules
720
727
var defaultSymbol = getExportAssignmentSymbol(moduleSymbol);
721
728
if (defaultSymbol) {
722
729
return {
@@ -729,6 +736,8 @@ module ts {
729
736
visit(moduleSymbol);
730
737
return result || moduleSymbol.exports;
731
738
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.
732
741
function visit(symbol: Symbol) {
733
742
if (!contains(visitedSymbols, symbol)) {
734
743
visitedSymbols.push(symbol);
@@ -738,6 +747,7 @@ module ts {
738
747
}
739
748
extendSymbolTable(result, symbol.exports);
740
749
}
750
+ // All export * declarations are collected in an __export symbol by the binder
741
751
var exportStars = symbol.exports["__export"];
742
752
if (exportStars) {
743
753
forEach(exportStars.declarations, node => {
0 commit comments