diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 582687530fc65..0b50c18911ebe 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; - let modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; + let modulekind = (compilerOptions.module !== undefined && compilerOptions.module !== null) ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; let emitResolver = createResolver(); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index f1d4b6e31ec37..5fd8c126d3fbd 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -72,13 +72,14 @@ namespace ts { name: "module", shortName: "m", type: { + "none": ModuleKind.None, "commonjs": ModuleKind.CommonJS, "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_umd_es6_or_none_only_valid_with_bundle, paramType: Diagnostics.KIND, error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 }, @@ -246,6 +247,12 @@ namespace ts { }, description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic, + }, + { + name: "bundle", + type: "string", + isFilePath: true, + description: Diagnostics.Specifies_entrypoint_file_for_bundling } ]; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a1f6565ed1ffb..2a148d385d413 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -140,6 +140,34 @@ namespace ts { } return result; } + + export function pairwiseMap(map: Map, f: (key: string, value: T) => U): U[] { + let result: U[]; + if (map) { + result = []; + for (let k in map) { + result.push(f(k, map[k])); + } + } + return result; + } + + export function flatten(array: T[][]): T[] { + if (array) { + return [].concat(...array); + } + return; + } + + export function keys(map: Map): string[] { + let result: string[] = []; + if (map) { + for (let k in map) { + result.push(k); + } + } + return result; + } export function concatenate(array1: T[], array2: T[]): T[] { if (!array2 || !array2.length) return array1; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f9789495be1e6..93b845efaef96 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -675,6 +675,10 @@ "category": "Error", "code": 1215 }, + "Cannot use option '--module none' without using '--bundle'.": { + "category": "Error", + "code": 1216 + }, "Export assignment is not supported when '--module' flag is 'system'.": { "category": "Error", "code": 1218 @@ -2056,6 +2060,10 @@ "category": "Error", "code": 5054 }, + "Option '{0}' requires both '{1}' and '{2}'.": { + "category": "Error", + "code": 5055 + }, "Concatenate and emit output to single file.": { "category": "Message", @@ -2101,7 +2109,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'": { + "Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es6', or 'none' (only valid with --bundle)": { "category": "Message", "code": 6016 }, @@ -2294,6 +2302,10 @@ "category": "Message", "code": 6072 }, + "Specifies entrypoint file for bundling.": { + "category": "Message", + "code": 6073 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6a6b75af65f37..1e5809a848c81 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -62,9 +62,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi }); };`; + const umdHelper = `(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); + } +})(`; + let compilerOptions = host.getCompilerOptions(); let languageVersion = compilerOptions.target || ScriptTarget.ES3; - let modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; + let modulekind = (compilerOptions.module !== undefined && compilerOptions.module !== null) ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; let diagnostics: Diagnostic[] = []; let newLine = host.getNewLine(); @@ -72,12 +81,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let shouldEmitJsx = (s: SourceFile) => (s.languageVariant === LanguageVariant.JSX && !jsxDesugaring); if (targetSourceFile === undefined) { - forEach(host.getSourceFiles(), sourceFile => { - if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { - let jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, sourceFile); + if (!compilerOptions.bundle) { + for (var sourceFile of host.getSourceFiles()) { + if (shouldEmitToOwnFile(sourceFile, compilerOptions)) { + let jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, sourceFile); + } } - }); + } if (compilerOptions.outFile || compilerOptions.out) { emitFile(compilerOptions.outFile || compilerOptions.out); @@ -167,6 +178,120 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** Called once the emit of the node is done */ let emitEnd = function (node: Node) { }; + + let bundleDependenciesMap: {[key: string]: string}; + + /** Called to build the opening part of a bundled module wrapper */ + let emitBundleWrapperStart: Map<() => void> = { + [ModuleKind.None]() {}, + [ModuleKind.CommonJS]() { + write("module.exports = "); + }, + [ModuleKind.AMD]() { + write("define([\"require\""); + forEachKey(bundleDependenciesMap, name => write(`, "${name}"`)); + write("], function(require"); + forEachValue(bundleDependenciesMap, name => write(`, ${name}`)); + write("){"); + writeLine(); + increaseIndent(); + write("return "); + }, + [ModuleKind.UMD]() { + writeLines(umdHelper); + write("[\"require\""); + forEachKey(bundleDependenciesMap, name => write(`, "${name}"`)); + write("], function(require"); + forEachValue(bundleDependenciesMap, name => write(`, ${name}`)); + write("){"); + writeLine(); + increaseIndent(); + write("return "); + }, + [ModuleKind.System]() { + exportFunctionForFile = makeUniqueName("exports"); + let deps: string[] = []; + forEachKey(bundleDependenciesMap, name => {deps.push(`"${name}"`);}); + writeLine(); + write(`System.register([${deps.join(", ")}], function(${exportFunctionForFile}) {`); + writeLine(); + increaseIndent(); + let idents: string[] = []; + forEachValue(bundleDependenciesMap, name => {idents.push(name);}); + forEach(idents, id => { + write(`var ${id};`); + writeLine(); + }); + let exportStarName = emitExportStarFunction(/*localNames*/undefined); + exportFunctionForFile = undefined; + currentSourceFile = undefined; + writeLine(); + write("return {") + writeLine(); + increaseIndent(); + let setters = map(idents, id => `function(m) { + ${id} = m; +}`); + writeLines("setters: ["+setters.join(","+newLine)); + write("],"); + writeLine(); + write("execute: function() {"); + writeLine(); + increaseIndent(); + write(`${exportStarName}(`); + }, + [ModuleKind.ES6]() { + write(`var __exports = `); + }, + } + + /** Called to build the closing part of a bundled module wrapper */ + let emitBundleWrapperEnd: Map<() => void> = { + [ModuleKind.None]() {}, + [ModuleKind.CommonJS]() { + write(";"); + }, + [ModuleKind.AMD]() { + write(";"); + decreaseIndent(); + writeLine(); + write("});"); + }, + [ModuleKind.UMD]() { + write(";"); + decreaseIndent(); + writeLine(); + write("});"); + }, + [ModuleKind.System]() { + write(");"); + writeLine(); + decreaseIndent(); + write("}"); + writeLine(); + decreaseIndent(); + write("};"); + decreaseIndent(); + writeLine(); + write("});"); + }, + [ModuleKind.ES6]() { + let module = host.resolveModuleName(compilerOptions.bundle); + if (!module) { + throw new Error('Bundle entrypoint not resolvable'); + } + let file = forEach(host.getSourceFiles(), file => file.fileName === module.resolvedFileName ? file : undefined); + forEachValue(file.symbol.exports, symbol => { + writeLine(); + if (symbol.name === "default") { + write("export default __exports[\"default\"];"); + } + else { + write(`export var ${symbol.name} = __exports.${symbol.name};`); + } + }); + }, + } /** Emit the text for the given token that comes after startPos * This by default writes the text provided with the given tokenKind @@ -207,11 +332,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitSourceFile(root); } else { + let originalKind = modulekind; + if (compilerOptions.bundle) { + buildBundleDependenciesMap(); + modulekind = ModuleKind.CommonJS; + emitBundleWrapperStart[originalKind](); + write("(function() {"); + increaseIndent(); + writeDefineHelper(); + forEach(host.getSourceFiles(), emitEmitHelpers); + writeLine(); + } + forEach(host.getSourceFiles(), sourceFile => { if (!isExternalModuleOrDeclarationFile(sourceFile)) { emitSourceFile(sourceFile); } + else if (compilerOptions.bundle && isExternalModule(sourceFile)) { + emitBundledFile(sourceFile); + } }); + + if (compilerOptions.bundle) { + writeLines(`return __define.require("${removeFileExtension(compilerOptions.bundle)}");`); + decreaseIndent(); + writeLines("})()"); + emitBundleWrapperEnd[originalKind](); + modulekind = originalKind; + } } writeLine(); @@ -223,6 +371,109 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi exportFunctionForFile = undefined; emit(sourceFile); } + + function emitBundledFile(sourceFile: SourceFile): void { + let dir = host.getCurrentDirectory(); + let canonicalName = removeFileExtension( + getRelativePathToDirectoryOrUrl(dir, sourceFile.fileName, dir, f => host.getCanonicalFileName(f), /*isAbsolutePathAnUrl*/false) + ); + writeLine(); + write(`__define("/${canonicalName}", function(require, exports, module){`); + writeLine(); + increaseIndent(); + emitBundledSourceFileNode(sourceFile); + decreaseIndent(); + writeLine(); + write("});"); + } + + function buildBundleDependenciesMap(): void { + let identifiers = deduplicate(flatten(map(host.getSourceFiles(), file => keys(file.identifiers)))); + let identifiersMap: Map = {}; + forEach(identifiers, name => identifiersMap[name] = escapeIdentifier(name)); + currentSourceFile = {identifiers: identifiersMap}; // Enables bundlewide makeUniqueName + let deps = deduplicate(filter(flatten(map(host.getSourceFiles(), file => pairwiseMap(file.resolvedModules, (importName, resolvedModule) => (!resolvedModule || resolvedModule.isExternalLibraryImport) ? importName : undefined))), name => !!name)); + let depsIdentifiers = map(deps, name => makeUniqueName(escapeIdentifier(makeIdentifierFromModuleName(name)))); + bundleDependenciesMap = {}; + forEach(deps, (name, index) => { + bundleDependenciesMap[name] = depsIdentifiers[index]; + }); + } + + function writeDefineHelper(): void { + writeLines(` +var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named \""+name+"\"."); }, + normalizeSlashes = function(path) { return path.replace("\\\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) {`); + forEachKey(bundleDependenciesMap, name => { + writeLines(` if (name === "${name}") return ${bundleDependenciesMap[name]};`); + }); + writeLines(` var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; +})();`); + } function isUniqueName(name: string): boolean { return !resolver.hasGlobalName(name) && @@ -3500,6 +3751,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function isES6ExportedDeclaration(node: Node) { return !!(node.flags & NodeFlags.Export) && + languageVersion >= ScriptTarget.ES6 && modulekind === ModuleKind.ES6 && node.parent.kind === SyntaxKind.SourceFile; } @@ -4600,7 +4852,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitEnd(node); write(";"); } - else if (isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { + else if (isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Default) && thisNodeIsDecorated && modulekind === ModuleKind.ES6) { // if this is a top level default export of decorated class, write the export after the declaration. writeLine(); write("export default "); @@ -5934,37 +6186,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return emitExportStarFunction(exportedNamesStorageRef); - function emitExportStarFunction(localNames: string): string { - const exportStarFunction = makeUniqueName("exportStar"); - - writeLine(); - - // define an export star helper function - write(`function ${exportStarFunction}(m) {`); - increaseIndent(); - writeLine(); - write(`var exports = {};`); - writeLine(); - write(`for(var n in m) {`); - increaseIndent(); - writeLine(); - write(`if (n !== "default"`); - if (localNames) { - write(`&& !${localNames}.hasOwnProperty(n)`); - } - write(`) exports[n] = m[n];`); - decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - write(`${exportFunctionForFile}(exports);`); - decreaseIndent(); - writeLine(); - write("}"); - - return exportStarFunction; - } - function writeExportedName(node: Identifier | Declaration): void { // do not record default exports // they are local to module and never overwritten (explicitly skipped) by star export @@ -6349,6 +6570,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("}"); // execute } + function emitExportStarFunction(localNames: string): string { + const exportStarFunction = makeUniqueName("exportStar"); + + writeLine(); + + // define an export star helper function + write(`function ${exportStarFunction}(m) {`); + increaseIndent(); + writeLine(); + write(`var exports = {};`); + writeLine(); + write(`for (var n in m) {`); + increaseIndent(); + writeLine(); + write(`if (n !== "default"`); + if (localNames) { + write(`&& !${localNames}.hasOwnProperty(n)`); + } + write(`) exports[n] = m[n];`); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write(`${exportFunctionForFile}(exports);`); + decreaseIndent(); + writeLine(); + write("}"); + + return exportStarFunction; + } + type DependencyGroup = Array; function emitSystemModule(node: SourceFile, startIndex: number): void { @@ -6504,14 +6756,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi 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); - } -})(`); + writeLines(umdHelper); emitAMDDependencies(node, false); write(") {"); increaseIndent(); @@ -6738,6 +6983,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitLeadingComments(node.endOfFileToken); } + + function emitBundledSourceFileNode(node: SourceFile) { + currentSourceFile = node; + exportFunctionForFile = undefined; + writeLine(); + emitShebang(); + emitDetachedComments(node); + + // emit prologue directives prior to __extends + let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + emitCommonJSModule(node, startIndex); + emitLeadingComments(node.endOfFileToken); + } function emitNodeWithCommentsAndWithoutSourcemap(node: Node): void { emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0dbaa3b39b251..e67eb5c2720e3 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -521,6 +521,7 @@ namespace ts { getNewLine: () => host.getNewLine(), getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, + resolveModuleName: (moduleName: string) => resolveModuleNamesWorker([moduleName], ts.combinePaths(host.getCurrentDirectory(), 'dummy.ts'))[0], writeFile: writeFileCallback || ( (fileName, data, writeByteOrderMark, onError) => host.writeFile(fileName, data, writeByteOrderMark, onError)), }; @@ -862,8 +863,8 @@ namespace ts { const importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); if (importedFile && resolution.isExternalLibraryImport) { if (!isExternalModule(importedFile)) { - let start = getTokenPosOfNode(file.imports[i], file) - fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); + let start = getTokenPosOfNode(file.imports[i], file) + fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); } else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { let start = getTokenPosOfNode(file.imports[i], file) @@ -947,6 +948,10 @@ namespace ts { return allFilesBelongToPath; } + + function moduleFormatProvided(): boolean { + return options.module !== undefined && options.module !== null; + } function verifyCompilerOptions() { if (options.isolatedModules) { @@ -1003,10 +1008,11 @@ namespace ts { let languageVersion = options.target || ScriptTarget.ES3; let outFile = options.outFile || options.out; + let moduleProvided = moduleFormatProvided(); let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (options.isolatedModules) { - if (!options.module && languageVersion < ScriptTarget.ES6) { + if (!moduleProvided && languageVersion < ScriptTarget.ES6) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } @@ -1016,12 +1022,20 @@ namespace ts { programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } - else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) { + else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !moduleProvided) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } + if (options.bundle && !(moduleProvided && outFile) ) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_requires_both_1_and_2, "bundle", "outFile", "module")); + } + + if (options.module === ModuleKind.None && !options.bundle) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_use_option_module_none_without_using_bundle)); + } + // 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)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2cb429a993e80..b586e68086b01 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2061,7 +2061,8 @@ namespace ts { experimentalDecorators?: boolean; experimentalAsyncFunctions?: boolean; emitDecoratorMetadata?: boolean; - moduleResolution?: ModuleResolutionKind + moduleResolution?: ModuleResolutionKind, + bundle?: string; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3397cd242b1d6..2e7626e9aedd7 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -34,7 +34,7 @@ namespace ts { export interface EmitHost extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; - + resolveModuleName(moduleName: string): ResolvedModule; getCommonSourceDirectory(): string; getCanonicalFileName(fileName: string): string; getNewLine(): string; diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index a24ed30ae143a..0a108a43872fe 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -94,7 +94,7 @@ class CompilerBaselineRunner extends RunnerBase { program = _program; }, function (settings) { harnessCompiler.setCompilerSettings(tcSettings); - }); + }, undefined, rootDir); }); after(() => { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 57eb848ac23ae..96b288244f9cb 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -918,7 +918,10 @@ module Harness { function getSourceFile(fn: string, languageVersion: ts.ScriptTarget) { fn = ts.normalizePath(fn); - if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) { + if (fn === defaultLibFileName) { + return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile; + } + else if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) { return filemap[getCanonicalFileName(fn)]; } else if (currentDirectory) { @@ -931,9 +934,6 @@ module Harness { return fourslashSourceFile; } else { - if (fn === defaultLibFileName) { - return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile; - } // Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC return undefined; } @@ -1079,7 +1079,6 @@ module Harness { options = options || { noResolve: false }; options.target = options.target || ts.ScriptTarget.ES3; - options.module = options.module || ts.ModuleKind.None; options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed; options.noErrorTruncation = true; options.skipDefaultLibCheck = true; diff --git a/tests/baselines/reference/bundleAMD.js b/tests/baselines/reference/bundleAMD.js new file mode 100644 index 0000000000000..4e597a2a99f64 --- /dev/null +++ b/tests/baselines/reference/bundleAMD.js @@ -0,0 +1,107 @@ +//// [tests/cases/compiler/bundleAMD.ts] //// + +//// [bundleAMD_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleAMD_file1.ts] +import {Foo, assert} from "./bundleAMD_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleAMD_bundle.js] +define(["require"], function(require){ + return (function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleAMD_file0", function(require, exports, module){ + class Foo { + } + Foo.CONSTANT = "Foo"; + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleAMD_file1", function(require, exports, module){ + var bundleAMD_file0_1 = require("./bundleAMD_file0"); + bundleAMD_file0_1.assert(bundleAMD_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleAMD_file1"); + })(); +}); diff --git a/tests/baselines/reference/bundleAMD.symbols b/tests/baselines/reference/bundleAMD.symbols new file mode 100644 index 0000000000000..c40d71a284896 --- /dev/null +++ b/tests/baselines/reference/bundleAMD.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleAMD_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleAMD_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleAMD_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleAMD_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleAMD_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleAMD_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleAMD_file1.ts === +import {Foo, assert} from "./bundleAMD_file0"; +>Foo : Symbol(Foo, Decl(bundleAMD_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleAMD_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleAMD_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleAMD_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleAMD_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleAMD_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleAMD.types b/tests/baselines/reference/bundleAMD.types new file mode 100644 index 0000000000000..6360bacb1cb88 --- /dev/null +++ b/tests/baselines/reference/bundleAMD.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleAMD_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleAMD_file1.ts === +import {Foo, assert} from "./bundleAMD_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleCommonjs.js b/tests/baselines/reference/bundleCommonjs.js new file mode 100644 index 0000000000000..a1e58a916e9f6 --- /dev/null +++ b/tests/baselines/reference/bundleCommonjs.js @@ -0,0 +1,105 @@ +//// [tests/cases/compiler/bundleCommonjs.ts] //// + +//// [bundleCommonjs_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleCommonjs_file1.ts] +import {Foo, assert} from "./bundleCommonjs_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleCommonjs_bundle.js] +module.exports = (function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleCommonjs_file0", function(require, exports, module){ + class Foo { + } + Foo.CONSTANT = "Foo"; + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleCommonjs_file1", function(require, exports, module){ + var bundleCommonjs_file0_1 = require("./bundleCommonjs_file0"); + bundleCommonjs_file0_1.assert(bundleCommonjs_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleCommonjs_file1"); +})(); diff --git a/tests/baselines/reference/bundleCommonjs.symbols b/tests/baselines/reference/bundleCommonjs.symbols new file mode 100644 index 0000000000000..96c115914ac3e --- /dev/null +++ b/tests/baselines/reference/bundleCommonjs.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleCommonjs_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleCommonjs_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleCommonjs_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleCommonjs_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleCommonjs_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleCommonjs_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleCommonjs_file1.ts === +import {Foo, assert} from "./bundleCommonjs_file0"; +>Foo : Symbol(Foo, Decl(bundleCommonjs_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleCommonjs_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleCommonjs_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleCommonjs_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleCommonjs_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleCommonjs_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleCommonjs.types b/tests/baselines/reference/bundleCommonjs.types new file mode 100644 index 0000000000000..f02ce64827520 --- /dev/null +++ b/tests/baselines/reference/bundleCommonjs.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleCommonjs_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleCommonjs_file1.ts === +import {Foo, assert} from "./bundleCommonjs_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleES6.js b/tests/baselines/reference/bundleES6.js new file mode 100644 index 0000000000000..6dd8d95779e52 --- /dev/null +++ b/tests/baselines/reference/bundleES6.js @@ -0,0 +1,105 @@ +//// [tests/cases/compiler/bundleES6.ts] //// + +//// [bundleES6_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleES6_file1.ts] +import {Foo, assert} from "./bundleES6_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleES6_bundle.js] +(function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleES6_file0", function(require, exports, module){ + class Foo { + } + Foo.CONSTANT = "Foo"; + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleES6_file1", function(require, exports, module){ + var bundleES6_file0_1 = require("./bundleES6_file0"); + bundleES6_file0_1.assert(bundleES6_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleES6_file1"); +})() diff --git a/tests/baselines/reference/bundleES6.symbols b/tests/baselines/reference/bundleES6.symbols new file mode 100644 index 0000000000000..92d0eba40b2f9 --- /dev/null +++ b/tests/baselines/reference/bundleES6.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleES6_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleES6_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleES6_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleES6_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleES6_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleES6_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleES6_file1.ts === +import {Foo, assert} from "./bundleES6_file0"; +>Foo : Symbol(Foo, Decl(bundleES6_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleES6_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleES6_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleES6_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleES6_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleES6_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleES6.types b/tests/baselines/reference/bundleES6.types new file mode 100644 index 0000000000000..b6b8d909a5ae2 --- /dev/null +++ b/tests/baselines/reference/bundleES6.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleES6_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleES6_file1.ts === +import {Foo, assert} from "./bundleES6_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleSFX.js b/tests/baselines/reference/bundleSFX.js new file mode 100644 index 0000000000000..52f7ef1be2c21 --- /dev/null +++ b/tests/baselines/reference/bundleSFX.js @@ -0,0 +1,105 @@ +//// [tests/cases/compiler/bundleSFX.ts] //// + +//// [bundleSFX_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleSFX_file1.ts] +import {Foo, assert} from "./bundleSFX_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleSFX_bundle.js] +(function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleSFX_file0", function(require, exports, module){ + class Foo { + } + Foo.CONSTANT = "Foo"; + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleSFX_file1", function(require, exports, module){ + var bundleSFX_file0_1 = require("./bundleSFX_file0"); + bundleSFX_file0_1.assert(bundleSFX_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleSFX_file1"); +})() diff --git a/tests/baselines/reference/bundleSFX.symbols b/tests/baselines/reference/bundleSFX.symbols new file mode 100644 index 0000000000000..f47acb343b9ab --- /dev/null +++ b/tests/baselines/reference/bundleSFX.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleSFX_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleSFX_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleSFX_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleSFX_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleSFX_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleSFX_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleSFX_file1.ts === +import {Foo, assert} from "./bundleSFX_file0"; +>Foo : Symbol(Foo, Decl(bundleSFX_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleSFX_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleSFX_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleSFX_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleSFX_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleSFX_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleSFX.types b/tests/baselines/reference/bundleSFX.types new file mode 100644 index 0000000000000..784e557751f9d --- /dev/null +++ b/tests/baselines/reference/bundleSFX.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleSFX_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleSFX_file1.ts === +import {Foo, assert} from "./bundleSFX_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleSystem.js b/tests/baselines/reference/bundleSystem.js new file mode 100644 index 0000000000000..06d4b8149271d --- /dev/null +++ b/tests/baselines/reference/bundleSystem.js @@ -0,0 +1,119 @@ +//// [tests/cases/compiler/bundleSystem.ts] //// + +//// [bundleSystem_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleSystem_file1.ts] +import {Foo, assert} from "./bundleSystem_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleSystem_bundle.js] +System.register([], function(exports_1) { + function exportStar_1(m) { + var exports = {}; + for (var n in m) { + if (n !== "default") exports[n] = m[n]; + } + exports_1(exports); + } + return { + setters: [], + execute: function() { + exportStar_1((function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleSystem_file0", function(require, exports, module){ + class Foo { + } + Foo.CONSTANT = "Foo"; + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleSystem_file1", function(require, exports, module){ + var bundleSystem_file0_1 = require("./bundleSystem_file0"); + bundleSystem_file0_1.assert(bundleSystem_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleSystem_file1"); + })()); + } + }; +}); diff --git a/tests/baselines/reference/bundleSystem.symbols b/tests/baselines/reference/bundleSystem.symbols new file mode 100644 index 0000000000000..4ffec0e8dc6fd --- /dev/null +++ b/tests/baselines/reference/bundleSystem.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleSystem_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleSystem_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleSystem_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleSystem_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleSystem_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleSystem_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleSystem_file1.ts === +import {Foo, assert} from "./bundleSystem_file0"; +>Foo : Symbol(Foo, Decl(bundleSystem_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleSystem_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleSystem_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleSystem_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleSystem_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleSystem_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleSystem.types b/tests/baselines/reference/bundleSystem.types new file mode 100644 index 0000000000000..13831fbd7b5c1 --- /dev/null +++ b/tests/baselines/reference/bundleSystem.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleSystem_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleSystem_file1.ts === +import {Foo, assert} from "./bundleSystem_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleToES3AMD.js b/tests/baselines/reference/bundleToES3AMD.js new file mode 100644 index 0000000000000..d27dd7d0f47ba --- /dev/null +++ b/tests/baselines/reference/bundleToES3AMD.js @@ -0,0 +1,110 @@ +//// [tests/cases/compiler/bundleToES3AMD.ts] //// + +//// [bundleToES3AMD_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleToES3AMD_file1.ts] +import {Foo, assert} from "./bundleToES3AMD_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleToES3AMD_bundle.js] +define(["require"], function(require){ + return (function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleToES3AMD_file0", function(require, exports, module){ + var Foo = (function () { + function Foo() { + } + Foo.CONSTANT = "Foo"; + return Foo; + })(); + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleToES3AMD_file1", function(require, exports, module){ + var bundleToES3AMD_file0_1 = require("./bundleToES3AMD_file0"); + bundleToES3AMD_file0_1.assert(bundleToES3AMD_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleToES3AMD_file1"); + })(); +}); diff --git a/tests/baselines/reference/bundleToES3AMD.symbols b/tests/baselines/reference/bundleToES3AMD.symbols new file mode 100644 index 0000000000000..6539aca7395bc --- /dev/null +++ b/tests/baselines/reference/bundleToES3AMD.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleToES3AMD_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleToES3AMD_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3AMD_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleToES3AMD_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleToES3AMD_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleToES3AMD_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleToES3AMD_file1.ts === +import {Foo, assert} from "./bundleToES3AMD_file0"; +>Foo : Symbol(Foo, Decl(bundleToES3AMD_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleToES3AMD_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleToES3AMD_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3AMD_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleToES3AMD_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3AMD_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleToES3AMD.types b/tests/baselines/reference/bundleToES3AMD.types new file mode 100644 index 0000000000000..88a70c50516e8 --- /dev/null +++ b/tests/baselines/reference/bundleToES3AMD.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleToES3AMD_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleToES3AMD_file1.ts === +import {Foo, assert} from "./bundleToES3AMD_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleToES3Commonjs.js b/tests/baselines/reference/bundleToES3Commonjs.js new file mode 100644 index 0000000000000..3d0967cf111a0 --- /dev/null +++ b/tests/baselines/reference/bundleToES3Commonjs.js @@ -0,0 +1,110 @@ +//// [tests/cases/compiler/bundleToES3Commonjs.ts] //// + +//// [bundleToES3Commonjs_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleToES3Commonjs_file1.ts] +import {Foo, assert} from "./bundleToES3Commonjs_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleToES3Commonjs_bundle.js] +define(["require"], function(require){ + return (function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleToES3Commonjs_file0", function(require, exports, module){ + var Foo = (function () { + function Foo() { + } + Foo.CONSTANT = "Foo"; + return Foo; + })(); + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleToES3Commonjs_file1", function(require, exports, module){ + var bundleToES3Commonjs_file0_1 = require("./bundleToES3Commonjs_file0"); + bundleToES3Commonjs_file0_1.assert(bundleToES3Commonjs_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleToES3Commonjs_file1"); + })(); +}); diff --git a/tests/baselines/reference/bundleToES3Commonjs.symbols b/tests/baselines/reference/bundleToES3Commonjs.symbols new file mode 100644 index 0000000000000..8fce13268c59e --- /dev/null +++ b/tests/baselines/reference/bundleToES3Commonjs.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleToES3Commonjs_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleToES3Commonjs_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3Commonjs_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleToES3Commonjs_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleToES3Commonjs_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleToES3Commonjs_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleToES3Commonjs_file1.ts === +import {Foo, assert} from "./bundleToES3Commonjs_file0"; +>Foo : Symbol(Foo, Decl(bundleToES3Commonjs_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleToES3Commonjs_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleToES3Commonjs_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3Commonjs_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleToES3Commonjs_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3Commonjs_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleToES3Commonjs.types b/tests/baselines/reference/bundleToES3Commonjs.types new file mode 100644 index 0000000000000..9371d1e7095d5 --- /dev/null +++ b/tests/baselines/reference/bundleToES3Commonjs.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleToES3Commonjs_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleToES3Commonjs_file1.ts === +import {Foo, assert} from "./bundleToES3Commonjs_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleToES3SFX.js b/tests/baselines/reference/bundleToES3SFX.js new file mode 100644 index 0000000000000..5d148aa480529 --- /dev/null +++ b/tests/baselines/reference/bundleToES3SFX.js @@ -0,0 +1,108 @@ +//// [tests/cases/compiler/bundleToES3SFX.ts] //// + +//// [bundleToES3SFX_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleToES3SFX_file1.ts] +import {Foo, assert} from "./bundleToES3SFX_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleToES3SFX_bundle.js] +(function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleToES3SFX_file0", function(require, exports, module){ + var Foo = (function () { + function Foo() { + } + Foo.CONSTANT = "Foo"; + return Foo; + })(); + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleToES3SFX_file1", function(require, exports, module){ + var bundleToES3SFX_file0_1 = require("./bundleToES3SFX_file0"); + bundleToES3SFX_file0_1.assert(bundleToES3SFX_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleToES3SFX_file1"); +})() diff --git a/tests/baselines/reference/bundleToES3SFX.symbols b/tests/baselines/reference/bundleToES3SFX.symbols new file mode 100644 index 0000000000000..51fc49953e96f --- /dev/null +++ b/tests/baselines/reference/bundleToES3SFX.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleToES3SFX_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleToES3SFX_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3SFX_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleToES3SFX_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleToES3SFX_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleToES3SFX_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleToES3SFX_file1.ts === +import {Foo, assert} from "./bundleToES3SFX_file0"; +>Foo : Symbol(Foo, Decl(bundleToES3SFX_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleToES3SFX_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleToES3SFX_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3SFX_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleToES3SFX_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3SFX_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleToES3SFX.types b/tests/baselines/reference/bundleToES3SFX.types new file mode 100644 index 0000000000000..65c191c998895 --- /dev/null +++ b/tests/baselines/reference/bundleToES3SFX.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleToES3SFX_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleToES3SFX_file1.ts === +import {Foo, assert} from "./bundleToES3SFX_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleToES3System.js b/tests/baselines/reference/bundleToES3System.js new file mode 100644 index 0000000000000..f52ff588eb8d4 --- /dev/null +++ b/tests/baselines/reference/bundleToES3System.js @@ -0,0 +1,122 @@ +//// [tests/cases/compiler/bundleToES3System.ts] //// + +//// [bundleToES3System_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleToES3System_file1.ts] +import {Foo, assert} from "./bundleToES3System_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleToES3System_bundle.js] +System.register([], function(exports_1) { + function exportStar_1(m) { + var exports = {}; + for (var n in m) { + if (n !== "default") exports[n] = m[n]; + } + exports_1(exports); + } + return { + setters: [], + execute: function() { + exportStar_1((function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleToES3System_file0", function(require, exports, module){ + var Foo = (function () { + function Foo() { + } + Foo.CONSTANT = "Foo"; + return Foo; + })(); + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleToES3System_file1", function(require, exports, module){ + var bundleToES3System_file0_1 = require("./bundleToES3System_file0"); + bundleToES3System_file0_1.assert(bundleToES3System_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleToES3System_file1"); + })()); + } + }; +}); diff --git a/tests/baselines/reference/bundleToES3System.symbols b/tests/baselines/reference/bundleToES3System.symbols new file mode 100644 index 0000000000000..7efb2520d0cd3 --- /dev/null +++ b/tests/baselines/reference/bundleToES3System.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleToES3System_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleToES3System_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3System_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleToES3System_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleToES3System_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleToES3System_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleToES3System_file1.ts === +import {Foo, assert} from "./bundleToES3System_file0"; +>Foo : Symbol(Foo, Decl(bundleToES3System_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleToES3System_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleToES3System_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3System_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleToES3System_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3System_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleToES3System.types b/tests/baselines/reference/bundleToES3System.types new file mode 100644 index 0000000000000..40f580772263e --- /dev/null +++ b/tests/baselines/reference/bundleToES3System.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleToES3System_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleToES3System_file1.ts === +import {Foo, assert} from "./bundleToES3System_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleToES3UMD.js b/tests/baselines/reference/bundleToES3UMD.js new file mode 100644 index 0000000000000..a98655ac03771 --- /dev/null +++ b/tests/baselines/reference/bundleToES3UMD.js @@ -0,0 +1,117 @@ +//// [tests/cases/compiler/bundleToES3UMD.ts] //// + +//// [bundleToES3UMD_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleToES3UMD_file1.ts] +import {Foo, assert} from "./bundleToES3UMD_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleToES3UMD_bundle.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"], function(require){ + return (function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleToES3UMD_file0", function(require, exports, module){ + var Foo = (function () { + function Foo() { + } + Foo.CONSTANT = "Foo"; + return Foo; + })(); + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleToES3UMD_file1", function(require, exports, module){ + var bundleToES3UMD_file0_1 = require("./bundleToES3UMD_file0"); + bundleToES3UMD_file0_1.assert(bundleToES3UMD_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleToES3UMD_file1"); + })(); +}); diff --git a/tests/baselines/reference/bundleToES3UMD.symbols b/tests/baselines/reference/bundleToES3UMD.symbols new file mode 100644 index 0000000000000..767eb320262f7 --- /dev/null +++ b/tests/baselines/reference/bundleToES3UMD.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleToES3UMD_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleToES3UMD_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3UMD_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleToES3UMD_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleToES3UMD_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleToES3UMD_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleToES3UMD_file1.ts === +import {Foo, assert} from "./bundleToES3UMD_file0"; +>Foo : Symbol(Foo, Decl(bundleToES3UMD_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleToES3UMD_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleToES3UMD_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3UMD_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleToES3UMD_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleToES3UMD_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleToES3UMD.types b/tests/baselines/reference/bundleToES3UMD.types new file mode 100644 index 0000000000000..a8ca6a9dece87 --- /dev/null +++ b/tests/baselines/reference/bundleToES3UMD.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleToES3UMD_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleToES3UMD_file1.ts === +import {Foo, assert} from "./bundleToES3UMD_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/bundleUMD.js b/tests/baselines/reference/bundleUMD.js new file mode 100644 index 0000000000000..d5e6710e8f91a --- /dev/null +++ b/tests/baselines/reference/bundleUMD.js @@ -0,0 +1,114 @@ +//// [tests/cases/compiler/bundleUMD.ts] //// + +//// [bundleUMD_file0.ts] + +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +//// [bundleUMD_file1.ts] +import {Foo, assert} from "./bundleUMD_file0"; +assert(Foo.CONSTANT === "Foo"); + + +//// [bundleUMD_bundle.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"], function(require){ + return (function() { + var __define = (this && this.__define) || (function() { + var cache = {}, + id = 0, + idMap = {}, + builtinRequire = typeof require === "function" ? require : function(name) { throw new Error("Could not find module named ""+name+""."); }, + normalizeSlashes = function(path) { return path.replace("\\", "/"); }, + forEach = function(array, callback) { + for (var i = 0, len = array.length; i < len; i++) { + callback(array[i], i); + } + }, + resolvePath = function(base, name) { + var result = normalizeSlashes(base).split("/"); + result.pop(); + forEach(normalizeSlashes(name).split("/"), function(part, index) { + switch(part) { + case "": + case ".": + break; + case "..": + if (result.length <= 1) { + if (result[0] === "..") { + result.push(".."); + break; + } + else if (result[0] === "." || result[0] === "") { + result[0] = ".."; + break; + } + } + result.pop(); + break; + default: + result.push(part); + break; + } + }); + if (result[0] === "") result.shift(); + return "/"+result.join("/"); + }, + initializeAndGet = function(resolved) { + if (typeof cache[resolved] === "function") { + cache[resolved](); + } + return (cache[resolved] && cache[resolved].exports); + }, + resolveRequire = function(name, from) { + var resolved = resolvePath(from || "/", name); + return (initializeAndGet(resolved) || builtinRequire(name)); + }, + define = function (declaredName, factory) { + idMap[++id] = declaredName; + var module = { + id: id, + exports: {} + }; + var require = function(name) { + if (typeof name === "number") return initializeAndGet(idMap[name]); + return resolveRequire(name, declaredName); + }; + cache[declaredName] = function() { + cache[declaredName] = module; + factory(require, module.exports, module); + }; + }; + define.require = resolveRequire; + return define; + })(); + __define("/tests/cases/compiler/bundleUMD_file0", function(require, exports, module){ + class Foo { + } + Foo.CONSTANT = "Foo"; + exports.Foo = Foo; + function assert(value) { + if (!value) + throw new Error("Assertion failed!"); + } + exports.assert = assert; + }); + __define("/tests/cases/compiler/bundleUMD_file1", function(require, exports, module){ + var bundleUMD_file0_1 = require("./bundleUMD_file0"); + bundleUMD_file0_1.assert(bundleUMD_file0_1.Foo.CONSTANT === "Foo"); + }); + return __define.require("bundleUMD_file1"); + })(); +}); diff --git a/tests/baselines/reference/bundleUMD.symbols b/tests/baselines/reference/bundleUMD.symbols new file mode 100644 index 0000000000000..7e8acfc1ae6e6 --- /dev/null +++ b/tests/baselines/reference/bundleUMD.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/bundleUMD_file0.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(bundleUMD_file0.ts, 0, 0)) + + static CONSTANT = "Foo"; +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleUMD_file0.ts, 1, 18)) +} + +export function assert(value: boolean) { +>assert : Symbol(assert, Decl(bundleUMD_file0.ts, 3, 1)) +>value : Symbol(value, Decl(bundleUMD_file0.ts, 5, 23)) + + if (!value) throw new Error("Assertion failed!"); +>value : Symbol(value, Decl(bundleUMD_file0.ts, 5, 23)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) +} + + +=== tests/cases/compiler/bundleUMD_file1.ts === +import {Foo, assert} from "./bundleUMD_file0"; +>Foo : Symbol(Foo, Decl(bundleUMD_file1.ts, 0, 8)) +>assert : Symbol(assert, Decl(bundleUMD_file1.ts, 0, 12)) + +assert(Foo.CONSTANT === "Foo"); +>assert : Symbol(assert, Decl(bundleUMD_file1.ts, 0, 12)) +>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleUMD_file0.ts, 1, 18)) +>Foo : Symbol(Foo, Decl(bundleUMD_file1.ts, 0, 8)) +>CONSTANT : Symbol(Foo.CONSTANT, Decl(bundleUMD_file0.ts, 1, 18)) + diff --git a/tests/baselines/reference/bundleUMD.types b/tests/baselines/reference/bundleUMD.types new file mode 100644 index 0000000000000..b2a1639f3c0cd --- /dev/null +++ b/tests/baselines/reference/bundleUMD.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bundleUMD_file0.ts === + +export class Foo { +>Foo : Foo + + static CONSTANT = "Foo"; +>CONSTANT : string +>"Foo" : string +} + +export function assert(value: boolean) { +>assert : (value: boolean) => void +>value : boolean + + if (!value) throw new Error("Assertion failed!"); +>!value : boolean +>value : boolean +>new Error("Assertion failed!") : Error +>Error : ErrorConstructor +>"Assertion failed!" : string +} + + +=== tests/cases/compiler/bundleUMD_file1.ts === +import {Foo, assert} from "./bundleUMD_file0"; +>Foo : typeof Foo +>assert : (value: boolean) => void + +assert(Foo.CONSTANT === "Foo"); +>assert(Foo.CONSTANT === "Foo") : void +>assert : (value: boolean) => void +>Foo.CONSTANT === "Foo" : boolean +>Foo.CONSTANT : string +>Foo : typeof Foo +>CONSTANT : string +>"Foo" : string + diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js index bf9b57c511cc2..68392519f0fa3 100644 --- a/tests/baselines/reference/systemModule11.js +++ b/tests/baselines/reference/systemModule11.js @@ -52,7 +52,7 @@ System.register(['bar'], function(exports_1) { }; function exportStar_1(m) { var exports = {}; - for(var n in m) { + for (var n in m) { if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } exports_1(exports); @@ -75,7 +75,7 @@ System.register(['bar'], function(exports_1) { }; function exportStar_1(m) { var exports = {}; - for(var n in m) { + for (var n in m) { if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } exports_1(exports); @@ -101,7 +101,7 @@ System.register(['a', 'bar'], function(exports_1) { }; function exportStar_1(m) { var exports = {}; - for(var n in m) { + for (var n in m) { if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } exports_1(exports); @@ -147,7 +147,7 @@ System.register(['a'], function(exports_1) { function foo() { } function exportStar_1(m) { var exports = {}; - for(var n in m) { + for (var n in m) { if (n !== "default") exports[n] = m[n]; } exports_1(exports); diff --git a/tests/baselines/reference/systemModule16.js b/tests/baselines/reference/systemModule16.js index 851b941492a4e..bf37ed4e489d3 100644 --- a/tests/baselines/reference/systemModule16.js +++ b/tests/baselines/reference/systemModule16.js @@ -24,7 +24,7 @@ System.register(["foo", "bar"], function(exports_1) { }; function exportStar_1(m) { var exports = {}; - for(var n in m) { + for (var n in m) { if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } exports_1(exports); diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index d7913f2f8b73e..32f21e0596f3c 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -31,7 +31,7 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], }; function exportStar_1(m) { var exports = {}; - for(var n in m) { + for (var n in m) { if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } exports_1(exports); diff --git a/tests/cases/compiler/bundleAMD.ts b/tests/cases/compiler/bundleAMD.ts new file mode 100644 index 0000000000000..f273651537a56 --- /dev/null +++ b/tests/cases/compiler/bundleAMD.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: amd +// @outFile: bundleAMD_bundle.js +// @bundle: ./bundleAMD_file1 + +// @Filename: bundleAMD_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleAMD_file1.ts +import {Foo, assert} from "./bundleAMD_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleAMD_file0"; diff --git a/tests/cases/compiler/bundleCommonjs.ts b/tests/cases/compiler/bundleCommonjs.ts new file mode 100644 index 0000000000000..10370fc466e13 --- /dev/null +++ b/tests/cases/compiler/bundleCommonjs.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: commonjs +// @outFile: bundleCommonjs_bundle.js +// @bundle: ./bundleCommonjs_file1 + +// @Filename: bundleCommonjs_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleCommonjs_file1.ts +import {Foo, assert} from "./bundleCommonjs_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleCommonjs_file0"; diff --git a/tests/cases/compiler/bundleES6.ts b/tests/cases/compiler/bundleES6.ts new file mode 100644 index 0000000000000..ec15bee18071c --- /dev/null +++ b/tests/cases/compiler/bundleES6.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: es6 +// @outFile: bundleES6_bundle.js +// @bundle: ./bundleES6_file1 + +// @Filename: bundleES6_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleES6_file1.ts +import {Foo, assert} from "./bundleES6_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleES6_file0"; diff --git a/tests/cases/compiler/bundleSFX.ts b/tests/cases/compiler/bundleSFX.ts new file mode 100644 index 0000000000000..700e51acad47d --- /dev/null +++ b/tests/cases/compiler/bundleSFX.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: none +// @outFile: bundleSFX_bundle.js +// @bundle: ./bundleSFX_file1 + +// @Filename: bundleSFX_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleSFX_file1.ts +import {Foo, assert} from "./bundleSFX_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleSFX_file0"; diff --git a/tests/cases/compiler/bundleSystem.ts b/tests/cases/compiler/bundleSystem.ts new file mode 100644 index 0000000000000..2dd949bdf54ea --- /dev/null +++ b/tests/cases/compiler/bundleSystem.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: system +// @outFile: bundleSystem_bundle.js +// @bundle: ./bundleSystem_file1 + +// @Filename: bundleSystem_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleSystem_file1.ts +import {Foo, assert} from "./bundleSystem_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleSystem_file0"; diff --git a/tests/cases/compiler/bundleToES3AMD.ts b/tests/cases/compiler/bundleToES3AMD.ts new file mode 100644 index 0000000000000..84fd3d9275b0d --- /dev/null +++ b/tests/cases/compiler/bundleToES3AMD.ts @@ -0,0 +1,20 @@ +// @target: es3 +// @module: amd +// @outFile: bundleToES3AMD_bundle.js +// @bundle: ./bundleToES3AMD_file1 + +// @Filename: bundleToES3AMD_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleToES3AMD_file1.ts +import {Foo, assert} from "./bundleToES3AMD_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleToES3AMD_file0"; diff --git a/tests/cases/compiler/bundleToES3Commonjs.ts b/tests/cases/compiler/bundleToES3Commonjs.ts new file mode 100644 index 0000000000000..37e1b642837c7 --- /dev/null +++ b/tests/cases/compiler/bundleToES3Commonjs.ts @@ -0,0 +1,20 @@ +// @target: es3 +// @module: amd +// @outFile: bundleToES3Commonjs_bundle.js +// @bundle: ./bundleToES3Commonjs_file1 + +// @Filename: bundleToES3Commonjs_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleToES3Commonjs_file1.ts +import {Foo, assert} from "./bundleToES3Commonjs_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleToES3Commonjs_file0"; diff --git a/tests/cases/compiler/bundleToES3SFX.ts b/tests/cases/compiler/bundleToES3SFX.ts new file mode 100644 index 0000000000000..dd5fba7808e99 --- /dev/null +++ b/tests/cases/compiler/bundleToES3SFX.ts @@ -0,0 +1,20 @@ +// @target: es3 +// @module: none +// @outFile: bundleToES3SFX_bundle.js +// @bundle: ./bundleToES3SFX_file1 + +// @Filename: bundleToES3SFX_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleToES3SFX_file1.ts +import {Foo, assert} from "./bundleToES3SFX_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleToES3SFX_file0"; diff --git a/tests/cases/compiler/bundleToES3System.ts b/tests/cases/compiler/bundleToES3System.ts new file mode 100644 index 0000000000000..5605c60e38fd6 --- /dev/null +++ b/tests/cases/compiler/bundleToES3System.ts @@ -0,0 +1,20 @@ +// @target: es3 +// @module: system +// @outFile: bundleToES3System_bundle.js +// @bundle: ./bundleToES3System_file1 + +// @Filename: bundleToES3System_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleToES3System_file1.ts +import {Foo, assert} from "./bundleToES3System_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleToES3System_file0"; diff --git a/tests/cases/compiler/bundleToES3UMD.ts b/tests/cases/compiler/bundleToES3UMD.ts new file mode 100644 index 0000000000000..f404d392f01fb --- /dev/null +++ b/tests/cases/compiler/bundleToES3UMD.ts @@ -0,0 +1,20 @@ +// @target: es3 +// @module: umd +// @outFile: bundleToES3UMD_bundle.js +// @bundle: ./bundleToES3UMD_file1 + +// @Filename: bundleToES3UMD_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleToES3UMD_file1.ts +import {Foo, assert} from "./bundleToES3UMD_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleToES3UMD_file0"; diff --git a/tests/cases/compiler/bundleUMD.ts b/tests/cases/compiler/bundleUMD.ts new file mode 100644 index 0000000000000..41ec57bcdc9ec --- /dev/null +++ b/tests/cases/compiler/bundleUMD.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: umd +// @outFile: bundleUMD_bundle.js +// @bundle: ./bundleUMD_file1 + +// @Filename: bundleUMD_file0.ts +export class Foo { + static CONSTANT = "Foo"; +} + +export function assert(value: boolean) { + if (!value) throw new Error("Assertion failed!"); +} + + +// @Filename: bundleUMD_file1.ts +import {Foo, assert} from "./bundleUMD_file0"; +assert(Foo.CONSTANT === "Foo"); + +export {assert} from "./bundleUMD_file0";