Skip to content

Es6 module emit #2065

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
19 changes: 16 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9500,6 +9500,10 @@ module ts {
}
}
else {
if (languageVersion >= ScriptTarget.ES6) {
// Import equals declaration is deprecated in es6 or above
grammarErrorOnNode(node, Diagnostics.Deprecated_syntax);
}
if (checkExternalImportOrExportDeclaration(node)) {
checkImportBinding(node);
}
Expand All @@ -9522,6 +9526,10 @@ module ts {
if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers);
}
if (languageVersion >= ScriptTarget.ES6) {
// export assignment is deprecated in es6 or above
grammarErrorOnNode(node, Diagnostics.Deprecated_syntax);
}

var container = node.parent;
if (container.kind !== SyntaxKind.SourceFile) {
Expand Down Expand Up @@ -10347,7 +10355,13 @@ module ts {

function getExportNameSubstitution(symbol: Symbol, location: Node): string {
if (isExternalModuleSymbol(symbol.parent)) {
return "exports." + unescapeIdentifier(symbol.name);
var symbolName = unescapeIdentifier(symbol.name);
if (isAMDOrCommonjsGen(compilerOptions, languageVersion)) {
return "exports." + symbolName;
}
else {
return symbolName;
}
}
var node = location;
var containerSymbol = getParentOfSymbol(symbol);
Expand Down Expand Up @@ -10375,7 +10389,7 @@ module ts {
return getExportNameSubstitution(exportSymbol, node.parent);
}
// Named imports from ES6 import declarations are rewritten
if (symbol.flags & SymbolFlags.Import) {
if ((symbol.flags & SymbolFlags.Import) && isAMDOrCommonjsGen(compilerOptions, languageVersion)) {
return getImportNameSubstitution(symbol);
}
}
Expand Down Expand Up @@ -10416,7 +10430,6 @@ module ts {
return true;
}
}
return forEachChild(node, isReferencedImportDeclaration);
}

function isImplementationOfOverload(node: FunctionLikeDeclaration) {
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ module ts {
External_module_0_has_no_default_export_or_export_assignment: { code: 1189, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export or export assignment." },
An_export_declaration_cannot_have_modifiers: { code: 1190, category: DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." },
Export_declarations_are_not_permitted_in_an_internal_module: { code: 1191, category: DiagnosticCategory.Error, key: "Export declarations are not permitted in an internal module." },
Deprecated_syntax: { code: 1192, category: DiagnosticCategory.Error, key: "Deprecated syntax" },
Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1193, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@
"category": "Error",
"code": 1191
},
"Deprecated syntax": {
"category": "Error",
"code": 1192
},
"Cannot compile external modules into amd or commonjs when targeting es6 or higher.": {
"category": "Error",
"code": 1193
},

"Duplicate identifier '{0}'.": {
"category": "Error",
Expand Down
Loading