Skip to content

Commit 234358e

Browse files
committed
Unifying ES6 and TypeScript external modules
Export assignments are now equivalent to export of member named "default" Export assignments and exports defaults collected by binder Export * declarations collected by binder Simplified logic for marking import symbols as referenced Removed "location" parameter from resolveEntityName Improved error position reporting in resolveEntityName
1 parent 84760c2 commit 234358e

File tree

4 files changed

+221
-231
lines changed

4 files changed

+221
-231
lines changed

Diff for: src/compiler/binder.ts

+22-12
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ module ts {
112112
return "__new";
113113
case SyntaxKind.IndexSignature:
114114
return "__index";
115+
case SyntaxKind.ExportAssignment:
116+
return "default";
117+
case SyntaxKind.ExportDeclaration:
118+
return "__export";
115119
}
116120
}
117121

@@ -137,9 +141,9 @@ module ts {
137141
: Diagnostics.Duplicate_identifier_0;
138142

139143
forEach(symbol.declarations, declaration => {
140-
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
144+
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
141145
});
142-
file.bindDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
146+
file.bindDiagnostics.push(createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
143147

144148
symbol = createSymbol(0, name);
145149
}
@@ -310,13 +314,6 @@ module ts {
310314
}
311315
}
312316

313-
function bindExportDeclaration(node: ExportDeclaration) {
314-
if (!node.exportClause) {
315-
((<ExportContainer>container).exportStars || ((<ExportContainer>container).exportStars = [])).push(node);
316-
}
317-
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
318-
}
319-
320317
function bindFunctionOrConstructorType(node: SignatureDeclaration) {
321318
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
322319
// to the one we would get for: { <...>(...): T }
@@ -478,9 +475,6 @@ module ts {
478475
case SyntaxKind.ExportSpecifier:
479476
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
480477
break;
481-
case SyntaxKind.ExportDeclaration:
482-
bindExportDeclaration(<ExportDeclaration>node);
483-
break;
484478
case SyntaxKind.ImportClause:
485479
if ((<ImportClause>node).name) {
486480
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
@@ -489,6 +483,22 @@ module ts {
489483
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
490484
}
491485
break;
486+
case SyntaxKind.ExportDeclaration:
487+
if (!(<ExportDeclaration>node).exportClause) {
488+
// All export * declarations are collected in an __export symbol
489+
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.ExportStar, 0);
490+
}
491+
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
492+
break;
493+
case SyntaxKind.ExportAssignment:
494+
if ((<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
495+
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes);
496+
}
497+
else {
498+
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
499+
}
500+
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
501+
break;
492502
case SyntaxKind.SourceFile:
493503
if (isExternalModule(<SourceFile>node)) {
494504
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).fileName) + '"', /*isBlockScopeContainer*/ true);

0 commit comments

Comments
 (0)