Skip to content

Commit 371f2df

Browse files
committed
Merge pull request #2139 from Microsoft/DtsExports_all
Exports + .d.ts emit
2 parents f96e52c + 2ad40c2 commit 371f2df

File tree

189 files changed

+4731
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+4731
-604
lines changed

src/compiler/checker.ts

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,19 @@ module ts {
512512
node.kind === SyntaxKind.ExportAssignment;
513513
}
514514

515+
function getAnyImportSyntax(node: Node): AnyImportSyntax {
516+
if (isAliasSymbolDeclaration(node)) {
517+
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
518+
return <ImportEqualsDeclaration>node;
519+
}
520+
521+
while (node.kind !== SyntaxKind.ImportDeclaration) {
522+
node = node.parent;
523+
}
524+
return <ImportDeclaration>node;
525+
}
526+
}
527+
515528
function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
516529
return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
517530
}
@@ -1122,7 +1135,7 @@ module ts {
11221135
}
11231136

11241137
function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
1125-
let aliasesToMakeVisible: ImportEqualsDeclaration[];
1138+
let aliasesToMakeVisible: AnyImportSyntax[];
11261139
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
11271140
return undefined;
11281141
}
@@ -1132,17 +1145,19 @@ module ts {
11321145
if (!isDeclarationVisible(declaration)) {
11331146
// Mark the unexported alias as visible if its parent is visible
11341147
// because these kind of aliases can be used to name types in declaration file
1135-
if (declaration.kind === SyntaxKind.ImportEqualsDeclaration &&
1136-
!(declaration.flags & NodeFlags.Export) &&
1137-
isDeclarationVisible(<Declaration>declaration.parent)) {
1148+
1149+
var anyImportSyntax = getAnyImportSyntax(declaration);
1150+
if (anyImportSyntax &&
1151+
!(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export
1152+
isDeclarationVisible(<Declaration>anyImportSyntax.parent)) {
11381153
getNodeLinks(declaration).isVisible = true;
11391154
if (aliasesToMakeVisible) {
1140-
if (!contains(aliasesToMakeVisible, declaration)) {
1141-
aliasesToMakeVisible.push(<ImportEqualsDeclaration>declaration);
1155+
if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
1156+
aliasesToMakeVisible.push(anyImportSyntax);
11421157
}
11431158
}
11441159
else {
1145-
aliasesToMakeVisible = [<ImportEqualsDeclaration>declaration];
1160+
aliasesToMakeVisible = [anyImportSyntax];
11461161
}
11471162
return true;
11481163
}
@@ -1766,8 +1781,15 @@ module ts {
17661781

17671782
function determineIfDeclarationIsVisible() {
17681783
switch (node.kind) {
1769-
case SyntaxKind.VariableDeclaration:
17701784
case SyntaxKind.BindingElement:
1785+
return isDeclarationVisible(<Declaration>node.parent.parent);
1786+
case SyntaxKind.VariableDeclaration:
1787+
if (isBindingPattern(node.name) &&
1788+
!(<BindingPattern>node.name).elements.length) {
1789+
// If the binding pattern is empty, this variable declaration is not visible
1790+
return false;
1791+
}
1792+
// Otherwise fall through
17711793
case SyntaxKind.ModuleDeclaration:
17721794
case SyntaxKind.ClassDeclaration:
17731795
case SyntaxKind.InterfaceDeclaration:
@@ -1779,7 +1801,7 @@ module ts {
17791801
// If the node is not exported or it is not ambient module element (except import declaration)
17801802
if (!(getCombinedNodeFlags(node) & NodeFlags.Export) &&
17811803
!(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
1782-
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
1804+
return isGlobalSourceFile(parent);
17831805
}
17841806
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
17851807
return isDeclarationVisible(<Declaration>parent);
@@ -1812,6 +1834,8 @@ module ts {
18121834
case SyntaxKind.ParenthesizedType:
18131835
return isDeclarationVisible(<Declaration>node.parent);
18141836

1837+
// Default binding, import specifier and namespace import is visible
1838+
// only on demand so by default it is not visible
18151839
case SyntaxKind.ImportClause:
18161840
case SyntaxKind.NamespaceImport:
18171841
case SyntaxKind.ImportSpecifier:
@@ -1837,6 +1861,40 @@ module ts {
18371861
}
18381862
}
18391863

1864+
function collectLinkedAliases(node: Identifier): Node[]{
1865+
var exportSymbol: Symbol;
1866+
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
1867+
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
1868+
}
1869+
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
1870+
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent);
1871+
}
1872+
var result: Node[] = [];
1873+
if (exportSymbol) {
1874+
buildVisibleNodeList(exportSymbol.declarations);
1875+
}
1876+
return result;
1877+
1878+
function buildVisibleNodeList(declarations: Declaration[]) {
1879+
forEach(declarations, declaration => {
1880+
getNodeLinks(declaration).isVisible = true;
1881+
var resultNode = getAnyImportSyntax(declaration) || declaration;
1882+
if (!contains(result, resultNode)) {
1883+
result.push(resultNode);
1884+
}
1885+
1886+
if (isInternalModuleImportEqualsDeclaration(declaration)) {
1887+
// Add the referenced top container visible
1888+
var internalModuleReference = <Identifier | QualifiedName>(<ImportEqualsDeclaration>declaration).moduleReference;
1889+
var firstIdentifier = getFirstIdentifier(internalModuleReference);
1890+
var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
1891+
Diagnostics.Cannot_find_name_0, firstIdentifier);
1892+
buildVisibleNodeList(importSymbol.declarations);
1893+
}
1894+
});
1895+
}
1896+
}
1897+
18401898
function getRootDeclaration(node: Node): Node {
18411899
while (node.kind === SyntaxKind.BindingElement) {
18421900
node = node.parent.parent;
@@ -11157,6 +11215,11 @@ module ts {
1115711215
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
1115811216
}
1115911217

11218+
function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
11219+
var type = getTypeOfExpression(expr);
11220+
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
11221+
}
11222+
1116011223
function isUnknownIdentifier(location: Node, name: string): boolean {
1116111224
Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location");
1116211225
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
@@ -11200,10 +11263,12 @@ module ts {
1120011263
isImplementationOfOverload,
1120111264
writeTypeOfDeclaration,
1120211265
writeReturnTypeOfSignatureDeclaration,
11266+
writeTypeOfExpression,
1120311267
isSymbolAccessible,
1120411268
isEntityNameVisible,
1120511269
getConstantValue,
1120611270
isUnknownIdentifier,
11271+
collectLinkedAliases,
1120711272
getBlockScopedVariableId,
1120811273
};
1120911274
}
@@ -12141,8 +12206,8 @@ module ts {
1214112206
}
1214212207

1214312208
function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean {
12144-
// A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports:
12145-
// categories:
12209+
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
12210+
// interfaces and imports categories:
1214612211
//
1214712212
// DeclarationElement:
1214812213
// ExportAssignment
@@ -12156,7 +12221,8 @@ module ts {
1215612221
node.kind === SyntaxKind.ImportEqualsDeclaration ||
1215712222
node.kind === SyntaxKind.ExportDeclaration ||
1215812223
node.kind === SyntaxKind.ExportAssignment ||
12159-
(node.flags & NodeFlags.Ambient)) {
12224+
(node.flags & NodeFlags.Ambient) ||
12225+
(node.flags & (NodeFlags.Export | NodeFlags.Default))) {
1216012226

1216112227
return false;
1216212228
}

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ module ts {
415415
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
416416
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
417417
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
418+
Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." },
418419
Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." },
419420
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
420421
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,10 @@
16531653
"category": "Error",
16541654
"code": 4081
16551655
},
1656+
"Default export of the module has or is using private name '{0}'.": {
1657+
"category": "Error",
1658+
"code": 4082
1659+
},
16561660
"Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": {
16571661
"category": "Error",
16581662
"code": 4091

0 commit comments

Comments
 (0)