Skip to content
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

Exports + .d.ts emit #2139

Merged
merged 33 commits into from
Mar 18, 2015
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6ac1bcc
Enable declaration emit for import "mod" syntax
sheetalkamat Feb 10, 2015
96139ca
Enable declaration emit for import * as ns from "mod" syntax
sheetalkamat Feb 10, 2015
f2a28a5
Declaration emit for NamedImport syntax
sheetalkamat Feb 9, 2015
05fcdf0
Declaration for default bindings of the import syntax
sheetalkamat Feb 10, 2015
e0323b4
Emit the import declaration in d.ts file only if it is visible
sheetalkamat Feb 11, 2015
c90f820
Enable test cases when import binding is used in export assignment di…
sheetalkamat Feb 11, 2015
863e73c
Test case for emitting partial part of import syntax
sheetalkamat Feb 11, 2015
0dfe425
Test cases for export import syntax
sheetalkamat Feb 9, 2015
00dc5fc
Add test cases for dts generation without export tag
sheetalkamat Feb 11, 2015
f8351c8
Set the declarations of export assignment visible on demand through d…
sheetalkamat Feb 11, 2015
0332fed
Merge branch 'es6Import' into es6ImportDts
sheetalkamat Feb 11, 2015
23c1c5e
Baseline accept after merging
sheetalkamat Feb 11, 2015
649cd3b
Declaration emit fixes for binding pattern in variable statements
sheetalkamat Feb 12, 2015
b88efa1
Test cases to verify the privacy error reporting is done on correct node
sheetalkamat Feb 12, 2015
e7ff4e2
Merge branch 'es6Import' into es6ImportDts
sheetalkamat Feb 13, 2015
5b6a9a8
Merge branch 'es6Import' into es6ImportDts
sheetalkamat Feb 17, 2015
fc1528f
Dts for export * from "mod" and export { a, b as c,...} [from "mod"]
sheetalkamat Feb 17, 2015
96e5286
Merge branch 'master' into es6ImportDts
mhegazy Feb 24, 2015
b8d78f9
Merge remote-tracking branch 'origin/master' into destructuringDts
vladima Feb 25, 2015
f8ae823
merge with master, fix emit for omitted expressions
vladima Feb 25, 2015
210e602
merge with destructuringDts
vladima Feb 25, 2015
300d1fc
Merge branch 'master' into DtsExports_all
vladima Mar 2, 2015
0e2fe02
update baselines
vladima Mar 2, 2015
66b1c02
merge with master
vladima Mar 2, 2015
8796396
merge with master
vladima Mar 13, 2015
a7dac51
merge with master
vladima Mar 14, 2015
e9ea336
Merge branch 'master' into DtsExports_all
vladima Mar 16, 2015
218736b
initial version of declaration emit for default export
vladima Mar 17, 2015
9b62c2c
Merge branch 'master' into DtsExports_all
vladima Mar 17, 2015
eb11607
use type annotation when emitting declarations
vladima Mar 17, 2015
e4f6f16
merge with master, accepted baselines
vladima Mar 18, 2015
c38e065
do not emit non-exported import declarations that don't have import c…
vladima Mar 18, 2015
2ad40c2
addressed PR feedback
vladima Mar 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 78 additions & 12 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,19 @@ module ts {
node.kind === SyntaxKind.ExportAssignment;
}

function getAnyImportSyntax(node: Node): AnyImportSyntax {
if (isAliasSymbolDeclaration(node)) {
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
return <ImportEqualsDeclaration>node;
}

while (node.kind !== SyntaxKind.ImportDeclaration) {
node = node.parent;
}
return <ImportDeclaration>node;
}
}

function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
}
Expand Down Expand Up @@ -1122,7 +1135,7 @@ module ts {
}

