Skip to content

Commit 42a0c34

Browse files
committed
Merge pull request #2335 from Microsoft/es6ImportExportEmit
ES6 emit for new import / export syntax
2 parents 6155832 + a06ce61 commit 42a0c34

File tree

200 files changed

+5480
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+5480
-181
lines changed

scripts/processDiagnosticMessages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
6565
' ' + convertPropertyName(nameMap[name]) +
6666
': { code: ' + diagnosticDetails.code +
6767
', category: DiagnosticCategory.' + diagnosticDetails.category +
68-
', key: "' + name.replace('"', '\\"') + '"' +
69-
(diagnosticDetails.isEarly ? ', isEarly: true' : '') +
68+
', key: "' + name.replace(/[\"]/g, '\\"') + '"' +
7069
' },\r\n';
7170
}
7271

src/compiler/checker.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ module ts {
783783
}
784784

785785
function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
786-
if (compilerOptions.target < ScriptTarget.ES6) {
786+
if (languageVersion < ScriptTarget.ES6) {
787787
// A default export hides all other exports in CommonJS and AMD modules
788788
let defaultSymbol = getExportAssignmentSymbol(moduleSymbol);
789789
if (defaultSymbol) {
@@ -1812,6 +1812,11 @@ module ts {
18121812
case SyntaxKind.ParenthesizedType:
18131813
return isDeclarationVisible(<Declaration>node.parent);
18141814

1815+
case SyntaxKind.ImportClause:
1816+
case SyntaxKind.NamespaceImport:
1817+
case SyntaxKind.ImportSpecifier:
1818+
return false;
1819+
18151820
// Type parameters are always visible
18161821
case SyntaxKind.TypeParameter:
18171822
// Source file is always visible
@@ -10093,6 +10098,12 @@ module ts {
1009310098
}
1009410099
}
1009510100
}
10101+
else {
10102+
if (languageVersion >= ScriptTarget.ES6) {
10103+
// Import equals declaration is deprecated in es6 or above
10104+
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead);
10105+
}
10106+
}
1009610107
}
1009710108
}
1009810109

@@ -10140,6 +10151,11 @@ module ts {
1014010151
}
1014110152

1014210153
checkExternalModuleExports(container);
10154+
10155+
if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) {
10156+
// export assignment is deprecated in es6 or above
10157+
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
10158+
}
1014310159
}
1014410160

1014510161
function getModuleStatements(node: Declaration): ModuleElement[] {
@@ -10182,7 +10198,7 @@ module ts {
1018210198
if (!links.exportsChecked) {
1018310199
let defaultSymbol = getExportAssignmentSymbol(moduleSymbol);
1018410200
if (defaultSymbol) {
10185-
if (hasExportedMembers(moduleSymbol)) {
10201+
if (languageVersion < ScriptTarget.ES6 && hasExportedMembers(moduleSymbol)) {
1018610202
let declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration;
1018710203
error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
1018810204
}
@@ -11005,7 +11021,15 @@ module ts {
1100511021

1100611022
function getExportNameSubstitution(symbol: Symbol, location: Node): string {
1100711023
if (isExternalModuleSymbol(symbol.parent)) {
11008-
return "exports." + unescapeIdentifier(symbol.name);
11024+
var symbolName = unescapeIdentifier(symbol.name);
11025+
// If this is es6 or higher, just use the name of the export
11026+
// no need to qualify it.
11027+
if (languageVersion >= ScriptTarget.ES6) {
11028+
return symbolName;
11029+
}
11030+
else {
11031+
return "exports." + symbolName;
11032+
}
1100911033
}
1101011034
let node = location;
1101111035
let containerSymbol = getParentOfSymbol(symbol);
@@ -11033,7 +11057,7 @@ module ts {
1103311057
return getExportNameSubstitution(exportSymbol, node.parent);
1103411058
}
1103511059
// Named imports from ES6 import declarations are rewritten
11036-
if (symbol.flags & SymbolFlags.Alias) {
11060+
if (symbol.flags & SymbolFlags.Alias && languageVersion < ScriptTarget.ES6) {
1103711061
return getAliasNameSubstitution(symbol);
1103811062
}
1103911063
}
@@ -11069,7 +11093,6 @@ module ts {
1106911093
return true;
1107011094
}
1107111095
}
11072-
return forEachChild(node, isReferencedAliasDeclaration);
1107311096
}
1107411097

1107511098
function isImplementationOfOverload(node: FunctionLikeDeclaration) {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ module ts {
159159
Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
160160
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
161161
A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." },
162+
Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." },
163+
Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." },
164+
Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." },
162165
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
163166
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." },
164167
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,18 @@
627627
"category": "Error",
628628
"code": 1201
629629
},
630+
"Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": {
631+
"category": "Error",
632+
"code": 1202
633+
},
634+
"Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.": {
635+
"category": "Error",
636+
"code": 1203
637+
},
638+
"Cannot compile external modules into amd or commonjs when targeting es6 or higher.": {
639+
"category": "Error",
640+
"code": 1204
641+
},
630642

631643
"Duplicate identifier '{0}'.": {
632644
"category": "Error",

0 commit comments

Comments
 (0)