Skip to content

Commit

Permalink
Unifying ES6 and TypeScript external modules
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ahejlsberg committed Mar 2, 2015
1 parent 84760c2 commit 234358e
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 231 deletions.
34 changes: 22 additions & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ module ts {
return "__new";
case SyntaxKind.IndexSignature:
return "__index";
case SyntaxKind.ExportAssignment:
return "default";

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Mar 4, 2015

Contributor

can you comment here that the name of the member is actually intended to be 'default', and that it needs to be that because consuming code can do "e.default" or "e['default']" to access it?

case SyntaxKind.ExportDeclaration:
return "__export";
}
}

Expand All @@ -137,9 +141,9 @@ module ts {
: Diagnostics.Duplicate_identifier_0;

forEach(symbol.declarations, declaration => {
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Mar 4, 2015

Contributor

We have a helper that gets the best child node to report an error on for a given node. We should just call that here. That helper should see if the thing has a name, and if so return it, otherwise return something better (or the whole declaration if necessary). That way all code benefits from the helper.

This comment has been minimized.

Copy link
@ahejlsberg

ahejlsberg Mar 4, 2015

Author Member

We have one already? What's it called and where is it?

});
file.bindDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
file.bindDiagnostics.push(createDiagnosticForNode(node.name || node, message, getDisplayName(node)));

symbol = createSymbol(0, name);
}
Expand Down Expand Up @@ -310,13 +314,6 @@ module ts {
}
}

function bindExportDeclaration(node: ExportDeclaration) {
if (!node.exportClause) {
((<ExportContainer>container).exportStars || ((<ExportContainer>container).exportStars = [])).push(node);
}
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
}

function bindFunctionOrConstructorType(node: SignatureDeclaration) {
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
// to the one we would get for: { <...>(...): T }
Expand Down Expand Up @@ -478,9 +475,6 @@ module ts {
case SyntaxKind.ExportSpecifier:
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.ExportDeclaration:
bindExportDeclaration(<ExportDeclaration>node);
break;
case SyntaxKind.ImportClause:
if ((<ImportClause>node).name) {
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
Expand All @@ -489,6 +483,22 @@ module ts {
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
}
break;
case SyntaxKind.ExportDeclaration:
if (!(<ExportDeclaration>node).exportClause) {
// All export * declarations are collected in an __export symbol

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Mar 4, 2015

Contributor

I'm not sure what this means. can you clarify what this means in the code?

declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.ExportStar, 0);
}
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.ExportAssignment:
if ((<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Mar 4, 2015

Contributor

Can you comment in the code the distinction here between why we treat an identifier and non-identifier differently?

This comment has been minimized.

Copy link
@ahejlsberg

ahejlsberg Mar 4, 2015

Author Member

There are comments in the final code. Would be better for you to start there.

declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes);
}
else {
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
}
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.SourceFile:
if (isExternalModule(<SourceFile>node)) {
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).fileName) + '"', /*isBlockScopeContainer*/ true);
Expand Down
Loading

0 comments on commit 234358e

Please sign in to comment.