diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 47f0594a76..002e049bdd 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -50,11 +50,12 @@ module ts { shortName: "m", type: { "commonjs": ModuleKind.CommonJS, - "amd": ModuleKind.AMD + "amd": ModuleKind.AMD, + "umd": ModuleKind.UMD }, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_or_umd, paramType: Diagnostics.KIND, - error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd + error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_or_umd }, { name: "noEmit", @@ -150,7 +151,7 @@ module ts { type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5, "es6": ScriptTarget.ES6 }, description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: Diagnostics.VERSION, - error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 + error: Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 }, { name: "version", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 90f0ed0a0d..0af10bdb89 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -161,7 +161,7 @@ module 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_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, + Cannot_compile_external_modules_into_amd_commonjs_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher." }, 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." }, @@ -463,7 +463,7 @@ module 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_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, + Specify_module_code_generation_Colon_commonjs_amd_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 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." }, @@ -484,8 +484,8 @@ module 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_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, - 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'." }, + Argument_for_module_option_must_be_commonjs_amd_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'." }, + 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}'." }, Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 48ef245c76..8aa4f73fe7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -631,7 +631,7 @@ "category": "Error", "code": 1203 }, - "Cannot compile external modules into amd or commonjs when targeting es6 or higher.": { + "Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.": { "category": "Error", "code": 1204 }, @@ -1840,7 +1840,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs' or 'amd'": { + "Specify module code generation: 'commonjs', 'amd', or 'umd'.": { "category": "Message", "code": 6016 }, @@ -1924,11 +1924,11 @@ "category": "Error", "code": 6045 }, - "Argument for '--module' option must be 'commonjs' or 'amd'.": { + "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'.": { "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'es3', 'es5', or 'es6'.": { + "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'.": { "category": "Error", "code": 6047 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bb65078009..eb116e924d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4645,27 +4645,25 @@ var __param = this.__param || function(index, decorator) { return function (targ } } - function emitAMDModule(node: SourceFile, startIndex: number) { - collectExternalModuleInfo(node); - + function emitAMDDependencies(node: SourceFile, includeNonAmdDependencies: boolean) { // An AMD define function has the following shape: // define(id?, dependencies?, factory); // // This has the shape of // define(name, ["module1", "module2"], function (module1Alias) { - // The location of the alias in the parameter list in the factory function needs to + // The location of the alias in the parameter list in the factory function needs to // match the position of the module name in the dependency list. // - // To ensure this is true in cases of modules with no aliases, e.g.: - // `import "module"` or `` + // To ensure this is true in cases of modules with no aliases, e.g.: + // `import "module"` or `` // we need to add modules without alias names to the end of the dependencies list - - let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the + + let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the // factory function. let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in // factory function. - let importAliasNames: string[] = []; // names of the parameters in the factory function; these - // paramters need to match the indexes of the corresponding + let importAliasNames: string[] = []; // names of the parameters in the factory function; these + // parameters need to match the indexes of the corresponding // module names in aliasedModuleNames. // Fill in amd-dependency tags @@ -4687,7 +4685,7 @@ var __param = this.__param || function(index, decorator) { return function (targ externalModuleName = getLiteralText(moduleName); } - // Find the name of the module alais, if there is one + // Find the name of the module alias, if there is one let importAliasName: string; let namespaceDeclaration = getNamespaceDeclarationNode(importNode); if (namespaceDeclaration && !isDefaultImport(importNode)) { @@ -4697,7 +4695,7 @@ var __param = this.__param || function(index, decorator) { return function (targ importAliasName = getGeneratedNameForNode(importNode); } - if (importAliasName) { + if (includeNonAmdDependencies && importAliasName) { aliasedModuleNames.push(externalModuleName); importAliasNames.push(importAliasName); } @@ -4705,12 +4703,7 @@ var __param = this.__param || function(index, decorator) { return function (targ unaliasedModuleNames.push(externalModuleName); } } - - writeLine(); - write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); - } + write("[\"require\", \"exports\""); if (aliasedModuleNames.length) { write(", "); @@ -4725,6 +4718,17 @@ var __param = this.__param || function(index, decorator) { return function (targ write(", "); write(importAliasNames.join(", ")); } + } + + function emitAMDModule(node: SourceFile, startIndex: number) { + collectExternalModuleInfo(node); + + writeLine(); + write("define("); + if (node.amdModuleName) { + write("\"" + node.amdModuleName + "\", "); + } + emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); write(") {"); increaseIndent(); emitExportStarHelper(); @@ -4746,6 +4750,31 @@ var __param = this.__param || function(index, decorator) { return function (targ emitExportEquals(/*emitAsReturn*/ false); } + function emitUMDModule(node: SourceFile, startIndex: number) { + collectExternalModuleInfo(node); + + // Module is detected first to support Browserify users that load into a browser with an AMD loader + writeLines(`(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(`); + emitAMDDependencies(node, false); + write(") {"); + increaseIndent(); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitES6Module(node: SourceFile, startIndex: number) { externalImports = undefined; exportSpecifiers = undefined; @@ -4830,6 +4859,9 @@ var __param = this.__param || function(index, decorator) { return function (targ else if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } + else if (compilerOptions.module === ModuleKind.UMD) { + emitUMDModule(node, startIndex); + } else { emitCommonJSModule(node, startIndex); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d49e01bd45..97c681838f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -567,7 +567,7 @@ module ts { // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_commonjs_or_umd_when_targeting_ES6_or_higher)); } // 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 17de069f06..4d2ef95a83 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1674,6 +1674,7 @@ module ts { None = 0, CommonJS = 1, AMD = 2, + UMD = 3, } export interface LineAndCharacter { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 784d8312d6..bec929b7db 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -957,6 +957,8 @@ module Harness { if (typeof setting.value === 'string') { if (setting.value.toLowerCase() === 'amd') { options.module = ts.ModuleKind.AMD; + } else if (setting.value.toLowerCase() === 'umd') { + options.module = ts.ModuleKind.UMD; } else if (setting.value.toLowerCase() === 'commonjs') { options.module = ts.ModuleKind.CommonJS; } else if (setting.value.toLowerCase() === 'unspecified') { diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index a098b0e72c..e689bbf8b4 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,4 +1,4 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' 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 +20,7 @@ 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 external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' 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/es5-umd.js b/tests/baselines/reference/es5-umd.js new file mode 100644 index 0000000000..0175e8e9fe --- /dev/null +++ b/tests/baselines/reference/es5-umd.js @@ -0,0 +1,32 @@ +//// [es5-umd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-umd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es5-umd.js.map + +//// [es5-umd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd.js.map b/tests/baselines/reference/es5-umd.js.map new file mode 100644 index 0000000000..5e29a48796 --- /dev/null +++ b/tests/baselines/reference/es5-umd.js.map @@ -0,0 +1,2 @@ +//// [es5-umd.js.map] +{"version":3,"file":"es5-umd.js","sourceRoot":"","sources":["es5-umd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.sourcemap.txt b/tests/baselines/reference/es5-umd.sourcemap.txt new file mode 100644 index 0000000000..bdbdec5fa9 --- /dev/null +++ b/tests/baselines/reference/es5-umd.sourcemap.txt @@ -0,0 +1,115 @@ +=================================================================== +JsFile: es5-umd.js +mapUrl: es5-umd.js.map +sourceRoot: +sources: es5-umd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd.js +sourceFile:es5-umd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^-> +1->class A + >{ + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=es5-umd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.symbols b/tests/baselines/reference/es5-umd.symbols new file mode 100644 index 0000000000..f570afd954 --- /dev/null +++ b/tests/baselines/reference/es5-umd.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-umd.ts === + +class A +>A : Symbol(A, Decl(es5-umd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd.types b/tests/baselines/reference/es5-umd.types new file mode 100644 index 0000000000..60987d429e --- /dev/null +++ b/tests/baselines/reference/es5-umd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-umd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd2.js b/tests/baselines/reference/es5-umd2.js new file mode 100644 index 0000000000..cb0265bf92 --- /dev/null +++ b/tests/baselines/reference/es5-umd2.js @@ -0,0 +1,42 @@ +//// [es5-umd2.ts] + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-umd2.js] +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.A = A; +}); +//# sourceMappingURL=es5-umd2.js.map + +//// [es5-umd2.d.ts] +export declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd2.js.map b/tests/baselines/reference/es5-umd2.js.map new file mode 100644 index 0000000000..13a785b2ed --- /dev/null +++ b/tests/baselines/reference/es5-umd2.js.map @@ -0,0 +1,2 @@ +//// [es5-umd2.js.map] +{"version":3,"file":"es5-umd2.js","sourceRoot":"","sources":["es5-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXY,SAAC,IAWb,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.sourcemap.txt b/tests/baselines/reference/es5-umd2.sourcemap.txt new file mode 100644 index 0000000000..bfadd9615f --- /dev/null +++ b/tests/baselines/reference/es5-umd2.sourcemap.txt @@ -0,0 +1,149 @@ +=================================================================== +JsFile: es5-umd2.js +mapUrl: es5-umd2.js.map +sourceRoot: +sources: es5-umd2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd2.js +sourceFile:es5-umd2.ts +------------------------------------------------------------------- +>>>(function (deps, factory) { +>>> if (typeof module === 'object' && typeof module.exports === 'object') { +>>> var v = factory(require, exports); if (v !== undefined) module.exports = v; +>>> } +>>> else if (typeof define === 'function' && define.amd) { +>>> define(deps, factory); +>>> } +>>>})(["require", "exports"], function (require, exports) { +>>> var A = (function () { +1 >^^^^ +2 > ^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^^^^^ +2 > ^^-> +1->export class A + >{ + > +1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^-> +1 > +2 > } +3 > +4 > export class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) +4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) +--- +>>> exports.A = A; +1->^^^^ +2 > ^^^^^^^^^ +3 > ^^^^ +4 > ^ +1-> +2 > A +3 > + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +4 > +1->Emitted(17, 5) Source(2, 14) + SourceIndex(0) +2 >Emitted(17, 14) Source(2, 15) + SourceIndex(0) +3 >Emitted(17, 18) Source(13, 2) + SourceIndex(0) +4 >Emitted(17, 19) Source(13, 2) + SourceIndex(0) +--- +>>>}); +>>>//# sourceMappingURL=es5-umd2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.symbols b/tests/baselines/reference/es5-umd2.symbols new file mode 100644 index 0000000000..3b911d7e6f --- /dev/null +++ b/tests/baselines/reference/es5-umd2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-umd2.ts === + +export class A +>A : Symbol(A, Decl(es5-umd2.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd2.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd2.types b/tests/baselines/reference/es5-umd2.types new file mode 100644 index 0000000000..fab4e9dfc0 --- /dev/null +++ b/tests/baselines/reference/es5-umd2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-umd2.ts === + +export class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js new file mode 100644 index 0000000000..2d18e2eecc --- /dev/null +++ b/tests/baselines/reference/es5-umd3.js @@ -0,0 +1,42 @@ +//// [es5-umd3.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-umd3.js] +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.default = A; +}); +//# sourceMappingURL=es5-umd3.js.map + +//// [es5-umd3.d.ts] +export default class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd3.js.map b/tests/baselines/reference/es5-umd3.js.map new file mode 100644 index 0000000000..8b955f1193 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.js.map @@ -0,0 +1,2 @@ +//// [es5-umd3.js.map] +{"version":3,"file":"es5-umd3.js","sourceRoot":"","sources":["es5-umd3.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXD,mBAWC,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.sourcemap.txt b/tests/baselines/reference/es5-umd3.sourcemap.txt new file mode 100644 index 0000000000..afb879ac71 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.sourcemap.txt @@ -0,0 +1,146 @@ +=================================================================== +JsFile: es5-umd3.js +mapUrl: es5-umd3.js.map +sourceRoot: +sources: es5-umd3.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd3.js +sourceFile:es5-umd3.ts +------------------------------------------------------------------- +>>>(function (deps, factory) { +>>> if (typeof module === 'object' && typeof module.exports === 'object') { +>>> var v = factory(require, exports); if (v !== undefined) module.exports = v; +>>> } +>>> else if (typeof define === 'function' && define.amd) { +>>> define(deps, factory); +>>> } +>>>})(["require", "exports"], function (require, exports) { +>>> var A = (function () { +1 >^^^^ +2 > ^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^^^^^ +2 > ^^-> +1->export default class A + >{ + > +1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^-> +1 > +2 > } +3 > +4 > export default class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) +4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) +--- +>>> exports.default = A; +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ +1-> +2 > export default class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +3 > +1->Emitted(17, 5) Source(2, 1) + SourceIndex(0) +2 >Emitted(17, 24) Source(13, 2) + SourceIndex(0) +3 >Emitted(17, 25) Source(13, 2) + SourceIndex(0) +--- +>>>}); +>>>//# sourceMappingURL=es5-umd3.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.symbols b/tests/baselines/reference/es5-umd3.symbols new file mode 100644 index 0000000000..3f830ae363 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-umd3.ts === + +export default class A +>A : Symbol(A, Decl(es5-umd3.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd3.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd3.types b/tests/baselines/reference/es5-umd3.types new file mode 100644 index 0000000000..b4b5f0dc36 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-umd3.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd4.js b/tests/baselines/reference/es5-umd4.js new file mode 100644 index 0000000000..85683f8f3c --- /dev/null +++ b/tests/baselines/reference/es5-umd4.js @@ -0,0 +1,45 @@ +//// [es5-umd4.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +export = A; + + +//// [es5-umd4.js] +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + return A; +}); +//# sourceMappingURL=es5-umd4.js.map + +//// [es5-umd4.d.ts] +declare class A { + constructor(); + B(): number; +} +export = A; diff --git a/tests/baselines/reference/es5-umd4.js.map b/tests/baselines/reference/es5-umd4.js.map new file mode 100644 index 0000000000..0a47d679ed --- /dev/null +++ b/tests/baselines/reference/es5-umd4.js.map @@ -0,0 +1,2 @@ +//// [es5-umd4.js.map] +{"version":3,"file":"es5-umd4.js","sourceRoot":"","sources":["es5-umd4.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAEU,AAAX,OAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.sourcemap.txt b/tests/baselines/reference/es5-umd4.sourcemap.txt new file mode 100644 index 0000000000..9afd8effec --- /dev/null +++ b/tests/baselines/reference/es5-umd4.sourcemap.txt @@ -0,0 +1,143 @@ +=================================================================== +JsFile: es5-umd4.js +mapUrl: es5-umd4.js.map +sourceRoot: +sources: es5-umd4.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd4.js +sourceFile:es5-umd4.ts +------------------------------------------------------------------- +>>>(function (deps, factory) { +>>> if (typeof module === 'object' && typeof module.exports === 'object') { +>>> var v = factory(require, exports); if (v !== undefined) module.exports = v; +>>> } +>>> else if (typeof define === 'function' && define.amd) { +>>> define(deps, factory); +>>> } +>>>})(["require", "exports"], function (require, exports) { +>>> var A = (function () { +1 >^^^^ +2 > ^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^^^^^ +2 > ^^-> +1->class A + >{ + > +1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^-> +1 > +2 > } +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) +4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) +--- +>>> return A; +1->^^^^ +2 > +3 > ^^^^^^^ +4 > ^ +5 > ^ +1-> + > + >export = A; +2 > +3 > export = +4 > A +5 > ; +1->Emitted(17, 5) Source(15, 12) + SourceIndex(0) +2 >Emitted(17, 5) Source(15, 1) + SourceIndex(0) +3 >Emitted(17, 12) Source(15, 10) + SourceIndex(0) +4 >Emitted(17, 13) Source(15, 11) + SourceIndex(0) +5 >Emitted(17, 14) Source(15, 12) + SourceIndex(0) +--- +>>>}); +>>>//# sourceMappingURL=es5-umd4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.symbols b/tests/baselines/reference/es5-umd4.symbols new file mode 100644 index 0000000000..cdf1e135cf --- /dev/null +++ b/tests/baselines/reference/es5-umd4.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/es5-umd4.ts === + +class A +>A : Symbol(A, Decl(es5-umd4.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd4.ts, 6, 5)) + { + return 42; + } +} + +export = A; +>A : Symbol(A, Decl(es5-umd4.ts, 0, 0)) + diff --git a/tests/baselines/reference/es5-umd4.types b/tests/baselines/reference/es5-umd4.types new file mode 100644 index 0000000000..59d23e6bd8 --- /dev/null +++ b/tests/baselines/reference/es5-umd4.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es5-umd4.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + +export = A; +>A : A + diff --git a/tests/baselines/reference/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt index cb1ef4b128..e1e44b4a49 100644 --- a/tests/baselines/reference/es6-amd.errors.txt +++ b/tests/baselines/reference/es6-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt index 18319504dc..30cf14f086 100644 --- a/tests/baselines/reference/es6-declaration-amd.errors.txt +++ b/tests/baselines/reference/es6-declaration-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt index 24a83f8ee1..da8968e9d5 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.errors.txt +++ b/tests/baselines/reference/es6-sourcemap-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-umd.errors.txt b/tests/baselines/reference/es6-umd.errors.txt new file mode 100644 index 0000000000..874b41552c --- /dev/null +++ b/tests/baselines/reference/es6-umd.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. + + +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' 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.js b/tests/baselines/reference/es6-umd.js new file mode 100644 index 0000000000..74cd671f5e --- /dev/null +++ b/tests/baselines/reference/es6-umd.js @@ -0,0 +1,30 @@ +//// [es6-umd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-umd.js] +class A { + constructor() { + } + B() { + return 42; + } +} +//# sourceMappingURL=es6-umd.js.map + +//// [es6-umd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-umd.js.map b/tests/baselines/reference/es6-umd.js.map new file mode 100644 index 0000000000..a5e82f7ccf --- /dev/null +++ b/tests/baselines/reference/es6-umd.js.map @@ -0,0 +1,2 @@ +//// [es6-umd.js.map] +{"version":3,"file":"es6-umd.js","sourceRoot":"","sources":["es6-umd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.sourcemap.txt b/tests/baselines/reference/es6-umd.sourcemap.txt new file mode 100644 index 0000000000..bb8281ce74 --- /dev/null +++ b/tests/baselines/reference/es6-umd.sourcemap.txt @@ -0,0 +1,91 @@ +=================================================================== +JsFile: es6-umd.js +mapUrl: es6-umd.js.map +sourceRoot: +sources: es6-umd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-umd.js +sourceFile:es6-umd.ts +------------------------------------------------------------------- +>>>class A { +1 > +2 >^^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> constructor() { +1->^^^^ +2 > ^^-> +1->class A + >{ + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> B() { +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> +1-> + > + > public +2 > B +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) +--- +>>> return 42; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1->() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>//# sourceMappingURL=es6-umd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.errors.txt b/tests/baselines/reference/es6-umd2.errors.txt new file mode 100644 index 0000000000..88d732df12 --- /dev/null +++ b/tests/baselines/reference/es6-umd2.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. + + +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' 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 new file mode 100644 index 0000000000..b12d35aacf --- /dev/null +++ b/tests/baselines/reference/es6-umd2.js @@ -0,0 +1,30 @@ +//// [es6-umd2.ts] + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-umd2.js] +export class A { + constructor() { + } + B() { + return 42; + } +} +//# sourceMappingURL=es6-umd2.js.map + +//// [es6-umd2.d.ts] +export declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-umd2.js.map b/tests/baselines/reference/es6-umd2.js.map new file mode 100644 index 0000000000..81f3d85a6c --- /dev/null +++ b/tests/baselines/reference/es6-umd2.js.map @@ -0,0 +1,2 @@ +//// [es6-umd2.js.map] +{"version":3,"file":"es6-umd2.js","sourceRoot":"","sources":["es6-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.sourcemap.txt b/tests/baselines/reference/es6-umd2.sourcemap.txt new file mode 100644 index 0000000000..d032aa3d6c --- /dev/null +++ b/tests/baselines/reference/es6-umd2.sourcemap.txt @@ -0,0 +1,91 @@ +=================================================================== +JsFile: es6-umd2.js +mapUrl: es6-umd2.js.map +sourceRoot: +sources: es6-umd2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-umd2.js +sourceFile:es6-umd2.ts +------------------------------------------------------------------- +>>>export class A { +1 > +2 >^^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> constructor() { +1->^^^^ +2 > ^^-> +1->export class A + >{ + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> B() { +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> +1-> + > + > public +2 > B +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) +--- +>>> return 42; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1->() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>//# sourceMappingURL=es6-umd2.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index 34bb303a57..5844f39ed3 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt index 635bb955c0..20b74ee394 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt +++ b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt index 5723b5c20d..b20f3808c9 100644 --- a/tests/baselines/reference/es6ImportNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt index 41d3f16093..ce4d496592 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -1,8 +1,8 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' 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 external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' 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/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt index bbe0d8b78b..e851817ee8 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== export class A { diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt index 87f53cb781..1de27c03c5 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== export class A { diff --git a/tests/baselines/reference/umdDependencyComment2.errors.txt b/tests/baselines/reference/umdDependencyComment2.errors.txt new file mode 100644 index 0000000000..66c4adf4c1 --- /dev/null +++ b/tests/baselines/reference/umdDependencyComment2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/umdDependencyComment2.ts(3,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyComment2.ts (1 errors) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); + \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyComment2.js b/tests/baselines/reference/umdDependencyComment2.js new file mode 100644 index 0000000000..cae3463151 --- /dev/null +++ b/tests/baselines/reference/umdDependencyComment2.js @@ -0,0 +1,20 @@ +//// [umdDependencyComment2.ts] +/// + +import m1 = require("m2") +m1.f(); + + +//// [umdDependencyComment2.js] +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "m2"], function (require, exports) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/baselines/reference/umdDependencyCommentName1.errors.txt b/tests/baselines/reference/umdDependencyCommentName1.errors.txt new file mode 100644 index 0000000000..6acb71c4b0 --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName1.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/umdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyCommentName1.ts (1 errors) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); + \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyCommentName1.js b/tests/baselines/reference/umdDependencyCommentName1.js new file mode 100644 index 0000000000..6cb87eb45f --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName1.js @@ -0,0 +1,20 @@ +//// [umdDependencyCommentName1.ts] +/// + +import m1 = require("m2") +m1.f(); + + +//// [umdDependencyCommentName1.js] +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "m2"], function (require, exports, b) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/baselines/reference/umdDependencyCommentName2.errors.txt b/tests/baselines/reference/umdDependencyCommentName2.errors.txt new file mode 100644 index 0000000000..3481ca6114 --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/umdDependencyCommentName2.ts(5,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyCommentName2.ts (1 errors) ==== + /// + /// + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); + \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyCommentName2.js b/tests/baselines/reference/umdDependencyCommentName2.js new file mode 100644 index 0000000000..d474454936 --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName2.js @@ -0,0 +1,24 @@ +//// [umdDependencyCommentName2.ts] +/// +/// +/// + +import m1 = require("m2") +m1.f(); + + +//// [umdDependencyCommentName2.js] +/// +/// +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "goo", "foo", "m2"], function (require, exports, b, c) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/cases/compiler/es5-umd.ts b/tests/cases/compiler/es5-umd.ts new file mode 100644 index 0000000000..d0f65f7698 --- /dev/null +++ b/tests/cases/compiler/es5-umd.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-umd2.ts b/tests/cases/compiler/es5-umd2.ts new file mode 100644 index 0000000000..a74ae21f4d --- /dev/null +++ b/tests/cases/compiler/es5-umd2.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-umd3.ts b/tests/cases/compiler/es5-umd3.ts new file mode 100644 index 0000000000..b4ab3cc1cf --- /dev/null +++ b/tests/cases/compiler/es5-umd3.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-umd4.ts b/tests/cases/compiler/es5-umd4.ts new file mode 100644 index 0000000000..5ab7e7de4e --- /dev/null +++ b/tests/cases/compiler/es5-umd4.ts @@ -0,0 +1,19 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +export = A; diff --git a/tests/cases/compiler/es6-umd.ts b/tests/cases/compiler/es6-umd.ts new file mode 100644 index 0000000000..239ff49ef6 --- /dev/null +++ b/tests/cases/compiler/es6-umd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: umd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-umd2.ts b/tests/cases/compiler/es6-umd2.ts new file mode 100644 index 0000000000..54622fe81a --- /dev/null +++ b/tests/cases/compiler/es6-umd2.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: umd + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/umdDependencyComment2.ts b/tests/cases/compiler/umdDependencyComment2.ts new file mode 100644 index 0000000000..87e4fd4852 --- /dev/null +++ b/tests/cases/compiler/umdDependencyComment2.ts @@ -0,0 +1,5 @@ +//@module: umd +/// + +import m1 = require("m2") +m1.f(); diff --git a/tests/cases/compiler/umdDependencyCommentName1.ts b/tests/cases/compiler/umdDependencyCommentName1.ts new file mode 100644 index 0000000000..90b852c9bf --- /dev/null +++ b/tests/cases/compiler/umdDependencyCommentName1.ts @@ -0,0 +1,5 @@ +//@module: umd +/// + +import m1 = require("m2") +m1.f(); diff --git a/tests/cases/compiler/umdDependencyCommentName2.ts b/tests/cases/compiler/umdDependencyCommentName2.ts new file mode 100644 index 0000000000..bbdd847b84 --- /dev/null +++ b/tests/cases/compiler/umdDependencyCommentName2.ts @@ -0,0 +1,7 @@ +//@module: umd +/// +/// +/// + +import m1 = require("m2") +m1.f();