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 11 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
45 changes: 35 additions & 10 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 @@ -516,6 +540,7 @@ module ts {
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
268 changes: 163 additions & 105 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,6 @@ module ts {
return hasProperty(map, key) ? map[key] : undefined;
}

export function mapToArray<T>(map: Map<T>): T[] {
let result: T[] = [];

for (let id in map) {
result.push(map[id]);
}

return result;
}

export function copyMap<T>(source: Map<T>, target: Map<T>): void {
for (let p in source) {
target[p] = source[p];
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module ts {
The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer: { code: 1189, category: DiagnosticCategory.Error, key: "The variable declaration of a 'for...in' statement cannot have an initializer." },
The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer: { code: 1190, category: DiagnosticCategory.Error, key: "The variable declaration of a 'for...of' statement cannot have an initializer." },
An_import_declaration_cannot_have_modifiers: { code: 1191, category: DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." },
External_module_0_has_no_default_export_or_export_assignment: { code: 1192, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export or export assignment." },
External_module_0_has_no_default_export: { code: 1192, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export." },
An_export_declaration_cannot_have_modifiers: { code: 1193, category: DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." },
Export_declarations_are_not_permitted_in_an_internal_module: { code: 1194, category: DiagnosticCategory.Error, key: "Export declarations are not permitted in an internal module." },
Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: DiagnosticCategory.Error, key: "Catch clause variable name must be an identifier." },
Expand Down Expand Up @@ -340,6 +340,8 @@ module ts {
Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." },
Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." },
Type_0_is_not_an_array_type_or_a_string_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." },
External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2496, category: DiagnosticCategory.Error, key: "External module '{0}' resolves to a non-module entity and cannot be imported using this construct." },
External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2497, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
Expand Down
10 changes: 9 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
"category": "Error",
"code": 1191
},
"External module '{0}' has no default export or export assignment.": {
"External module '{0}' has no default export.": {
"category": "Error",
"code": 1192
},
Expand Down Expand Up @@ -1351,6 +1351,14 @@
"category": "Error",
"code": 2461
},
"External module '{0}' resolves to a non-module entity and cannot be imported using this construct.": {
"category": "Error",
"code": 2496
},
"External module '{0}' uses 'export =' and cannot be used with 'export *'.": {
"category": "Error",
"code": 2497
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
Loading