From 48ba708e5e50e03214b8deba48a9306ac42eeb1d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 15 Sep 2015 15:36:37 -0700 Subject: [PATCH 1/7] Add es6 module kind, stop using script version to infer it --- src/compiler/commandLineParser.ts | 5 +- .../diagnosticInformationMap.generated.ts | 6 +- src/compiler/diagnosticMessages.json | 6 +- src/compiler/emitter.ts | 43 +++--- src/compiler/program.ts | 10 +- src/compiler/types.ts | 1 + .../constDeclarations-access5.errors.txt | 2 - .../reference/constDeclarations-access5.js | 66 ++++----- tests/baselines/reference/es6-amd.errors.txt | 18 --- tests/baselines/reference/es6-amd.symbols | 16 +++ tests/baselines/reference/es6-amd.types | 17 +++ .../reference/es6-declaration-amd.errors.txt | 18 --- .../reference/es6-declaration-amd.symbols | 16 +++ .../reference/es6-declaration-amd.types | 17 +++ .../reference/es6-sourcemap-amd.errors.txt | 18 --- .../reference/es6-sourcemap-amd.symbols | 16 +++ .../reference/es6-sourcemap-amd.types | 17 +++ tests/baselines/reference/es6-umd.errors.txt | 18 --- tests/baselines/reference/es6-umd.symbols | 16 +++ tests/baselines/reference/es6-umd.types | 17 +++ tests/baselines/reference/es6-umd2.errors.txt | 18 --- tests/baselines/reference/es6-umd2.js | 20 ++- tests/baselines/reference/es6-umd2.symbols | 16 +++ tests/baselines/reference/es6-umd2.types | 17 +++ ...tBindingFollowedWithNamedImport.errors.txt | 25 ---- ...rtDefaultBindingFollowedWithNamedImport.js | 30 ++-- ...aultBindingFollowedWithNamedImport.symbols | 67 +++++++++ ...efaultBindingFollowedWithNamedImport.types | 69 ++++++++++ .../es6ImportNameSpaceImport.errors.txt | 13 -- .../reference/es6ImportNameSpaceImport.js | 4 +- .../es6ImportNameSpaceImport.symbols | 18 +++ .../reference/es6ImportNameSpaceImport.types | 19 +++ .../reference/es6ImportNamedImport.errors.txt | 44 ------ .../reference/es6ImportNamedImport.js | 58 ++++---- .../reference/es6ImportNamedImport.symbols | 123 +++++++++++++++++ .../reference/es6ImportNamedImport.types | 129 ++++++++++++++++++ ...rtNamedImportInExportAssignment.errors.txt | 2 - .../es6ImportNamedImportInExportAssignment.js | 5 +- ...es6ModuleWithModuleGenTargetAmd.errors.txt | 16 --- .../es6ModuleWithModuleGenTargetAmd.js | 15 +- .../es6ModuleWithModuleGenTargetAmd.symbols | 14 ++ .../es6ModuleWithModuleGenTargetAmd.types | 15 ++ ...duleWithModuleGenTargetCommonjs.errors.txt | 16 --- .../es6ModuleWithModuleGenTargetCommonjs.js | 3 +- ...6ModuleWithModuleGenTargetCommonjs.symbols | 14 ++ ...es6ModuleWithModuleGenTargetCommonjs.types | 15 ++ .../reference/systemModule1.errors.txt | 7 - tests/baselines/reference/systemModule1.js | 10 +- .../baselines/reference/systemModule1.symbols | 5 + tests/baselines/reference/systemModule1.types | 6 + 50 files changed, 814 insertions(+), 342 deletions(-) delete mode 100644 tests/baselines/reference/es6-amd.errors.txt create mode 100644 tests/baselines/reference/es6-amd.symbols create mode 100644 tests/baselines/reference/es6-amd.types delete mode 100644 tests/baselines/reference/es6-declaration-amd.errors.txt create mode 100644 tests/baselines/reference/es6-declaration-amd.symbols create mode 100644 tests/baselines/reference/es6-declaration-amd.types delete mode 100644 tests/baselines/reference/es6-sourcemap-amd.errors.txt create mode 100644 tests/baselines/reference/es6-sourcemap-amd.symbols create mode 100644 tests/baselines/reference/es6-sourcemap-amd.types delete mode 100644 tests/baselines/reference/es6-umd.errors.txt create mode 100644 tests/baselines/reference/es6-umd.symbols create mode 100644 tests/baselines/reference/es6-umd.types delete mode 100644 tests/baselines/reference/es6-umd2.errors.txt create mode 100644 tests/baselines/reference/es6-umd2.symbols create mode 100644 tests/baselines/reference/es6-umd2.types delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.symbols create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types delete mode 100644 tests/baselines/reference/es6ImportNameSpaceImport.errors.txt create mode 100644 tests/baselines/reference/es6ImportNameSpaceImport.symbols create mode 100644 tests/baselines/reference/es6ImportNameSpaceImport.types delete mode 100644 tests/baselines/reference/es6ImportNamedImport.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImport.symbols create mode 100644 tests/baselines/reference/es6ImportNamedImport.types delete mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.symbols create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.types delete mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.symbols create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.types delete mode 100644 tests/baselines/reference/systemModule1.errors.txt create mode 100644 tests/baselines/reference/systemModule1.symbols create mode 100644 tests/baselines/reference/systemModule1.types diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d22bc98668840..1bdeb93e35604 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 7d1d63e5a565d..ccd3b2be73edd 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -160,7 +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_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." }, 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." }, - Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." }, + 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." }, @@ -528,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." }, @@ -549,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 245be4a3c9b5f..a7bbdf16a19a7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -627,7 +627,7 @@ "category": "Error", "code": 1203 }, - "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.": { + "Cannot compile modules into 'es6' when targeting 'ES5' or lower.": { "category": "Error", "code": 1204 }, @@ -2102,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 }, @@ -2186,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/emitter.ts b/src/compiler/emitter.ts index 5410cd9c681c4..89c8f375bce01 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -188,6 +188,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** If removeComments is true, no leading-comments needed to be emitted **/ let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos: number) { } : emitLeadingCommentsOfPositionWorker; + + let moduleEmitDelegates: Map<(node: SourceFile, startIndex: number) => void> = { + [ModuleKind.ES6]: emitES6Module, + [ModuleKind.AMD]: emitAMDModule, + [ModuleKind.System]: emitSystemModule, + [ModuleKind.UMD]: emitUMDModule, + [ModuleKind.CommonJS]: emitCommonJSModule, + }; if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { initializeEmitterWithSourceMaps(); @@ -1493,7 +1501,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (container) { if (container.kind === SyntaxKind.SourceFile) { // Identifier references module export - if (languageVersion < ScriptTarget.ES6 && compilerOptions.module !== ModuleKind.System) { + if (compilerOptions.module !== ModuleKind.ES6 && compilerOptions.module !== ModuleKind.System) { write("exports."); } } @@ -1503,7 +1511,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("."); } } - else if (languageVersion < ScriptTarget.ES6) { + else if (compilerOptions.module !== ModuleKind.ES6) { let declaration = resolver.getReferencedImportDeclaration(node); if (declaration) { if (declaration.kind === SyntaxKind.ImportClause) { @@ -3049,7 +3057,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(getGeneratedNameForNode(container)); write("."); } - else if (languageVersion < ScriptTarget.ES6 && compilerOptions.module !== ModuleKind.System) { + else if (compilerOptions.module !== ModuleKind.ES6 && compilerOptions.module !== ModuleKind.System) { write("exports."); } } @@ -3469,7 +3477,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function isES6ExportedDeclaration(node: Node) { return !!(node.flags & NodeFlags.Export) && - languageVersion >= ScriptTarget.ES6 && + compilerOptions.module === ModuleKind.ES6 && node.parent.kind === SyntaxKind.SourceFile; } @@ -5421,7 +5429,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitImportDeclaration(node: ImportDeclaration) { - if (languageVersion < ScriptTarget.ES6) { + if (compilerOptions.module !== ModuleKind.ES6) { return emitExternalImportDeclaration(node); } @@ -5586,7 +5594,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitExportDeclaration(node: ExportDeclaration) { Debug.assert(compilerOptions.module !== ModuleKind.System); - if (languageVersion < ScriptTarget.ES6) { + if (compilerOptions.module !== ModuleKind.ES6) { if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { emitStart(node); let generatedName = getGeneratedNameForNode(node); @@ -5652,7 +5660,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[], shouldEmit: (node: Node) => boolean) { - Debug.assert(languageVersion >= ScriptTarget.ES6); + Debug.assert(compilerOptions.module === ModuleKind.ES6); let needsComma = false; for (let specifier of specifiers) { @@ -5672,7 +5680,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitExportAssignment(node: ExportAssignment) { if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - if (languageVersion >= ScriptTarget.ES6) { + if (compilerOptions.module === ModuleKind.ES6) { writeLine(); emitStart(node); write("export default "); @@ -6681,7 +6689,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitSourceFileNode(node: SourceFile) { + function emitSourceFileNode(node: SourceFile) { // Start new file on new line writeLine(); emitShebang(); @@ -6691,21 +6699,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); if (isExternalModule(node) || compilerOptions.isolatedModules) { - if (languageVersion >= ScriptTarget.ES6) { - emitES6Module(node, startIndex); - } - else if (compilerOptions.module === ModuleKind.AMD) { - emitAMDModule(node, startIndex); - } - else if (compilerOptions.module === ModuleKind.System) { - emitSystemModule(node, startIndex); - } - else if (compilerOptions.module === ModuleKind.UMD) { - emitUMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } + let emitModule = moduleEmitDelegates[compilerOptions.module] || moduleEmitDelegates[ModuleKind.CommonJS]; + emitModule(node, startIndex); } else { externalImports = undefined; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1ac4151e8345d..c632bab0887f0 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -343,6 +343,10 @@ namespace ts { let classifiableNames: Map; let skipDefaultLib = options.noLib; + + if (options.target >= ScriptTarget.ES6 && !options.module) { // Preserve old ES6 module behavior + options.module = ModuleKind.ES6; + } let start = new Date().getTime(); @@ -1022,9 +1026,9 @@ 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 when in es6 or above - if (options.module && languageVersion >= ScriptTarget.ES6) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + // 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 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c16ec511d85d7..8f722f03ac113 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2076,6 +2076,7 @@ namespace ts { AMD = 2, UMD = 3, System = 4, + ES6 = 5, } export const enum JsxEmit { diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index d58abfe6bd4a3..23858ddf11c12 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,4 +1,3 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: 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. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -20,7 +19,6 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ==== /// import m = require('constDeclarations_access_1'); diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 7735e37d2b0c3..71b8c99ae58f0 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -49,35 +49,39 @@ m.x.toString(); //// [constDeclarations_access_1.js] -export const x = 0; +define(["require", "exports"], function (require, exports) { + exports.x = 0; +}); //// [constDeclarations_access_2.js] -// Errors -m.x = 1; -m.x += 2; -m.x -= 3; -m.x *= 4; -m.x /= 5; -m.x %= 6; -m.x <<= 7; -m.x >>= 8; -m.x >>>= 9; -m.x &= 10; -m.x |= 11; -m.x ^= 12; -m; -m.x++; -m.x--; -++m.x; ---m.x; -++((m.x)); -m["x"] = 0; -// OK -var a = m.x + 1; -function f(v) { } -f(m.x); -if (m.x) { } -m.x; -(m.x); --m.x; -+m.x; -m.x.toString(); +define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { + // Errors + m.x = 1; + m.x += 2; + m.x -= 3; + m.x *= 4; + m.x /= 5; + m.x %= 6; + m.x <<= 7; + m.x >>= 8; + m.x >>>= 9; + m.x &= 10; + m.x |= 11; + m.x ^= 12; + m; + m.x++; + m.x--; + ++m.x; + --m.x; + ++((m.x)); + m["x"] = 0; + // OK + var a = m.x + 1; + function f(v) { } + f(m.x); + if (m.x) { } + m.x; + (m.x); + -m.x; + +m.x; + m.x.toString(); +}); diff --git a/tests/baselines/reference/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt deleted file mode 100644 index b4a6442458b78..0000000000000 --- a/tests/baselines/reference/es6-amd.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6-amd.ts (0 errors) ==== - - class A - { - constructor () - { - - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.symbols b/tests/baselines/reference/es6-amd.symbols new file mode 100644 index 0000000000000..ad5cf38e7cd09 --- /dev/null +++ b/tests/baselines/reference/es6-amd.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-amd.ts === + +class A +>A : Symbol(A, Decl(es6-amd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es6-amd.ts, 6, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6-amd.types new file mode 100644 index 0000000000000..7a6fb6e32f559 --- /dev/null +++ b/tests/baselines/reference/es6-amd.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt deleted file mode 100644 index fe5a254dd54a4..0000000000000 --- a/tests/baselines/reference/es6-declaration-amd.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ==== - - class A - { - constructor () - { - - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.symbols b/tests/baselines/reference/es6-declaration-amd.symbols new file mode 100644 index 0000000000000..f1a728396cc58 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-declaration-amd.ts === + +class A +>A : Symbol(A, Decl(es6-declaration-amd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es6-declaration-amd.ts, 6, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es6-declaration-amd.types new file mode 100644 index 0000000000000..a46d22c82c58d --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6-declaration-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt deleted file mode 100644 index 8ffa16aaa2397..0000000000000 --- a/tests/baselines/reference/es6-sourcemap-amd.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ==== - - class A - { - constructor () - { - - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.symbols b/tests/baselines/reference/es6-sourcemap-amd.symbols new file mode 100644 index 0000000000000..13be6367ba0d3 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-sourcemap-amd.ts === + +class A +>A : Symbol(A, Decl(es6-sourcemap-amd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es6-sourcemap-amd.ts, 6, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es6-sourcemap-amd.types new file mode 100644 index 0000000000000..580a688afab44 --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6-sourcemap-amd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/es6-umd.errors.txt b/tests/baselines/reference/es6-umd.errors.txt deleted file mode 100644 index 72a58585073bc..0000000000000 --- a/tests/baselines/reference/es6-umd.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6-umd.ts (0 errors) ==== - - class A - { - constructor () - { - - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.symbols b/tests/baselines/reference/es6-umd.symbols new file mode 100644 index 0000000000000..f7c57215ea6d3 --- /dev/null +++ b/tests/baselines/reference/es6-umd.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-umd.ts === + +class A +>A : Symbol(A, Decl(es6-umd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es6-umd.ts, 6, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-umd.types b/tests/baselines/reference/es6-umd.types new file mode 100644 index 0000000000000..f43c491e003a5 --- /dev/null +++ b/tests/baselines/reference/es6-umd.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6-umd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/es6-umd2.errors.txt b/tests/baselines/reference/es6-umd2.errors.txt deleted file mode 100644 index 00becfb105fa1..0000000000000 --- a/tests/baselines/reference/es6-umd2.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6-umd2.ts (0 errors) ==== - - export class A - { - constructor () - { - - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.js b/tests/baselines/reference/es6-umd2.js index 416932d89bc2a..04c17d49951fb 100644 --- a/tests/baselines/reference/es6-umd2.js +++ b/tests/baselines/reference/es6-umd2.js @@ -14,10 +14,20 @@ export class A } //// [es6-umd2.js] -export class A { - constructor() { +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; } - B() { - return 42; + else if (typeof define === 'function' && define.amd) { + define(deps, factory); } -} +})(["require", "exports"], function (require, exports) { + class A { + constructor() { + } + B() { + return 42; + } + } + exports.A = A; +}); diff --git a/tests/baselines/reference/es6-umd2.symbols b/tests/baselines/reference/es6-umd2.symbols new file mode 100644 index 0000000000000..88acf1272798e --- /dev/null +++ b/tests/baselines/reference/es6-umd2.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/es6-umd2.ts === + +export class A +>A : Symbol(A, Decl(es6-umd2.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es6-umd2.ts, 6, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6-umd2.types b/tests/baselines/reference/es6-umd2.types new file mode 100644 index 0000000000000..eb66523c6ecec --- /dev/null +++ b/tests/baselines/reference/es6-umd2.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6-umd2.ts === + +export class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt deleted file mode 100644 index b0b7465477ba7..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== - - export var a = 10; - export var x = a; - export var m = a; - export default {}; - -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (0 errors) ==== - import defaultBinding1, { } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; - import defaultBinding2, { a } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; - var x1: number = a; - import defaultBinding3, { a as b } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; - var x1: number = b; - import defaultBinding4, { x, a as y } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; - var x1: number = x; - var x1: number = y; - import defaultBinding5, { x as z, } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; - var x1: number = z; - import defaultBinding6, { m, } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; - var x1: number = m; - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index 554fecf9116ca..d6be494a8d1ad 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -23,22 +23,22 @@ var x1: number = m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] -export var a = 10; -export var x = a; -export var m = a; -export default {}; +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +exports.default = {}; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] -import { a } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; -var x1 = a; -import { a as b } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; -var x1 = b; -import { x, a as y } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; -var x1 = x; -var x1 = y; -import { x as z } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; -var x1 = z; -import { m } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; -var x1 = m; +var es6ImportDefaultBindingFollowedWithNamedImport_0_1 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_1.a; +var es6ImportDefaultBindingFollowedWithNamedImport_0_2 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_2.a; +var es6ImportDefaultBindingFollowedWithNamedImport_0_3 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_3.x; +var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_3.a; +var es6ImportDefaultBindingFollowedWithNamedImport_0_4 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_4.x; +var es6ImportDefaultBindingFollowedWithNamedImport_0_5 = require("./es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImport_0_5.m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.symbols b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.symbols new file mode 100644 index 0000000000000..5da138f6c6242 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.symbols @@ -0,0 +1,67 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts === + +export var a = 10; +>a : Symbol(a, Decl(es6ImportDefaultBindingFollowedWithNamedImport_0.ts, 1, 10)) + +export var x = a; +>x : Symbol(x, Decl(es6ImportDefaultBindingFollowedWithNamedImport_0.ts, 2, 10)) +>a : Symbol(a, Decl(es6ImportDefaultBindingFollowedWithNamedImport_0.ts, 1, 10)) + +export var m = a; +>m : Symbol(m, Decl(es6ImportDefaultBindingFollowedWithNamedImport_0.ts, 3, 10)) +>a : Symbol(a, Decl(es6ImportDefaultBindingFollowedWithNamedImport_0.ts, 1, 10)) + +export default {}; + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts === +import defaultBinding1, { } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding1 : Symbol(defaultBinding1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 0, 6)) + +import defaultBinding2, { a } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding2 : Symbol(defaultBinding2, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 1, 6)) +>a : Symbol(a, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 1, 25)) + +var x1: number = a; +>x1 : Symbol(x1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 2, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 4, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 6, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 7, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 9, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 11, 3)) +>a : Symbol(a, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 1, 25)) + +import defaultBinding3, { a as b } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding3 : Symbol(defaultBinding3, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 3, 6)) +>a : Symbol(b, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 3, 25)) +>b : Symbol(b, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 3, 25)) + +var x1: number = b; +>x1 : Symbol(x1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 2, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 4, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 6, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 7, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 9, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 11, 3)) +>b : Symbol(b, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 3, 25)) + +import defaultBinding4, { x, a as y } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding4 : Symbol(defaultBinding4, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 5, 6)) +>x : Symbol(x, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 5, 25)) +>a : Symbol(y, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 5, 28)) +>y : Symbol(y, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 5, 28)) + +var x1: number = x; +>x1 : Symbol(x1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 2, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 4, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 6, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 7, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 9, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 11, 3)) +>x : Symbol(x, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 5, 25)) + +var x1: number = y; +>x1 : Symbol(x1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 2, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 4, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 6, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 7, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 9, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 11, 3)) +>y : Symbol(y, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 5, 28)) + +import defaultBinding5, { x as z, } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding5 : Symbol(defaultBinding5, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 8, 6)) +>x : Symbol(z, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 8, 25)) +>z : Symbol(z, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 8, 25)) + +var x1: number = z; +>x1 : Symbol(x1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 2, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 4, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 6, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 7, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 9, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 11, 3)) +>z : Symbol(z, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 8, 25)) + +import defaultBinding6, { m, } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding6 : Symbol(defaultBinding6, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 10, 6)) +>m : Symbol(m, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 10, 25)) + +var x1: number = m; +>x1 : Symbol(x1, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 2, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 4, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 6, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 7, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 9, 3), Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 11, 3)) +>m : Symbol(m, Decl(es6ImportDefaultBindingFollowedWithNamedImport_1.ts, 10, 25)) + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types new file mode 100644 index 0000000000000..fe0137403a982 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types @@ -0,0 +1,69 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts === + +export var a = 10; +>a : number +>10 : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +export default {}; +>{} : {} + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts === +import defaultBinding1, { } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding1 : {} + +import defaultBinding2, { a } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding2 : {} +>a : number + +var x1: number = a; +>x1 : number +>a : number + +import defaultBinding3, { a as b } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding3 : {} +>a : number +>b : number + +var x1: number = b; +>x1 : number +>b : number + +import defaultBinding4, { x, a as y } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding4 : {} +>x : number +>a : number +>y : number + +var x1: number = x; +>x1 : number +>x : number + +var x1: number = y; +>x1 : number +>y : number + +import defaultBinding5, { x as z, } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding5 : {} +>x : number +>z : number + +var x1: number = z; +>x1 : number +>z : number + +import defaultBinding6, { m, } from "./es6ImportDefaultBindingFollowedWithNamedImport_0"; +>defaultBinding6 : {} +>m : number + +var x1: number = m; +>x1 : number +>m : number + diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt deleted file mode 100644 index 67616662ca832..0000000000000 --- a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportNameSpaceImport_1.ts (0 errors) ==== - import * as nameSpaceBinding from "./es6ImportNameSpaceImport_0"; - var x = nameSpaceBinding.a; - import * as nameSpaceBinding2 from "./es6ImportNameSpaceImport_0"; // elide this - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 7498b8ee9e867..32bdd78b32995 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -11,9 +11,9 @@ import * as nameSpaceBinding2 from "./es6ImportNameSpaceImport_0"; // elide this //// [es6ImportNameSpaceImport_0.js] -export var a = 10; +exports.a = 10; //// [es6ImportNameSpaceImport_1.js] -import * as nameSpaceBinding from "./es6ImportNameSpaceImport_0"; +var nameSpaceBinding = require("./es6ImportNameSpaceImport_0"); var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.symbols b/tests/baselines/reference/es6ImportNameSpaceImport.symbols new file mode 100644 index 0000000000000..add2b792d4916 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts === + +export var a = 10; +>a : Symbol(a, Decl(es6ImportNameSpaceImport_0.ts, 1, 10)) + +=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts === +import * as nameSpaceBinding from "./es6ImportNameSpaceImport_0"; +>nameSpaceBinding : Symbol(nameSpaceBinding, Decl(es6ImportNameSpaceImport_1.ts, 0, 6)) + +var x = nameSpaceBinding.a; +>x : Symbol(x, Decl(es6ImportNameSpaceImport_1.ts, 1, 3)) +>nameSpaceBinding.a : Symbol(nameSpaceBinding.a, Decl(es6ImportNameSpaceImport_0.ts, 1, 10)) +>nameSpaceBinding : Symbol(nameSpaceBinding, Decl(es6ImportNameSpaceImport_1.ts, 0, 6)) +>a : Symbol(nameSpaceBinding.a, Decl(es6ImportNameSpaceImport_0.ts, 1, 10)) + +import * as nameSpaceBinding2 from "./es6ImportNameSpaceImport_0"; // elide this +>nameSpaceBinding2 : Symbol(nameSpaceBinding2, Decl(es6ImportNameSpaceImport_1.ts, 2, 6)) + diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types new file mode 100644 index 0000000000000..56ee0c4d87a99 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts === + +export var a = 10; +>a : number +>10 : number + +=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts === +import * as nameSpaceBinding from "./es6ImportNameSpaceImport_0"; +>nameSpaceBinding : typeof nameSpaceBinding + +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "./es6ImportNameSpaceImport_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt deleted file mode 100644 index efcda1f536874..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImport.errors.txt +++ /dev/null @@ -1,44 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== - - export var a = 10; - export var x = a; - export var m = a; - export var a1 = 10; - export var x1 = 10; - export var z1 = 10; - export var z2 = 10; - export var aaaa = 10; - -==== tests/cases/compiler/es6ImportNamedImport_1.ts (0 errors) ==== - import { } from "./es6ImportNamedImport_0"; - import { a } from "./es6ImportNamedImport_0"; - var xxxx = a; - import { a as b } from "./es6ImportNamedImport_0"; - var xxxx = b; - import { x, a as y } from "./es6ImportNamedImport_0"; - var xxxx = x; - var xxxx = y; - import { x as z, } from "./es6ImportNamedImport_0"; - var xxxx = z; - import { m, } from "./es6ImportNamedImport_0"; - var xxxx = m; - import { a1, x1 } from "./es6ImportNamedImport_0"; - var xxxx = a1; - var xxxx = x1; - import { a1 as a11, x1 as x11 } from "./es6ImportNamedImport_0"; - var xxxx = a11; - var xxxx = x11; - import { z1 } from "./es6ImportNamedImport_0"; - var z111 = z1; - import { z2 as z3 } from "./es6ImportNamedImport_0"; - var z2 = z3; // z2 shouldn't give redeclare error - - // These are elided - import { aaaa } from "./es6ImportNamedImport_0"; - // These are elided - import { aaaa as bbbb } from "./es6ImportNamedImport_0"; - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 6edb6ccb7cd8c..3ed7a6adeb03d 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -42,36 +42,36 @@ import { aaaa as bbbb } from "./es6ImportNamedImport_0"; //// [es6ImportNamedImport_0.js] -export var a = 10; -export var x = a; -export var m = a; -export var a1 = 10; -export var x1 = 10; -export var z1 = 10; -export var z2 = 10; -export var aaaa = 10; +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; //// [es6ImportNamedImport_1.js] -import { a } from "./es6ImportNamedImport_0"; -var xxxx = a; -import { a as b } from "./es6ImportNamedImport_0"; -var xxxx = b; -import { x, a as y } from "./es6ImportNamedImport_0"; -var xxxx = x; -var xxxx = y; -import { x as z } from "./es6ImportNamedImport_0"; -var xxxx = z; -import { m } from "./es6ImportNamedImport_0"; -var xxxx = m; -import { a1, x1 } from "./es6ImportNamedImport_0"; -var xxxx = a1; -var xxxx = x1; -import { a1 as a11, x1 as x11 } from "./es6ImportNamedImport_0"; -var xxxx = a11; -var xxxx = x11; -import { z1 } from "./es6ImportNamedImport_0"; -var z111 = z1; -import { z2 as z3 } from "./es6ImportNamedImport_0"; -var z2 = z3; // z2 shouldn't give redeclare error +var es6ImportNamedImport_0_1 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_1.a; +var es6ImportNamedImport_0_2 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_2.a; +var es6ImportNamedImport_0_3 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_3.x; +var xxxx = es6ImportNamedImport_0_3.a; +var es6ImportNamedImport_0_4 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_4.x; +var es6ImportNamedImport_0_5 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_5.m; +var es6ImportNamedImport_0_6 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_6.a1; +var xxxx = es6ImportNamedImport_0_6.x1; +var es6ImportNamedImport_0_7 = require("./es6ImportNamedImport_0"); +var xxxx = es6ImportNamedImport_0_7.a1; +var xxxx = es6ImportNamedImport_0_7.x1; +var es6ImportNamedImport_0_8 = require("./es6ImportNamedImport_0"); +var z111 = es6ImportNamedImport_0_8.z1; +var es6ImportNamedImport_0_9 = require("./es6ImportNamedImport_0"); +var z2 = es6ImportNamedImport_0_9.z2; // z2 shouldn't give redeclare error //// [es6ImportNamedImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImport.symbols b/tests/baselines/reference/es6ImportNamedImport.symbols new file mode 100644 index 0000000000000..0d30db6113fe4 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.symbols @@ -0,0 +1,123 @@ +=== tests/cases/compiler/es6ImportNamedImport_0.ts === + +export var a = 10; +>a : Symbol(a, Decl(es6ImportNamedImport_0.ts, 1, 10)) + +export var x = a; +>x : Symbol(x, Decl(es6ImportNamedImport_0.ts, 2, 10)) +>a : Symbol(a, Decl(es6ImportNamedImport_0.ts, 1, 10)) + +export var m = a; +>m : Symbol(m, Decl(es6ImportNamedImport_0.ts, 3, 10)) +>a : Symbol(a, Decl(es6ImportNamedImport_0.ts, 1, 10)) + +export var a1 = 10; +>a1 : Symbol(a1, Decl(es6ImportNamedImport_0.ts, 4, 10)) + +export var x1 = 10; +>x1 : Symbol(x1, Decl(es6ImportNamedImport_0.ts, 5, 10)) + +export var z1 = 10; +>z1 : Symbol(z1, Decl(es6ImportNamedImport_0.ts, 6, 10)) + +export var z2 = 10; +>z2 : Symbol(z2, Decl(es6ImportNamedImport_0.ts, 7, 10)) + +export var aaaa = 10; +>aaaa : Symbol(aaaa, Decl(es6ImportNamedImport_0.ts, 8, 10)) + +=== tests/cases/compiler/es6ImportNamedImport_1.ts === +import { } from "./es6ImportNamedImport_0"; +import { a } from "./es6ImportNamedImport_0"; +>a : Symbol(a, Decl(es6ImportNamedImport_1.ts, 1, 8)) + +var xxxx = a; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>a : Symbol(a, Decl(es6ImportNamedImport_1.ts, 1, 8)) + +import { a as b } from "./es6ImportNamedImport_0"; +>a : Symbol(b, Decl(es6ImportNamedImport_1.ts, 3, 8)) +>b : Symbol(b, Decl(es6ImportNamedImport_1.ts, 3, 8)) + +var xxxx = b; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>b : Symbol(b, Decl(es6ImportNamedImport_1.ts, 3, 8)) + +import { x, a as y } from "./es6ImportNamedImport_0"; +>x : Symbol(x, Decl(es6ImportNamedImport_1.ts, 5, 8)) +>a : Symbol(y, Decl(es6ImportNamedImport_1.ts, 5, 11)) +>y : Symbol(y, Decl(es6ImportNamedImport_1.ts, 5, 11)) + +var xxxx = x; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>x : Symbol(x, Decl(es6ImportNamedImport_1.ts, 5, 8)) + +var xxxx = y; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>y : Symbol(y, Decl(es6ImportNamedImport_1.ts, 5, 11)) + +import { x as z, } from "./es6ImportNamedImport_0"; +>x : Symbol(z, Decl(es6ImportNamedImport_1.ts, 8, 8)) +>z : Symbol(z, Decl(es6ImportNamedImport_1.ts, 8, 8)) + +var xxxx = z; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>z : Symbol(z, Decl(es6ImportNamedImport_1.ts, 8, 8)) + +import { m, } from "./es6ImportNamedImport_0"; +>m : Symbol(m, Decl(es6ImportNamedImport_1.ts, 10, 8)) + +var xxxx = m; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>m : Symbol(m, Decl(es6ImportNamedImport_1.ts, 10, 8)) + +import { a1, x1 } from "./es6ImportNamedImport_0"; +>a1 : Symbol(a1, Decl(es6ImportNamedImport_1.ts, 12, 8)) +>x1 : Symbol(x1, Decl(es6ImportNamedImport_1.ts, 12, 12)) + +var xxxx = a1; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>a1 : Symbol(a1, Decl(es6ImportNamedImport_1.ts, 12, 8)) + +var xxxx = x1; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>x1 : Symbol(x1, Decl(es6ImportNamedImport_1.ts, 12, 12)) + +import { a1 as a11, x1 as x11 } from "./es6ImportNamedImport_0"; +>a1 : Symbol(a11, Decl(es6ImportNamedImport_1.ts, 15, 8)) +>a11 : Symbol(a11, Decl(es6ImportNamedImport_1.ts, 15, 8)) +>x1 : Symbol(x11, Decl(es6ImportNamedImport_1.ts, 15, 19)) +>x11 : Symbol(x11, Decl(es6ImportNamedImport_1.ts, 15, 19)) + +var xxxx = a11; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>a11 : Symbol(a11, Decl(es6ImportNamedImport_1.ts, 15, 8)) + +var xxxx = x11; +>xxxx : Symbol(xxxx, Decl(es6ImportNamedImport_1.ts, 2, 3), Decl(es6ImportNamedImport_1.ts, 4, 3), Decl(es6ImportNamedImport_1.ts, 6, 3), Decl(es6ImportNamedImport_1.ts, 7, 3), Decl(es6ImportNamedImport_1.ts, 9, 3), Decl(es6ImportNamedImport_1.ts, 11, 3), Decl(es6ImportNamedImport_1.ts, 13, 3), Decl(es6ImportNamedImport_1.ts, 14, 3), Decl(es6ImportNamedImport_1.ts, 16, 3), Decl(es6ImportNamedImport_1.ts, 17, 3)) +>x11 : Symbol(x11, Decl(es6ImportNamedImport_1.ts, 15, 19)) + +import { z1 } from "./es6ImportNamedImport_0"; +>z1 : Symbol(z1, Decl(es6ImportNamedImport_1.ts, 18, 8)) + +var z111 = z1; +>z111 : Symbol(z111, Decl(es6ImportNamedImport_1.ts, 19, 3)) +>z1 : Symbol(z1, Decl(es6ImportNamedImport_1.ts, 18, 8)) + +import { z2 as z3 } from "./es6ImportNamedImport_0"; +>z2 : Symbol(z3, Decl(es6ImportNamedImport_1.ts, 20, 8)) +>z3 : Symbol(z3, Decl(es6ImportNamedImport_1.ts, 20, 8)) + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : Symbol(z2, Decl(es6ImportNamedImport_1.ts, 21, 3)) +>z3 : Symbol(z3, Decl(es6ImportNamedImport_1.ts, 20, 8)) + +// These are elided +import { aaaa } from "./es6ImportNamedImport_0"; +>aaaa : Symbol(aaaa, Decl(es6ImportNamedImport_1.ts, 24, 8)) + +// These are elided +import { aaaa as bbbb } from "./es6ImportNamedImport_0"; +>aaaa : Symbol(bbbb, Decl(es6ImportNamedImport_1.ts, 26, 8)) +>bbbb : Symbol(bbbb, Decl(es6ImportNamedImport_1.ts, 26, 8)) + diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types new file mode 100644 index 0000000000000..bd7c43d70319b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.types @@ -0,0 +1,129 @@ +=== tests/cases/compiler/es6ImportNamedImport_0.ts === + +export var a = 10; +>a : number +>10 : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +export var a1 = 10; +>a1 : number +>10 : number + +export var x1 = 10; +>x1 : number +>10 : number + +export var z1 = 10; +>z1 : number +>10 : number + +export var z2 = 10; +>z2 : number +>10 : number + +export var aaaa = 10; +>aaaa : number +>10 : number + +=== tests/cases/compiler/es6ImportNamedImport_1.ts === +import { } from "./es6ImportNamedImport_0"; +import { a } from "./es6ImportNamedImport_0"; +>a : number + +var xxxx = a; +>xxxx : number +>a : number + +import { a as b } from "./es6ImportNamedImport_0"; +>a : number +>b : number + +var xxxx = b; +>xxxx : number +>b : number + +import { x, a as y } from "./es6ImportNamedImport_0"; +>x : number +>a : number +>y : number + +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + +import { x as z, } from "./es6ImportNamedImport_0"; +>x : number +>z : number + +var xxxx = z; +>xxxx : number +>z : number + +import { m, } from "./es6ImportNamedImport_0"; +>m : number + +var xxxx = m; +>xxxx : number +>m : number + +import { a1, x1 } from "./es6ImportNamedImport_0"; +>a1 : number +>x1 : number + +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + +import { a1 as a11, x1 as x11 } from "./es6ImportNamedImport_0"; +>a1 : number +>a11 : number +>x1 : number +>x11 : number + +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "./es6ImportNamedImport_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "./es6ImportNamedImport_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "./es6ImportNamedImport_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "./es6ImportNamedImport_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt index fec4d18215802..f397a16690eaf 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -1,8 +1,6 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index 44ac0d188b327..5bdbd89df0786 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -9,9 +9,10 @@ import { a } from "./es6ImportNamedImportInExportAssignment_0"; export = a; //// [es6ImportNamedImportInExportAssignment_0.js] -export var a = 10; +exports.a = 10; //// [es6ImportNamedImportInExportAssignment_1.js] -import { a } from "./es6ImportNamedImportInExportAssignment_0"; +var es6ImportNamedImportInExportAssignment_0_1 = require("./es6ImportNamedImportInExportAssignment_0"); +module.exports = es6ImportNamedImportInExportAssignment_0_1.a; //// [es6ImportNamedImportInExportAssignment_0.d.ts] diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt deleted file mode 100644 index 9592a9f899e64..0000000000000 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== - export class A - { - constructor () - { - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js index 8757bd1c88f52..dec8de1e36ee1 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -12,10 +12,13 @@ export class A } //// [es6ModuleWithModuleGenTargetAmd.js] -export class A { - constructor() { +define(["require", "exports"], function (require, exports) { + class A { + constructor() { + } + B() { + return 42; + } } - B() { - return 42; - } -} + exports.A = A; +}); diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.symbols b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.symbols new file mode 100644 index 0000000000000..24367cc28ad39 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts === +export class A +>A : Symbol(A, Decl(es6ModuleWithModuleGenTargetAmd.ts, 0, 0)) +{ + constructor () + { + } + + public B() +>B : Symbol(B, Decl(es6ModuleWithModuleGenTargetAmd.ts, 4, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.types b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.types new file mode 100644 index 0000000000000..067ceb005e8e2 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts === +export class A +>A : A +{ + constructor () + { + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt deleted file mode 100644 index b740104009982..0000000000000 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== - export class A - { - constructor () - { - } - - public B() - { - return 42; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js index 2df98e20826aa..36e66cb572135 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -12,10 +12,11 @@ export class A } //// [es6ModuleWithModuleGenTargetCommonjs.js] -export class A { +class A { constructor() { } B() { return 42; } } +exports.A = A; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.symbols b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.symbols new file mode 100644 index 0000000000000..4a84c00c48ffe --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts === +export class A +>A : Symbol(A, Decl(es6ModuleWithModuleGenTargetCommonjs.ts, 0, 0)) +{ + constructor () + { + } + + public B() +>B : Symbol(B, Decl(es6ModuleWithModuleGenTargetCommonjs.ts, 4, 5)) + { + return 42; + } +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.types b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.types new file mode 100644 index 0000000000000..58f0f89f955d8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts === +export class A +>A : A +{ + constructor () + { + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} diff --git a/tests/baselines/reference/systemModule1.errors.txt b/tests/baselines/reference/systemModule1.errors.txt deleted file mode 100644 index 18b64607455e3..0000000000000 --- a/tests/baselines/reference/systemModule1.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. - - -!!! error TS1204: Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher. -==== tests/cases/compiler/systemModule1.ts (0 errors) ==== - - export var x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/systemModule1.js b/tests/baselines/reference/systemModule1.js index 9731106471c84..573a7ae04c883 100644 --- a/tests/baselines/reference/systemModule1.js +++ b/tests/baselines/reference/systemModule1.js @@ -3,4 +3,12 @@ export var x = 1; //// [systemModule1.js] -export var x = 1; +System.register([], function(exports_1) { + var x; + return { + setters:[], + execute: function() { + x = 1; + } + } +}); diff --git a/tests/baselines/reference/systemModule1.symbols b/tests/baselines/reference/systemModule1.symbols new file mode 100644 index 0000000000000..d6293c21fd9a9 --- /dev/null +++ b/tests/baselines/reference/systemModule1.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/systemModule1.ts === + +export var x = 1; +>x : Symbol(x, Decl(systemModule1.ts, 1, 10)) + diff --git a/tests/baselines/reference/systemModule1.types b/tests/baselines/reference/systemModule1.types new file mode 100644 index 0000000000000..2adf73d116f88 --- /dev/null +++ b/tests/baselines/reference/systemModule1.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/systemModule1.ts === + +export var x = 1; +>x : number +>1 : number + From c71a0acdff7ebf5724a93f082f41347f40a7f26d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 15 Sep 2015 15:45:23 -0700 Subject: [PATCH 2/7] Pair of new tests for the new flag --- .../reference/es5andes6module.errors.txt | 19 ++++++++++++++ tests/baselines/reference/es5andes6module.js | 26 +++++++++++++++++++ tests/baselines/reference/es6modulekind.js | 23 ++++++++++++++++ .../baselines/reference/es6modulekind.symbols | 16 ++++++++++++ tests/baselines/reference/es6modulekind.types | 17 ++++++++++++ tests/cases/compiler/es5andes6module.ts | 17 ++++++++++++ tests/cases/compiler/es6modulekind.ts | 17 ++++++++++++ 7 files changed, 135 insertions(+) create mode 100644 tests/baselines/reference/es5andes6module.errors.txt create mode 100644 tests/baselines/reference/es5andes6module.js create mode 100644 tests/baselines/reference/es6modulekind.js create mode 100644 tests/baselines/reference/es6modulekind.symbols create mode 100644 tests/baselines/reference/es6modulekind.types create mode 100644 tests/cases/compiler/es5andes6module.ts create mode 100644 tests/cases/compiler/es6modulekind.ts diff --git a/tests/baselines/reference/es5andes6module.errors.txt b/tests/baselines/reference/es5andes6module.errors.txt new file mode 100644 index 0000000000000..d5a672b948628 --- /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 0000000000000..0d489357852cb --- /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 0000000000000..96b315389d10e --- /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 0000000000000..0b5eeb2a6fb07 --- /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 0000000000000..d7fde0c7d4426 --- /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 0000000000000..0fbff3c23d25d --- /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 0000000000000..0722e1690a3c8 --- /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 From 60a120f22affec36891c26abe129fe479ae20119 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 16 Sep 2015 11:08:03 -0700 Subject: [PATCH 3/7] remove es6 as option from command line --- src/compiler/commandLineParser.ts | 5 ++-- .../diagnosticInformationMap.generated.ts | 5 ++-- src/compiler/diagnosticMessages.json | 8 ++---- src/compiler/program.ts | 5 ---- .../reference/es5andes6module.errors.txt | 19 -------------- tests/baselines/reference/es5andes6module.js | 26 ------------------- tests/baselines/reference/es6modulekind.js | 23 ---------------- .../baselines/reference/es6modulekind.symbols | 16 ------------ tests/baselines/reference/es6modulekind.types | 17 ------------ tests/cases/compiler/es5andes6module.ts | 17 ------------ tests/cases/compiler/es6modulekind.ts | 17 ------------ 11 files changed, 6 insertions(+), 152 deletions(-) delete mode 100644 tests/baselines/reference/es5andes6module.errors.txt delete mode 100644 tests/baselines/reference/es5andes6module.js delete mode 100644 tests/baselines/reference/es6modulekind.js delete mode 100644 tests/baselines/reference/es6modulekind.symbols delete mode 100644 tests/baselines/reference/es6modulekind.types delete mode 100644 tests/cases/compiler/es5andes6module.ts delete mode 100644 tests/cases/compiler/es6modulekind.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1bdeb93e35604..d22bc98668840 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -76,11 +76,10 @@ namespace ts { "amd": ModuleKind.AMD, "system": ModuleKind.System, "umd": ModuleKind.UMD, - "es6": ModuleKind.ES6, }, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd, paramType: Diagnostics.KIND, - error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 + error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd }, { name: "newLine", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ccd3b2be73edd..d0839007ecc5f 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -160,7 +160,6 @@ 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_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." }, 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." }, - 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." }, @@ -528,7 +527,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_umd_or_es6: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" }, + 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'" }, 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." }, @@ -549,7 +548,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_umd_or_es6: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." }, + 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_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 a7bbdf16a19a7..80ae01153e962 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -627,10 +627,6 @@ "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 @@ -2102,7 +2098,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'": { + "Specify module code generation: 'commonjs', 'amd', 'system', or 'umd'": { "category": "Message", "code": 6016 }, @@ -2186,7 +2182,7 @@ "category": "Error", "code": 6045 }, - "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'.": { + "Argument for '--module' option must be 'commonjs', 'amd', 'system', or 'umd'.": { "category": "Error", "code": 6046 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c632bab0887f0..649a507677804 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1026,11 +1026,6 @@ 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 deleted file mode 100644 index d5a672b948628..0000000000000 --- a/tests/baselines/reference/es5andes6module.errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 0d489357852cb..0000000000000 --- a/tests/baselines/reference/es5andes6module.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [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 deleted file mode 100644 index 96b315389d10e..0000000000000 --- a/tests/baselines/reference/es6modulekind.js +++ /dev/null @@ -1,23 +0,0 @@ -//// [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 deleted file mode 100644 index 0b5eeb2a6fb07..0000000000000 --- a/tests/baselines/reference/es6modulekind.symbols +++ /dev/null @@ -1,16 +0,0 @@ -=== 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 deleted file mode 100644 index d7fde0c7d4426..0000000000000 --- a/tests/baselines/reference/es6modulekind.types +++ /dev/null @@ -1,17 +0,0 @@ -=== 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 deleted file mode 100644 index 0fbff3c23d25d..0000000000000 --- a/tests/cases/compiler/es5andes6module.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @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 deleted file mode 100644 index 0722e1690a3c8..0000000000000 --- a/tests/cases/compiler/es6modulekind.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @target: ES6 -// @sourcemap: false -// @declaration: false -// @module: es6 - -export default class A -{ - constructor () - { - - } - - public B() - { - return 42; - } -} \ No newline at end of file From 75a5c2229ce5f8dd261174489b739d45057bdc6a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 16 Sep 2015 11:24:41 -0700 Subject: [PATCH 4/7] Fix import/export assignment checks to look at module kind rather than language version --- src/compiler/checker.ts | 10 +++++----- src/compiler/diagnosticInformationMap.generated.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++-- .../reference/constDeclarations-access5.errors.txt | 5 +---- .../reference/es6ExportAssignment.errors.txt | 4 ++-- .../reference/es6ExportAssignment2.errors.txt | 4 ++-- .../baselines/reference/es6ExportEquals.errors.txt | 4 ++-- .../reference/es6ImportEqualsDeclaration.errors.txt | 8 ++++---- ...s6ImportNamedImportInExportAssignment.errors.txt | 12 ------------ .../es6ImportNamedImportInExportAssignment.symbols | 12 ++++++++++++ .../es6ImportNamedImportInExportAssignment.types | 13 +++++++++++++ 11 files changed, 45 insertions(+), 35 deletions(-) delete mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.symbols create mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 13eb00f5af70c..9cb98de096348 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13379,9 +13379,9 @@ namespace ts { } } else { - if (languageVersion >= ScriptTarget.ES6 && !isInAmbientContext(node)) { + if (compilerOptions.module === ModuleKind.ES6 && !isInAmbientContext(node)) { // Import equals declaration is deprecated in es6 or above - 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); + grammarErrorOnNode(node, Diagnostics.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); } } } @@ -13456,9 +13456,9 @@ namespace ts { checkExternalModuleExports(container); if (node.isExportEquals && !isInAmbientContext(node)) { - if (languageVersion >= ScriptTarget.ES6) { - // export assignment is deprecated in es6 or above - grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + if (compilerOptions.module === ModuleKind.ES6) { + // export assignment is not supported in es6 modules + grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead); } else if (compilerOptions.module === ModuleKind.System) { // system modules does not support export assignment diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d0839007ecc5f..c2130562f9ca4 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -158,8 +158,8 @@ namespace ts { An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, 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_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." }, - 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." }, + 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." }, 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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 80ae01153e962..a2002d17affb7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,11 +619,11 @@ "category": "Error", "code": 1200 }, - "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.": { + "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.": { "category": "Error", "code": 1202 }, - "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.": { + "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead.": { "category": "Error", "code": 1203 }, diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 23858ddf11c12..23200e50ee42b 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,4 +1,3 @@ -tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: 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. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -19,11 +18,9 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ==== +==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== /// import m = require('constDeclarations_access_1'); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1202: 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. // Errors m.x = 1; ~~~ diff --git a/tests/baselines/reference/es6ExportAssignment.errors.txt b/tests/baselines/reference/es6ExportAssignment.errors.txt index 1db7d04e05e9f..970d2e184dc51 100644 --- a/tests/baselines/reference/es6ExportAssignment.errors.txt +++ b/tests/baselines/reference/es6ExportAssignment.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. ==== tests/cases/compiler/es6ExportAssignment.ts (1 errors) ==== @@ -6,4 +6,4 @@ tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1203: Export assignmen var a = 10; export = a; ~~~~~~~~~~~ -!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAssignment2.errors.txt b/tests/baselines/reference/es6ExportAssignment2.errors.txt index d5e1dfebd9df7..248491f98c3ac 100644 --- a/tests/baselines/reference/es6ExportAssignment2.errors.txt +++ b/tests/baselines/reference/es6ExportAssignment2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/a.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +tests/cases/compiler/a.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. ==== tests/cases/compiler/a.ts (1 errors) ==== @@ -6,7 +6,7 @@ tests/cases/compiler/a.ts(3,1): error TS1203: Export assignment cannot be used w var a = 10; export = a; // Error: export = not allowed in ES6 ~~~~~~~~~~~ -!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. ==== tests/cases/compiler/b.ts (0 errors) ==== import * as a from "a"; diff --git a/tests/baselines/reference/es6ExportEquals.errors.txt b/tests/baselines/reference/es6ExportEquals.errors.txt index 174c72341f6c9..e8db09456d3e1 100644 --- a/tests/baselines/reference/es6ExportEquals.errors.txt +++ b/tests/baselines/reference/es6ExportEquals.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/es6ExportEquals.ts(4,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +tests/cases/compiler/es6ExportEquals.ts(4,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. tests/cases/compiler/es6ExportEquals.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. @@ -8,7 +8,7 @@ tests/cases/compiler/es6ExportEquals.ts(4,1): error TS2309: An export assignment export = f; ~~~~~~~~~~~ -!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. ~~~~~~~~~~~ !!! error TS2309: An export assignment cannot be used in a module with other exported elements. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt index d3351ee97b22c..7de5d7f0e3d0f 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/client.ts(1,1): error TS1202: 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. -tests/cases/compiler/server.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +tests/cases/compiler/client.ts(1,1): error TS1202: 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. +tests/cases/compiler/server.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. ==== tests/cases/compiler/client.ts (1 errors) ==== import a = require("server"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1202: 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. +!!! error TS1202: 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. ==== tests/cases/compiler/server.ts (1 errors) ==== var a = 10; export = a; ~~~~~~~~~~~ -!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt deleted file mode 100644 index f397a16690eaf..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. - - -==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts (1 errors) ==== - import { a } from "./es6ImportNamedImportInExportAssignment_0"; - export = a; - ~~~~~~~~~~~ -!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.symbols b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.symbols new file mode 100644 index 0000000000000..03ca0740f08a9 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts === + +export var a = 10; +>a : Symbol(a, Decl(es6ImportNamedImportInExportAssignment_0.ts, 1, 10)) + +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts === +import { a } from "./es6ImportNamedImportInExportAssignment_0"; +>a : Symbol(a, Decl(es6ImportNamedImportInExportAssignment_1.ts, 0, 8)) + +export = a; +>a : Symbol(a, Decl(es6ImportNamedImportInExportAssignment_1.ts, 0, 8)) + diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types new file mode 100644 index 0000000000000..09023b6dd8097 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts === + +export var a = 10; +>a : number +>10 : number + +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts === +import { a } from "./es6ImportNamedImportInExportAssignment_0"; +>a : number + +export = a; +>a : number + From f2b901a3c735a6c30981142a0fa324bdb3206abd Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 17 Sep 2015 13:14:31 -0700 Subject: [PATCH 5/7] reverts 60a120f, reexposes es6 option --- src/compiler/commandLineParser.ts | 5 ++-- .../diagnosticInformationMap.generated.ts | 5 ++-- src/compiler/diagnosticMessages.json | 8 ++++-- src/compiler/program.ts | 5 ++++ .../reference/es5andes6module.errors.txt | 19 ++++++++++++++ tests/baselines/reference/es5andes6module.js | 26 +++++++++++++++++++ tests/baselines/reference/es6modulekind.js | 23 ++++++++++++++++ .../baselines/reference/es6modulekind.symbols | 16 ++++++++++++ tests/baselines/reference/es6modulekind.types | 17 ++++++++++++ tests/cases/compiler/es5andes6module.ts | 17 ++++++++++++ tests/cases/compiler/es6modulekind.ts | 17 ++++++++++++ 11 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/es5andes6module.errors.txt create mode 100644 tests/baselines/reference/es5andes6module.js create mode 100644 tests/baselines/reference/es6modulekind.js create mode 100644 tests/baselines/reference/es6modulekind.symbols create mode 100644 tests/baselines/reference/es6modulekind.types create mode 100644 tests/cases/compiler/es5andes6module.ts create mode 100644 tests/cases/compiler/es6modulekind.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d22bc98668840..1bdeb93e35604 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 c2130562f9ca4..4f7f79812babc 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 a2002d17affb7..64b4a4ad5756e 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 649a507677804..c632bab0887f0 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 0000000000000..d5a672b948628 --- /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 0000000000000..0d489357852cb --- /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 0000000000000..96b315389d10e --- /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 0000000000000..0b5eeb2a6fb07 --- /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 0000000000000..d7fde0c7d4426 --- /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 0000000000000..0fbff3c23d25d --- /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 0000000000000..0722e1690a3c8 --- /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 From 8d6cb5fbb56bc1f993e0564ff480f18c09f9a68a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 17 Sep 2015 13:26:04 -0700 Subject: [PATCH 6/7] Feedback from PR --- src/compiler/checker.ts | 7 ++++--- src/compiler/emitter.ts | 45 +++++++++++++++++++++-------------------- src/compiler/program.ts | 4 ---- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9cb98de096348..37bbffee43a3f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -44,6 +44,7 @@ namespace ts { let compilerOptions = host.getCompilerOptions(); let languageVersion = compilerOptions.target || ScriptTarget.ES3; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; let emitResolver = createResolver(); @@ -13379,7 +13380,7 @@ namespace ts { } } else { - if (compilerOptions.module === ModuleKind.ES6 && !isInAmbientContext(node)) { + if (modulekind === ModuleKind.ES6 && !isInAmbientContext(node)) { // Import equals declaration is deprecated in es6 or above grammarErrorOnNode(node, Diagnostics.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); } @@ -13456,11 +13457,11 @@ namespace ts { checkExternalModuleExports(container); if (node.isExportEquals && !isInAmbientContext(node)) { - if (compilerOptions.module === ModuleKind.ES6) { + if (modulekind === ModuleKind.ES6) { // export assignment is not supported in es6 modules grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead); } - else if (compilerOptions.module === ModuleKind.System) { + else if (modulekind === ModuleKind.System) { // system modules does not support export assignment grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 89c8f375bce01..1c5b101f5a733 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -64,6 +64,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let compilerOptions = host.getCompilerOptions(); let languageVersion = compilerOptions.target || ScriptTarget.ES3; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; let diagnostics: Diagnostic[] = []; let newLine = host.getNewLine(); @@ -1501,7 +1502,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (container) { if (container.kind === SyntaxKind.SourceFile) { // Identifier references module export - if (compilerOptions.module !== ModuleKind.ES6 && compilerOptions.module !== ModuleKind.System) { + if (modulekind !== ModuleKind.ES6 && modulekind !== ModuleKind.System) { write("exports."); } } @@ -1511,7 +1512,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("."); } } - else if (compilerOptions.module !== ModuleKind.ES6) { + else if (modulekind !== ModuleKind.ES6) { let declaration = resolver.getReferencedImportDeclaration(node); if (declaration) { if (declaration.kind === SyntaxKind.ImportClause) { @@ -3057,7 +3058,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(getGeneratedNameForNode(container)); write("."); } - else if (compilerOptions.module !== ModuleKind.ES6 && compilerOptions.module !== ModuleKind.System) { + else if (modulekind !== ModuleKind.ES6 && modulekind !== ModuleKind.System) { write("exports."); } } @@ -3077,7 +3078,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (node.parent.kind === SyntaxKind.SourceFile) { Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment); // only allow export default at a source file level - if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { + if (modulekind === ModuleKind.CommonJS || modulekind === ModuleKind.AMD || modulekind === ModuleKind.UMD) { if (!currentSourceFile.symbol.exports["___esModule"]) { if (languageVersion === ScriptTarget.ES5) { // default value of configurable, enumerable, writable are `false`. @@ -3099,7 +3100,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitStart(node); // emit call to exporter only for top level nodes - if (compilerOptions.module === ModuleKind.System && node.parent === currentSourceFile) { + if (modulekind === ModuleKind.System && node.parent === currentSourceFile) { // emit export default as // export("default", ) write(`${exportFunctionForFile}("`); @@ -3135,7 +3136,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitExportMemberAssignments(name: Identifier) { - if (compilerOptions.module === ModuleKind.System) { + if (modulekind === ModuleKind.System) { return; } @@ -3155,7 +3156,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitExportSpecifierInSystemModule(specifier: ExportSpecifier): void { - Debug.assert(compilerOptions.module === ModuleKind.System); + Debug.assert(modulekind === ModuleKind.System); if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier) ) { return; @@ -3477,7 +3478,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function isES6ExportedDeclaration(node: Node) { return !!(node.flags & NodeFlags.Export) && - compilerOptions.module === ModuleKind.ES6 && + modulekind === ModuleKind.ES6 && node.parent.kind === SyntaxKind.SourceFile; } @@ -5243,7 +5244,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(";"); } if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { - if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) { + if (modulekind === ModuleKind.System && (node.flags & NodeFlags.Export)) { // write the call to exporter for enum writeLine(); write(`${exportFunctionForFile}("`); @@ -5365,7 +5366,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(" = {}));"); emitEnd(node); if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { - if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) { + if (modulekind === ModuleKind.System && (node.flags & NodeFlags.Export)) { writeLine(); write(`${exportFunctionForFile}("`); emitDeclarationName(node); @@ -5429,7 +5430,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitImportDeclaration(node: ImportDeclaration) { - if (compilerOptions.module !== ModuleKind.ES6) { + if (modulekind !== ModuleKind.ES6) { return emitExternalImportDeclaration(node); } @@ -5480,7 +5481,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; let namespaceDeclaration = getNamespaceDeclarationNode(node); - if (compilerOptions.module !== ModuleKind.AMD) { + if (modulekind !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); if (namespaceDeclaration && !isDefaultImport(node)) { @@ -5592,15 +5593,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitExportDeclaration(node: ExportDeclaration) { - Debug.assert(compilerOptions.module !== ModuleKind.System); + Debug.assert(modulekind !== ModuleKind.System); - if (compilerOptions.module !== ModuleKind.ES6) { + if (modulekind !== ModuleKind.ES6) { if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { emitStart(node); let generatedName = getGeneratedNameForNode(node); if (node.exportClause) { // export { x, y, ... } from "foo" - if (compilerOptions.module !== ModuleKind.AMD) { + if (modulekind !== ModuleKind.AMD) { write("var "); write(generatedName); write(" = "); @@ -5627,7 +5628,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // export * from "foo" writeLine(); write("__export("); - if (compilerOptions.module !== ModuleKind.AMD) { + if (modulekind !== ModuleKind.AMD) { emitRequire(getExternalModuleName(node)); } else { @@ -5660,7 +5661,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[], shouldEmit: (node: Node) => boolean) { - Debug.assert(compilerOptions.module === ModuleKind.ES6); + Debug.assert(modulekind === ModuleKind.ES6); let needsComma = false; for (let specifier of specifiers) { @@ -5680,7 +5681,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitExportAssignment(node: ExportAssignment) { if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - if (compilerOptions.module === ModuleKind.ES6) { + if (modulekind === ModuleKind.ES6) { writeLine(); emitStart(node); write("export default "); @@ -5695,7 +5696,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi else { writeLine(); emitStart(node); - if (compilerOptions.module === ModuleKind.System) { + if (modulekind === ModuleKind.System) { write(`${exportFunctionForFile}("default",`); emit(node.expression); write(")"); @@ -6141,7 +6142,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function isCurrentFileSystemExternalModule() { - return compilerOptions.module === ModuleKind.System && isExternalModule(currentSourceFile); + return modulekind === ModuleKind.System && isExternalModule(currentSourceFile); } function emitSystemModuleBody(node: SourceFile, dependencyGroups: DependencyGroup[], startIndex: number): void { @@ -6689,7 +6690,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitSourceFileNode(node: SourceFile) { + function emitSourceFileNode(node: SourceFile) { // Start new file on new line writeLine(); emitShebang(); @@ -6699,7 +6700,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); if (isExternalModule(node) || compilerOptions.isolatedModules) { - let emitModule = moduleEmitDelegates[compilerOptions.module] || moduleEmitDelegates[ModuleKind.CommonJS]; + let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS]; emitModule(node, startIndex); } else { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c632bab0887f0..96bad37043ac2 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -343,10 +343,6 @@ namespace ts { let classifiableNames: Map; let skipDefaultLib = options.noLib; - - if (options.target >= ScriptTarget.ES6 && !options.module) { // Preserve old ES6 module behavior - options.module = ModuleKind.ES6; - } let start = new Date().getTime(); From 04b0aa269f6de1eeba23d6a7ff5f537bab5a8672 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 18 Sep 2015 10:29:54 -0700 Subject: [PATCH 7/7] s/var/let --- src/compiler/checker.ts | 2 +- src/compiler/emitter.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 37bbffee43a3f..372521d6c1410 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -44,7 +44,7 @@ namespace ts { let compilerOptions = host.getCompilerOptions(); let languageVersion = compilerOptions.target || ScriptTarget.ES3; - var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; + let modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; let emitResolver = createResolver(); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1c5b101f5a733..4e6d96961a96a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -64,7 +64,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let compilerOptions = host.getCompilerOptions(); let languageVersion = compilerOptions.target || ScriptTarget.ES3; - var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; + let modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; let diagnostics: Diagnostic[] = []; let newLine = host.getNewLine();