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

Revised ES6 modules #2460

Merged
merged 30 commits into from
Mar 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c39dfdc
Introduce NodeFlags.ExportContext
ahejlsberg Mar 17, 2015
57a9fc5
Separate 'export default' and 'export ='
ahejlsberg Mar 21, 2015
f3fb85f
Accepting new baselines
ahejlsberg Mar 21, 2015
6838d47
Simplify collection of external module info in emitter
ahejlsberg Mar 21, 2015
a152515
Emit and use '__export' helper for 'export *' declarations
ahejlsberg Mar 21, 2015
20d1f73
Add support for exporting imported symbols
ahejlsberg Mar 22, 2015
956d7a8
Fixing emit for import d, * as foo from "foo" case
ahejlsberg Mar 22, 2015
e63854b
Adding basic tests
ahejlsberg Mar 22, 2015
df03c68
Accepting new baselines
ahejlsberg Mar 22, 2015
b2656b0
Deleting unused code
ahejlsberg Mar 22, 2015
3f0cfe3
Adding a few comments
ahejlsberg Mar 22, 2015
6074b3e
Consistently error on more than one 'export default'
ahejlsberg Mar 23, 2015
f90253f
Merge branch 'master' into exportEquals
mhegazy Mar 23, 2015
86d561d
Check for instantiation on export default in ES6
mhegazy Mar 23, 2015
b9e503d
Ellide uninstantiated exports in ES6
mhegazy Mar 23, 2015
d47445b
Merge branch 'exportEquals' of https://github.com/Microsoft/TypeScrip…
mhegazy Mar 23, 2015
d2ead15
Accept baseline changes
mhegazy Mar 23, 2015
580bb83
Fix issue with AMD emit for 'import d, * as x from "foo"'
ahejlsberg Mar 23, 2015
7356775
Accepting new baselines
ahejlsberg Mar 24, 2015
515cdcd
return undefined if we are not renaming to ensure we get the correct …
mhegazy Mar 24, 2015
4361e6e
Merge branch 'exportEquals' into exportEqualsMerged
mhegazy Mar 25, 2015
352633d
Rename isES6ModuleMemberDeclaration to isES6ExportedDeclaration.
mhegazy Mar 25, 2015
27c5d6f
use the correct check for import and export specifiers
mhegazy Mar 25, 2015
6c40c95
Disallow export declarations in internal modules
mhegazy Mar 25, 2015
ab5c09a
Make isReferencedAliasDeclaration check children
mhegazy Mar 25, 2015
bc51dd1
In ES6 use "export var x" for internal modules and enums instead of a…
mhegazy Mar 25, 2015
aa01dcd
Move es6 alias name handeling to getAliasNameSubstitution to match ge…
mhegazy Mar 25, 2015
1c45b77
Merge branch 'master' into exportEqualsMerged
mhegazy Mar 25, 2015
fad8892
Merge branch 'master' into exportEqualsMerged
mhegazy Mar 25, 2015
a05f1e8
Merge pull request #2467 from Microsoft/exportEqualsMerged
ahejlsberg Mar 25, 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
49 changes: 37 additions & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module ts {
case SyntaxKind.ExportDeclaration:
return "__export";
case SyntaxKind.ExportAssignment:
return "default";
return (<ExportAssignment>node).isExportEquals ? "export=" : "default";
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a fairly odd name to give this entity. Is it used elsewhere? if so, we should put it in a common location so we don't have magic strings like this floating around.

Copy link
Member Author

Choose a reason for hiding this comment

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

It needs a name that can meaningfully be shown in error messages (such as duplicate symbol 'export=' when there is more than one). It is used in a few other places, but so are all the other ones here.

case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ClassDeclaration:
return node.flags & NodeFlags.Default ? "default" : undefined;
Expand Down Expand Up @@ -188,14 +188,6 @@ module ts {
return symbol;
}

function isAmbientContext(node: Node): boolean {
while (node) {
if (node.flags & NodeFlags.Ambient) return true;
node = node.parent;
}
return false;
}

function declareModuleMember(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) {
let hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export;
if (symbolKind & SymbolFlags.Alias) {
Expand All @@ -218,7 +210,7 @@ module ts {
// 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
if (hasExportModifier || isAmbientContext(container)) {
if (hasExportModifier || container.flags & NodeFlags.ExportContext) {
let exportKind = (symbolKind & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
(symbolKind & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
(symbolKind & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
Expand Down Expand Up @@ -311,7 +303,39 @@ module ts {
bindChildren(node, symbolKind, isBlockScopeContainer);
}

function isAmbientContext(node: Node): boolean {
while (node) {
if (node.flags & NodeFlags.Ambient) return true;
node = node.parent;
}
return false;
}

function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
var body = node.kind === SyntaxKind.SourceFile ? node : (<ModuleDeclaration>node).body;
if (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock) {
for (let stat of (<Block>body).statements) {
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
return true;
}
}
}
return false;
}

function setExportContextFlag(node: ModuleDeclaration | SourceFile) {
// A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
// declarations with export modifiers) is an export context in which declarations are implicitly exported.
if (isAmbientContext(node) && !hasExportDeclarations(node)) {
node.flags |= NodeFlags.ExportContext;
}
else {
node.flags &= ~NodeFlags.ExportContext;
}
}

function bindModuleDeclaration(node: ModuleDeclaration) {
setExportContextFlag(node);
if (node.name.kind === SyntaxKind.StringLiteral) {
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true);
}
Expand Down Expand Up @@ -508,15 +532,16 @@ module ts {
case SyntaxKind.ExportAssignment:
if ((<ExportAssignment>node).expression && (<ExportAssignment>node).expression.kind === SyntaxKind.Identifier) {
// An export default clause with an identifier exports all meanings of that identifier
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
}
else {
// An export default clause with an expression exports a value
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
declareSymbol(container.symbol.exports, container.symbol, <Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
}
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.SourceFile:
setExportContextFlag(<SourceFile>node);
if (isExternalModule(<SourceFile>node)) {
bindAnonymousDeclaration(<SourceFile>node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).fileName) + '"', /*isBlockScopeContainer*/ true);
break;
Expand Down
Loading