diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d22bc986688..1bdeb93e356 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -76,10 +76,11 @@ namespace ts { "amd": ModuleKind.AMD, "system": ModuleKind.System, "umd": ModuleKind.UMD, + "es6": ModuleKind.ES6, }, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, paramType: Diagnostics.KIND, - error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd + error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 }, { name: "newLine", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c2130562f9c..4f7f79812ba 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -160,6 +160,7 @@ namespace ts { Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead." }, + Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile modules into 'es6' when targeting 'ES5' or lower." }, 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." }, Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, 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." }, @@ -527,7 +528,7 @@ namespace ts { Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." }, 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)" }, - 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'" }, + Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -548,7 +549,7 @@ namespace ts { Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - 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'." }, + Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." }, 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'." }, 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 or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a2002d17aff..64b4a4ad575 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -627,6 +627,10 @@ "category": "Error", "code": 1203 }, + "Cannot compile modules into 'es6' when targeting 'ES5' or lower.": { + "category": "Error", + "code": 1204 + }, "Decorators are only available when targeting ECMAScript 5 and higher.": { "category": "Error", "code": 1205 @@ -2098,7 +2102,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', 'system', or 'umd'": { + "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'": { "category": "Message", "code": 6016 }, @@ -2182,7 +2186,7 @@ "category": "Error", "code": 6045 }, - "Argument for '--module' option must be 'commonjs', 'amd', 'system', or 'umd'.": { + "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'.": { "category": "Error", "code": 6046 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 649a5076778..c632bab0887 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1026,6 +1026,11 @@ namespace ts { programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } + // Cannot specify module gen target of es6 when below es6 + if (options.module === ModuleKind.ES6 && languageVersion < ScriptTarget.ES6) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower)); + } + // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted if (options.outDir || // there is --outDir specified diff --git a/tests/baselines/reference/es5andes6module.errors.txt b/tests/baselines/reference/es5andes6module.errors.txt new file mode 100644 index 00000000000..d5a672b9486 --- /dev/null +++ b/tests/baselines/reference/es5andes6module.errors.txt @@ -0,0 +1,19 @@ +error TS1204: Cannot compile modules into 'es6' when targeting 'ES5' or lower. + + +!!! error TS1204: Cannot compile modules into 'es6' when targeting 'ES5' or lower. +==== tests/cases/compiler/es5andes6module.ts (0 errors) ==== + + export default class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/es5andes6module.js b/tests/baselines/reference/es5andes6module.js new file mode 100644 index 00000000000..0d489357852 --- /dev/null +++ b/tests/baselines/reference/es5andes6module.js @@ -0,0 +1,26 @@ +//// [es5andes6module.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5andes6module.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.default = A; diff --git a/tests/baselines/reference/es6modulekind.js b/tests/baselines/reference/es6modulekind.js new file mode 100644 index 00000000000..96b315389d1 --- /dev/null +++ b/tests/baselines/reference/es6modulekind.js @@ -0,0 +1,23 @@ +//// [es6modulekind.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6modulekind.js] +export default class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/es6modulekind.symbols b/tests/baselines/reference/es6modulekind.symbols new file mode 100644 index 00000000000..0b5eeb2a6fb --- /dev/null +++ b/tests/baselines/reference/es6modulekind.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6modulekind.ts === + +export default class A +>A : Symbol(A, Decl(es6modulekind.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es6modulekind.ts, 6, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6modulekind.types b/tests/baselines/reference/es6modulekind.types new file mode 100644 index 00000000000..d7fde0c7d44 --- /dev/null +++ b/tests/baselines/reference/es6modulekind.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6modulekind.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/cases/compiler/es5andes6module.ts b/tests/cases/compiler/es5andes6module.ts new file mode 100644 index 00000000000..0fbff3c23d2 --- /dev/null +++ b/tests/cases/compiler/es5andes6module.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: es6 + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es6modulekind.ts b/tests/cases/compiler/es6modulekind.ts new file mode 100644 index 00000000000..0722e1690a3 --- /dev/null +++ b/tests/cases/compiler/es6modulekind.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: es6 + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file