Skip to content

Commit 824808c

Browse files
committed
Merge pull request #2840 from Microsoft/systemModule
Added support for emitting System.register modules
2 parents 218e101 + af89255 commit 824808c

Some content is hidden

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

63 files changed

+6959
-102
lines changed

Diff for: src/compiler/checker.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -10689,9 +10689,15 @@ module ts {
1068910689
}
1069010690
checkExternalModuleExports(container);
1069110691

10692-
if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) {
10693-
// export assignment is deprecated in es6 or above
10694-
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
10692+
if (node.isExportEquals) {
10693+
if (languageVersion >= ScriptTarget.ES6) {
10694+
// export assignment is deprecated in es6 or above
10695+
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead);
10696+
}
10697+
else if (compilerOptions.module === ModuleKind.System) {
10698+
// system modules does not support export assignment
10699+
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
10700+
}
1069510701
}
1069610702
}
1069710703

@@ -11514,9 +11520,11 @@ module ts {
1151411520

1151511521
function getExportNameSubstitution(symbol: Symbol, location: Node, getGeneratedNameForNode: (Node: Node) => string): string {
1151611522
if (isExternalModuleSymbol(symbol.parent)) {
11517-
// If this is es6 or higher, just use the name of the export
11523+
// 1. If this is es6 or higher, just use the name of the export
1151811524
// no need to qualify it.
11519-
if (languageVersion >= ScriptTarget.ES6) {
11525+
// 2. export mechanism for System modules is different from CJS\AMD
11526+
// and it does not need qualifications for exports
11527+
if (languageVersion >= ScriptTarget.ES6 || compilerOptions.module === ModuleKind.System) {
1152011528
return undefined;
1152111529
}
1152211530
return "exports." + unescapeIdentifier(symbol.name);
@@ -11877,6 +11885,15 @@ module ts {
1187711885
return !!resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
1187811886
}
1187911887

11888+
function getReferencedValueDeclaration(reference: Identifier): Declaration {
11889+
Debug.assert(!nodeIsSynthesized(reference));
11890+
let symbol =
11891+
getNodeLinks(reference).resolvedSymbol ||
11892+
resolveName(reference, reference.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
11893+
11894+
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
11895+
}
11896+
1188011897
function getBlockScopedVariableId(n: Identifier): number {
1188111898
Debug.assert(!nodeIsSynthesized(n));
1188211899

@@ -11935,6 +11952,7 @@ module ts {
1193511952
resolvesToSomeValue,
1193611953
collectLinkedAliases,
1193711954
getBlockScopedVariableId,
11955+
getReferencedValueDeclaration,
1193811956
serializeTypeOfNode,
1193911957
serializeParameterTypesOfNode,
1194011958
serializeReturnTypeOfNode,

Diff for: src/compiler/commandLineParser.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ module ts {
5151
type: {
5252
"commonjs": ModuleKind.CommonJS,
5353
"amd": ModuleKind.AMD,
54-
"umd": ModuleKind.UMD
54+
"system": ModuleKind.System,
55+
"umd": ModuleKind.UMD,
5556
},
56-
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_or_umd,
57+
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd,
5758
paramType: Diagnostics.KIND,
58-
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_or_umd
59+
error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd
5960
},
6061
{
6162
name: "noEmit",

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ module ts {
161161
Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
162162
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." },
163163
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_commonjs_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher." },
164+
Cannot_compile_external_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." },
165165
Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." },
166166
Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." },
167167
Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." },
@@ -175,6 +175,7 @@ module ts {
175175
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
176176
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
177177
Type_expected_0_is_a_reserved_word_in_strict_mode_Module_is_automatically_in_strict_mode: { code: 1217, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Module is automatically in strict mode." },
178+
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
178179
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
179180
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." },
180181
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -464,7 +465,7 @@ module ts {
464465
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
465466
Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." },
466467
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
467-
Specify_module_code_generation_Colon_commonjs_amd_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', or 'umd'." },
468+
Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" },
468469
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
469470
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
470471
Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." },
@@ -485,7 +486,7 @@ module ts {
485486
Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
486487
Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
487488
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
488-
Argument_for_module_option_must_be_commonjs_amd_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'." },
489+
Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." },
489490
Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." },
490491
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'." },
491492
Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },

Diff for: src/compiler/diagnosticMessages.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@
631631
"category": "Error",
632632
"code": 1203
633633
},
634-
"Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.": {
634+
"Cannot compile external modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.": {
635635
"category": "Error",
636636
"code": 1204
637637
},
@@ -687,6 +687,10 @@
687687
"category": "Error",
688688
"code": 1217
689689
},
690+
"Export assignment is not supported when '--module' flag is 'system'.": {
691+
"category": "Error",
692+
"code": 1218
693+
},
690694
"Duplicate identifier '{0}'.": {
691695
"category": "Error",
692696
"code": 2300
@@ -1844,7 +1848,7 @@
18441848
"category": "Message",
18451849
"code": 6015
18461850
},
1847-
"Specify module code generation: 'commonjs', 'amd', or 'umd'.": {
1851+
"Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'": {
18481852
"category": "Message",
18491853
"code": 6016
18501854
},
@@ -1928,7 +1932,7 @@
19281932
"category": "Error",
19291933
"code": 6045
19301934
},
1931-
"Argument for '--module' option must be 'commonjs', 'amd', or 'umd'.": {
1935+
"Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'.": {
19321936
"category": "Error",
19331937
"code": 6046
19341938
},

0 commit comments

Comments
 (0)