function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
let aliasesToMakeVisible: ImportEqualsDeclaration[];
let aliasesToMakeVisible: AnyImportSyntax[];
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
return undefined;
}
Expand All @@ -1132,17 +1145,19 @@ module ts {
if (!isDeclarationVisible(declaration)) {
// Mark the unexported alias as visible if its parent is visible
// because these kind of aliases can be used to name types in declaration file
if (declaration.kind === SyntaxKind.ImportEqualsDeclaration &&
!(declaration.flags & NodeFlags.Export) &&
isDeclarationVisible(<Declaration>declaration.parent)) {

var anyImportSyntax = getAnyImportSyntax(declaration);
if (anyImportSyntax &&
!(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export
isDeclarationVisible(<Declaration>anyImportSyntax.parent)) {
getNodeLinks(declaration).isVisible = true;
if (aliasesToMakeVisible) {
if (!contains(aliasesToMakeVisible, declaration)) {
aliasesToMakeVisible.push(<ImportEqualsDeclaration>declaration);
if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
aliasesToMakeVisible.push(anyImportSyntax);
}
}
else {
aliasesToMakeVisible = [<ImportEqualsDeclaration>declaration];
aliasesToMakeVisible = [anyImportSyntax];
}
return true;
}
Expand Down Expand Up @@ -1766,8 +1781,15 @@ module ts {

function determineIfDeclarationIsVisible() {
switch (node.kind) {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.BindingElement:
return isDeclarationVisible(<Declaration>node.parent.parent);
case SyntaxKind.VariableDeclaration:
if (isBindingPattern(node.name) &&
!(<BindingPattern>node.name).elements.length) {
// If the binding pattern is empty, this variable declaration is not visible
return false;
}
// Otherwise fall through
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
Expand All @@ -1779,7 +1801,7 @@ module ts {
// If the node is not exported or it is not ambient module element (except import declaration)
if (!(getCombinedNodeFlags(node) & NodeFlags.Export) &&
!(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) {
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
return isGlobalSourceFile(parent);
}
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
return isDeclarationVisible(<Declaration>parent);
Expand Down Expand Up @@ -1812,6 +1834,8 @@ module ts {
case SyntaxKind.ParenthesizedType:
return isDeclarationVisible(<Declaration>node.parent);

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

function setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we find a better name.

var exportSymbol: Symbol;
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
}
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent);
}
var result: Node[] = [];
if (exportSymbol) {
buildVisibleNodeList(exportSymbol.declarations);
}
return result;

function buildVisibleNodeList(declarations: Declaration[]) {
forEach(declarations, declaration => {
getNodeLinks(declaration).isVisible = true;
var resultNode = getAnyImportSyntax(declaration) || declaration;
if (!contains(result, resultNode)) {
result.push(resultNode);
}

if (isInternalModuleImportEqualsDeclaration(declaration)) {
// Add the referenced top container visible
var internalModuleReference = <Identifier | QualifiedName>(<ImportEqualsDeclaration>declaration).moduleReference;
var firstIdentifier = getFirstIdentifier(internalModuleReference);
var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
Diagnostics.Cannot_find_name_0, firstIdentifier);
buildVisibleNodeList(importSymbol.declarations);
}
});
}
}

function getRootDeclaration(node: Node): Node {
while (node.kind === SyntaxKind.BindingElement) {
node = node.parent.parent;
Expand Down Expand Up @@ -11157,6 +11215,11 @@ module ts {
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}

function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
var type = getTypeOfExpression(expr);
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
}

function isUnknownIdentifier(location: Node, name: string): boolean {
Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location");
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
Expand Down Expand Up @@ -11200,10 +11263,12 @@ module ts {
isImplementationOfOverload,
writeTypeOfDeclaration,
writeReturnTypeOfSignatureDeclaration,
writeTypeOfExpression,
isSymbolAccessible,
isEntityNameVisible,
getConstantValue,
isUnknownIdentifier,
setDeclarationsOfIdentifierAsVisible,
getBlockScopedVariableId,
};
}
Expand Down Expand Up @@ -12141,8 +12206,8 @@ module ts {
}

function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean {
// A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports:
// categories:
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
// interfaces and imports categories:
//
// DeclarationElement:
// ExportAssignment
Expand All @@ -12156,7 +12221,8 @@ module ts {
node.kind === SyntaxKind.ImportEqualsDeclaration ||
node.kind === SyntaxKind.ExportDeclaration ||
node.kind === SyntaxKind.ExportAssignment ||
(node.flags & NodeFlags.Ambient)) {
(node.flags & NodeFlags.Ambient) ||
(node.flags & (NodeFlags.Export | NodeFlags.Default))) {

return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ module ts {
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}'." },
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}'." },
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}'." },
Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4081, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." },
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." },
The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
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." },
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,10 @@
"category": "Error",
"code": 4081
},
"Default export of the module has or is using private name '{0}'.": {
"category": "Error",
"code": 4081
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update code

},
"Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": {
"category": "Error",
"code": 4091
Expand Down
Loading