diff --git a/Jakefile.js b/Jakefile.js index b025bba4087..dae99085bef 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -626,9 +626,7 @@ function deleteTemporaryProjectOutput() { } } -var testTimeout = 20000; -desc("Runs the tests using the built run.js file. Syntax is jake runtests. Optional parameters 'host=', 'tests=[regex], reporter=[list|spec|json|]', debug=true."); -task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { +function runConsoleTests(defaultReporter, defaultSubsets, postLint) { cleanTestDirs(); var debug = process.env.debug || process.env.d; tests = process.env.test || process.env.tests || process.env.t; @@ -638,7 +636,7 @@ task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { fs.unlinkSync(testConfigFile); } - if(tests || light) { + if (tests || light) { writeTestConfigFile(tests, light, testConfigFile); } @@ -648,20 +646,48 @@ task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { colors = process.env.colors || process.env.color colors = colors ? ' --no-colors ' : ' --colors '; - tests = tests ? ' -g ' + tests : ''; - reporter = process.env.reporter || process.env.r || 'mocha-fivemat-progress-reporter'; + reporter = process.env.reporter || process.env.r || defaultReporter; + // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer - var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; - console.log(cmd); - exec(cmd, function() { - deleteTemporaryProjectOutput(); - var lint = jake.Task['lint']; - lint.addListener('complete', function () { - complete(); + var subsetRegexes; + if(defaultSubsets.length === 0) { + subsetRegexes = [tests] + } + else { + var subsets = tests ? tests.split("|") : defaultSubsets; + subsetRegexes = subsets.map(function (sub) { return "^" + sub + ".*$"; }); + subsetRegexes.push("^(?!" + subsets.join("|") + ").*$"); + } + subsetRegexes.forEach(function (subsetRegex) { + tests = subsetRegex ? ' -g "' + subsetRegex + '"' : ''; + var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; + console.log(cmd); + exec(cmd, function () { + deleteTemporaryProjectOutput(); + if (postLint) { + var lint = jake.Task['lint']; + lint.addListener('complete', function () { + complete(); + }); + lint.invoke(); + } + else { + complete(); + } }); - lint.invoke(); }); +} + +var testTimeout = 20000; +desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true."); +task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function() { + runConsoleTests('min', ['compiler', 'conformance', 'Projects', 'fourslash']); +}, {async: true}); + +desc("Runs the tests using the built run.js file. Optional arguments are: t[ests]=regex r[eporter]=[list|spec|json|] d[ebug]=true color[s]=false."); +task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { + runConsoleTests('mocha-fivemat-progress-reporter', [], /*postLint*/ true); }, {async: true}); desc("Generates code coverage data via instanbul"); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfbd7090f5e..50b826c1d14 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2845,23 +2845,29 @@ namespace ts { return type.resolvedBaseConstructorType; } + function hasClassBaseType(type: InterfaceType): boolean { + return !!forEach(getBaseTypes(type), t => !!(t.symbol.flags & SymbolFlags.Class)); + } + function getBaseTypes(type: InterfaceType): ObjectType[] { + let isClass = type.symbol.flags & SymbolFlags.Class; + let isInterface = type.symbol.flags & SymbolFlags.Interface; if (!type.resolvedBaseTypes) { - if (type.symbol.flags & SymbolFlags.Class) { + if (!isClass && !isInterface) { + Debug.fail("type must be class or interface"); + } + if (isClass) { resolveBaseTypesOfClass(type); } - else if (type.symbol.flags & SymbolFlags.Interface) { + if (isInterface) { resolveBaseTypesOfInterface(type); } - else { - Debug.fail("type must be class or interface"); - } } return type.resolvedBaseTypes; } function resolveBaseTypesOfClass(type: InterfaceType): void { - type.resolvedBaseTypes = emptyArray; + type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray; let baseContructorType = getBaseConstructorTypeOfClass(type); if (!(baseContructorType.flags & TypeFlags.ObjectType)) { return; @@ -2897,11 +2903,16 @@ namespace ts { typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType)); return; } - type.resolvedBaseTypes = [baseType]; + if (type.resolvedBaseTypes === emptyArray) { + type.resolvedBaseTypes = [baseType]; + } + else { + type.resolvedBaseTypes.push(baseType); + } } function resolveBaseTypesOfInterface(type: InterfaceType): void { - type.resolvedBaseTypes = []; + type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray; for (let declaration of type.symbol.declarations) { if (declaration.kind === SyntaxKind.InterfaceDeclaration && getInterfaceBaseTypeNodes(declaration)) { for (let node of getInterfaceBaseTypeNodes(declaration)) { @@ -2909,7 +2920,12 @@ namespace ts { if (baseType !== unknownType) { if (getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface)) { if (type !== baseType && !hasBaseType(baseType, type)) { - type.resolvedBaseTypes.push(baseType); + if (type.resolvedBaseTypes === emptyArray) { + type.resolvedBaseTypes = [baseType]; + } + else { + type.resolvedBaseTypes.push(baseType); + } } else { error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType)); @@ -3252,7 +3268,7 @@ namespace ts { } function getDefaultConstructSignatures(classType: InterfaceType): Signature[] { - if (!getBaseTypes(classType).length) { + if (!hasClassBaseType(classType)) { return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)]; } let baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -5621,11 +5637,10 @@ namespace ts { // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N source = getErasedSignature(source); target = getErasedSignature(target); - let sourceLen = source.parameters.length; let targetLen = target.parameters.length; for (let i = 0; i < targetLen; i++) { - let s = source.hasRestParameter && i === sourceLen - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); - let t = target.hasRestParameter && i === targetLen - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); + let s = isRestParameterIndex(source, i) ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); + let t = isRestParameterIndex(target, i) ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); let related = compareTypes(s, t); if (!related) { return Ternary.False; @@ -5638,6 +5653,10 @@ namespace ts { return result; } + function isRestParameterIndex(signature: Signature, parameterIndex: number) { + return signature.hasRestParameter && parameterIndex >= signature.parameters.length - 1; + } + function isSupertypeOfEach(candidate: Type, types: Type[]): boolean { for (let type of types) { if (candidate !== type && !isTypeSubtypeOf(type, candidate)) return false; @@ -6803,8 +6822,9 @@ namespace ts { } // If last parameter is contextually rest parameter get its type - if (indexOfParameter === (func.parameters.length - 1) && - funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) { + if (funcHasRestParameters && + indexOfParameter === (func.parameters.length - 1) && + isRestParameterIndex(contextualSignature, func.parameters.length - 1)) { return getTypeOfSymbol(lastOrUndefined(contextualSignature.parameters)); } } @@ -8409,7 +8429,7 @@ namespace ts { // If spread arguments are present, check that they correspond to a rest parameter. If so, no // further checking is necessary. if (spreadArgIndex >= 0) { - return signature.hasRestParameter && spreadArgIndex >= signature.parameters.length - 1; + return isRestParameterIndex(signature, spreadArgIndex); } // Too many arguments implies incorrect arity. @@ -9400,7 +9420,7 @@ namespace ts { let contextualParameterType = getTypeAtPosition(context, i); assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } - if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) { + if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) { let parameter = lastOrUndefined(signature.parameters); let contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters)); assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); @@ -15990,11 +16010,14 @@ namespace ts { // DeclarationElement: // ExportAssignment // export_opt InterfaceDeclaration + // export_opt TypeAliasDeclaration // export_opt ImportDeclaration // export_opt ExternalImportDeclaration // export_opt AmbientDeclaration // + // TODO: The spec needs to be amended to reflect this grammar. if (node.kind === SyntaxKind.InterfaceDeclaration || + node.kind === SyntaxKind.TypeAliasDeclaration || node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration || diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 0c561ab06d8..58e72241374 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -79,9 +79,9 @@ namespace ts { "es6": ModuleKind.ES6, "es2015": ModuleKind.ES2015, }, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015, paramType: Diagnostics.KIND, - error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 + error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es2015 }, { name: "newLine", @@ -212,9 +212,9 @@ namespace ts { "es6": ScriptTarget.ES6, "es2015": ScriptTarget.ES2015, }, - description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, + description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_experimental, paramType: Diagnostics.VERSION, - error: Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 + error: Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES2015 }, { name: "version", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 188cf23f76c..4fdeb122983 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -627,7 +627,7 @@ "category": "Error", "code": 1203 }, - "Cannot compile modules into 'es6' when targeting 'ES5' or lower.": { + "Cannot compile modules into 'es2015' when targeting 'ES5' or lower.": { "category": "Error", "code": 1204 }, @@ -1712,10 +1712,6 @@ "category": "Error", "code": 2654 }, - "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition.": { - "category": "Error", - "code": 2655 - }, "Exported external package typings file '{0}' is not a module. Please contact the package author to update the package definition.": { "category": "Error", "code": 2656 @@ -2044,7 +2040,7 @@ "category": "Error", "code": 5042 }, - "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": { + "Option 'isolatedModules' can only be used when either option '--module' is provided or option 'target' is 'ES2015' or higher.": { "category": "Error", "code": 5047 }, @@ -2105,11 +2101,11 @@ "category": "Message", "code": 6010 }, - "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": { - "category": "Message", - "code": 6015 - }, - "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'": { + "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": { + "category": "Message", + "code": 6015 + }, + "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'": { "category": "Message", "code": 6016 }, @@ -2193,14 +2189,14 @@ "category": "Error", "code": 6045 }, - "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'.": { + "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es2015'.": { "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'.": { - "category": "Error", - "code": 6047 - }, + "Argument for '--target' option must be 'ES3', 'ES5', or 'ES2015'.": { + "category": "Error", + "code": 6047 + }, "Locale must be of the form or -. For example '{0}' or '{1}'.": { "category": "Error", "code": 6048 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 32f40e7f180..c73d22c898b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2770,7 +2770,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * we we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean { - if (!node || languageVersion >= ScriptTarget.ES6 || !isCurrentFileSystemExternalModule()) { + if (!node || !isCurrentFileSystemExternalModule()) { return false; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d76e7585d15..20272ce9898 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -863,10 +863,6 @@ namespace ts { 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); - fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); - } else if (importedFile.referencedFiles.length) { let firstRef = importedFile.referencedFiles[0]; fileProcessingDiagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); @@ -1005,7 +1001,7 @@ namespace ts { let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (options.isolatedModules) { if (!options.module && 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)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher)); } let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); @@ -1022,7 +1018,7 @@ namespace ts { // 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)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } // there has to be common source directory if user specified --outdir || --sourceRoot diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e51fda074c5..c493cf8f87f 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -159,6 +159,11 @@ namespace ts { let timerHandleForRecompilation: number; // Handle for 0.25s wait timer to trigger recompilation let timerHandleForDirectoryChanges: number; // Handle for 0.25s wait timer to trigger directory change handler + // This map stores and reuses results of fileExists check that happen inside 'createProgram' + // This allows to save time in module resolution heavy scenarios when existence of the same file might be checked multiple times. + let cachedExistingFiles: Map; + let hostFileExists: typeof compilerHost.fileExists; + if (commandLine.options.locale) { if (!isJSONSupported()) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale")); @@ -274,8 +279,14 @@ namespace ts { compilerHost = createCompilerHost(compilerOptions); hostGetSourceFile = compilerHost.getSourceFile; compilerHost.getSourceFile = getSourceFile; + + hostFileExists = compilerHost.fileExists; + compilerHost.fileExists = cachedFileExists; } + // reset the cache of existing files + cachedExistingFiles = {}; + let compileResult = compile(rootFileNames, compilerOptions, compilerHost); if (!compilerOptions.watch) { @@ -286,6 +297,13 @@ namespace ts { reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); } + function cachedFileExists(fileName: string): boolean { + if (hasProperty(cachedExistingFiles, fileName)) { + return cachedExistingFiles[fileName]; + } + return cachedExistingFiles[fileName] = hostFileExists(fileName); + } + function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) { // Return existing SourceFile object if one is available if (cachedProgram) { @@ -567,7 +585,7 @@ namespace ts { function writeConfigFile(options: CompilerOptions, fileNames: string[]) { let currentDirectory = sys.getCurrentDirectory(); - let file = combinePaths(currentDirectory, "tsconfig.json"); + let file = normalizePath(combinePaths(currentDirectory, "tsconfig.json")); if (sys.fileExists(file)) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file)); } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index efcca0e37c5..e7d6aee8052 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1268,11 +1268,15 @@ namespace ts.server { if (info.isOpen) { if (this.openFileRoots.indexOf(info) >= 0) { this.openFileRoots = copyListRemovingItem(info, this.openFileRoots); + if (info.defaultProject && !info.defaultProject.isConfiguredProject()) { + this.removeProject(info.defaultProject); + } } if (this.openFilesReferenced.indexOf(info) >= 0) { this.openFilesReferenced = copyListRemovingItem(info, this.openFilesReferenced); } this.openFileRootsConfigured.push(info); + info.defaultProject = project; } } project.addRoot(info); diff --git a/src/server/server.ts b/src/server/server.ts index 39864fc8477..26279959ad7 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -11,7 +11,7 @@ namespace ts.server { input: process.stdin, output: process.stdout, terminal: false, - }); + }); class Logger implements ts.server.Logger { fd = -1; @@ -58,7 +58,7 @@ namespace ts.server { isVerbose() { return this.loggingEnabled() && (this.level == "verbose"); } - + msg(s: string, type = "Err") { if (this.fd < 0) { @@ -89,18 +89,18 @@ namespace ts.server { } exit() { - this.projectService.log("Exiting...","Info"); + this.projectService.log("Exiting...", "Info"); this.projectService.closeLog(); process.exit(0); } listen() { - rl.on('line',(input: string) => { + rl.on('line', (input: string) => { var message = input.trim(); this.onMessage(message); }); - rl.on('close',() => { + rl.on('close', () => { this.exit(); }); } @@ -155,6 +155,38 @@ namespace ts.server { var logger = createLoggerFromEnv(); + let pending: string[] = []; + function queueMessage(s: string) { + pending.push(s); + if (pending.length === 1) { + drain(); + } + } + + function drain() { + Debug.assert(pending.length > 0); + writeBuffer(new Buffer(pending[0], "utf8"), 0); + } + + function writeBuffer(buffer: Buffer, offset: number) { + const toWrite = buffer.length - offset; + fs.write(1, buffer, offset, toWrite, undefined, (err, written, buffer) => { + if (toWrite > written) { + writeBuffer(buffer, offset + written); + } + else { + Debug.assert(pending.length > 0); + pending.shift(); + if (pending.length > 0) { + drain(); + } + } + }); + } + + // Override sys.write because fs.writeSync is not reliable on Node 4 + ts.sys.write = (s: string) => queueMessage(s); + var ioSession = new IOSession(ts.sys, logger); process.on('uncaughtException', function(err: Error) { ioSession.logError(err, "unknown"); diff --git a/tests/baselines/reference/es5andes6module.errors.txt b/tests/baselines/reference/es5andes6module.errors.txt index d5a672b9486..6908bfc8ae6 100644 --- a/tests/baselines/reference/es5andes6module.errors.txt +++ b/tests/baselines/reference/es5andes6module.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile modules into 'es6' when targeting 'ES5' or lower. +error TS1204: Cannot compile modules into 'es2015' when targeting 'ES5' or lower. -!!! error TS1204: Cannot compile modules into 'es6' when targeting 'ES5' or lower. +!!! error TS1204: Cannot compile modules into 'es2015' when targeting 'ES5' or lower. ==== tests/cases/compiler/es5andes6module.ts (0 errors) ==== export default class A diff --git a/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt b/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt index 7d290bcae44..1abc6ca47d4 100644 --- a/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt +++ b/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt @@ -1,6 +1,6 @@ -error TS5047: Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. +error TS5047: Option 'isolatedModules' can only be used when either option '--module' is provided or option 'target' is 'ES2015' or higher. -!!! error TS5047: Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. +!!! error TS5047: Option 'isolatedModules' can only be used when either option '--module' is provided or option 'target' is 'ES2015' or higher. ==== tests/cases/compiler/isolatedModulesUnspecifiedModule.ts (0 errors) ==== export var x; \ No newline at end of file diff --git a/tests/baselines/reference/mergedInheritedClassInterface.js b/tests/baselines/reference/mergedInheritedClassInterface.js new file mode 100644 index 00000000000..2cc88ac9431 --- /dev/null +++ b/tests/baselines/reference/mergedInheritedClassInterface.js @@ -0,0 +1,96 @@ +//// [mergedInheritedClassInterface.ts] +interface BaseInterface { + required: number; + optional?: number; +} + +class BaseClass { + baseMethod() { } + baseNumber: number; +} + +interface Child extends BaseInterface { + additional: number; +} + +class Child extends BaseClass { + classNumber: number; + method() { } +} + +interface ChildNoBaseClass extends BaseInterface { + additional2: string; +} +class ChildNoBaseClass { + classString: string; + method2() { } +} +class Grandchild extends ChildNoBaseClass { +} + +// checks if properties actually were merged +var child : Child; +child.required; +child.optional; +child.additional; +child.baseNumber; +child.classNumber; +child.baseMethod(); +child.method(); + +var grandchild: Grandchild; +grandchild.required; +grandchild.optional; +grandchild.additional2; +grandchild.classString; +grandchild.method2(); + + +//// [mergedInheritedClassInterface.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var BaseClass = (function () { + function BaseClass() { + } + BaseClass.prototype.baseMethod = function () { }; + return BaseClass; +})(); +var Child = (function (_super) { + __extends(Child, _super); + function Child() { + _super.apply(this, arguments); + } + Child.prototype.method = function () { }; + return Child; +})(BaseClass); +var ChildNoBaseClass = (function () { + function ChildNoBaseClass() { + } + ChildNoBaseClass.prototype.method2 = function () { }; + return ChildNoBaseClass; +})(); +var Grandchild = (function (_super) { + __extends(Grandchild, _super); + function Grandchild() { + _super.apply(this, arguments); + } + return Grandchild; +})(ChildNoBaseClass); +// checks if properties actually were merged +var child; +child.required; +child.optional; +child.additional; +child.baseNumber; +child.classNumber; +child.baseMethod(); +child.method(); +var grandchild; +grandchild.required; +grandchild.optional; +grandchild.additional2; +grandchild.classString; +grandchild.method2(); diff --git a/tests/baselines/reference/mergedInheritedClassInterface.symbols b/tests/baselines/reference/mergedInheritedClassInterface.symbols new file mode 100644 index 00000000000..5f4ae67df6f --- /dev/null +++ b/tests/baselines/reference/mergedInheritedClassInterface.symbols @@ -0,0 +1,130 @@ +=== tests/cases/conformance/classes/classDeclarations/mergedInheritedClassInterface.ts === +interface BaseInterface { +>BaseInterface : Symbol(BaseInterface, Decl(mergedInheritedClassInterface.ts, 0, 0)) + + required: number; +>required : Symbol(required, Decl(mergedInheritedClassInterface.ts, 0, 25)) + + optional?: number; +>optional : Symbol(optional, Decl(mergedInheritedClassInterface.ts, 1, 21)) +} + +class BaseClass { +>BaseClass : Symbol(BaseClass, Decl(mergedInheritedClassInterface.ts, 3, 1)) + + baseMethod() { } +>baseMethod : Symbol(baseMethod, Decl(mergedInheritedClassInterface.ts, 5, 17)) + + baseNumber: number; +>baseNumber : Symbol(baseNumber, Decl(mergedInheritedClassInterface.ts, 6, 20)) +} + +interface Child extends BaseInterface { +>Child : Symbol(Child, Decl(mergedInheritedClassInterface.ts, 8, 1), Decl(mergedInheritedClassInterface.ts, 12, 1)) +>BaseInterface : Symbol(BaseInterface, Decl(mergedInheritedClassInterface.ts, 0, 0)) + + additional: number; +>additional : Symbol(additional, Decl(mergedInheritedClassInterface.ts, 10, 39)) +} + +class Child extends BaseClass { +>Child : Symbol(Child, Decl(mergedInheritedClassInterface.ts, 8, 1), Decl(mergedInheritedClassInterface.ts, 12, 1)) +>BaseClass : Symbol(BaseClass, Decl(mergedInheritedClassInterface.ts, 3, 1)) + + classNumber: number; +>classNumber : Symbol(classNumber, Decl(mergedInheritedClassInterface.ts, 14, 31)) + + method() { } +>method : Symbol(method, Decl(mergedInheritedClassInterface.ts, 15, 24)) +} + +interface ChildNoBaseClass extends BaseInterface { +>ChildNoBaseClass : Symbol(ChildNoBaseClass, Decl(mergedInheritedClassInterface.ts, 17, 1), Decl(mergedInheritedClassInterface.ts, 21, 1)) +>BaseInterface : Symbol(BaseInterface, Decl(mergedInheritedClassInterface.ts, 0, 0)) + + additional2: string; +>additional2 : Symbol(additional2, Decl(mergedInheritedClassInterface.ts, 19, 50)) +} +class ChildNoBaseClass { +>ChildNoBaseClass : Symbol(ChildNoBaseClass, Decl(mergedInheritedClassInterface.ts, 17, 1), Decl(mergedInheritedClassInterface.ts, 21, 1)) + + classString: string; +>classString : Symbol(classString, Decl(mergedInheritedClassInterface.ts, 22, 24)) + + method2() { } +>method2 : Symbol(method2, Decl(mergedInheritedClassInterface.ts, 23, 24)) +} +class Grandchild extends ChildNoBaseClass { +>Grandchild : Symbol(Grandchild, Decl(mergedInheritedClassInterface.ts, 25, 1)) +>ChildNoBaseClass : Symbol(ChildNoBaseClass, Decl(mergedInheritedClassInterface.ts, 17, 1), Decl(mergedInheritedClassInterface.ts, 21, 1)) +} + +// checks if properties actually were merged +var child : Child; +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>Child : Symbol(Child, Decl(mergedInheritedClassInterface.ts, 8, 1), Decl(mergedInheritedClassInterface.ts, 12, 1)) + +child.required; +>child.required : Symbol(BaseInterface.required, Decl(mergedInheritedClassInterface.ts, 0, 25)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>required : Symbol(BaseInterface.required, Decl(mergedInheritedClassInterface.ts, 0, 25)) + +child.optional; +>child.optional : Symbol(BaseInterface.optional, Decl(mergedInheritedClassInterface.ts, 1, 21)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>optional : Symbol(BaseInterface.optional, Decl(mergedInheritedClassInterface.ts, 1, 21)) + +child.additional; +>child.additional : Symbol(Child.additional, Decl(mergedInheritedClassInterface.ts, 10, 39)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>additional : Symbol(Child.additional, Decl(mergedInheritedClassInterface.ts, 10, 39)) + +child.baseNumber; +>child.baseNumber : Symbol(BaseClass.baseNumber, Decl(mergedInheritedClassInterface.ts, 6, 20)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>baseNumber : Symbol(BaseClass.baseNumber, Decl(mergedInheritedClassInterface.ts, 6, 20)) + +child.classNumber; +>child.classNumber : Symbol(Child.classNumber, Decl(mergedInheritedClassInterface.ts, 14, 31)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>classNumber : Symbol(Child.classNumber, Decl(mergedInheritedClassInterface.ts, 14, 31)) + +child.baseMethod(); +>child.baseMethod : Symbol(BaseClass.baseMethod, Decl(mergedInheritedClassInterface.ts, 5, 17)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>baseMethod : Symbol(BaseClass.baseMethod, Decl(mergedInheritedClassInterface.ts, 5, 17)) + +child.method(); +>child.method : Symbol(Child.method, Decl(mergedInheritedClassInterface.ts, 15, 24)) +>child : Symbol(child, Decl(mergedInheritedClassInterface.ts, 30, 3)) +>method : Symbol(Child.method, Decl(mergedInheritedClassInterface.ts, 15, 24)) + +var grandchild: Grandchild; +>grandchild : Symbol(grandchild, Decl(mergedInheritedClassInterface.ts, 39, 3)) +>Grandchild : Symbol(Grandchild, Decl(mergedInheritedClassInterface.ts, 25, 1)) + +grandchild.required; +>grandchild.required : Symbol(BaseInterface.required, Decl(mergedInheritedClassInterface.ts, 0, 25)) +>grandchild : Symbol(grandchild, Decl(mergedInheritedClassInterface.ts, 39, 3)) +>required : Symbol(BaseInterface.required, Decl(mergedInheritedClassInterface.ts, 0, 25)) + +grandchild.optional; +>grandchild.optional : Symbol(BaseInterface.optional, Decl(mergedInheritedClassInterface.ts, 1, 21)) +>grandchild : Symbol(grandchild, Decl(mergedInheritedClassInterface.ts, 39, 3)) +>optional : Symbol(BaseInterface.optional, Decl(mergedInheritedClassInterface.ts, 1, 21)) + +grandchild.additional2; +>grandchild.additional2 : Symbol(ChildNoBaseClass.additional2, Decl(mergedInheritedClassInterface.ts, 19, 50)) +>grandchild : Symbol(grandchild, Decl(mergedInheritedClassInterface.ts, 39, 3)) +>additional2 : Symbol(ChildNoBaseClass.additional2, Decl(mergedInheritedClassInterface.ts, 19, 50)) + +grandchild.classString; +>grandchild.classString : Symbol(ChildNoBaseClass.classString, Decl(mergedInheritedClassInterface.ts, 22, 24)) +>grandchild : Symbol(grandchild, Decl(mergedInheritedClassInterface.ts, 39, 3)) +>classString : Symbol(ChildNoBaseClass.classString, Decl(mergedInheritedClassInterface.ts, 22, 24)) + +grandchild.method2(); +>grandchild.method2 : Symbol(ChildNoBaseClass.method2, Decl(mergedInheritedClassInterface.ts, 23, 24)) +>grandchild : Symbol(grandchild, Decl(mergedInheritedClassInterface.ts, 39, 3)) +>method2 : Symbol(ChildNoBaseClass.method2, Decl(mergedInheritedClassInterface.ts, 23, 24)) + diff --git a/tests/baselines/reference/mergedInheritedClassInterface.types b/tests/baselines/reference/mergedInheritedClassInterface.types new file mode 100644 index 00000000000..e7e645fb278 --- /dev/null +++ b/tests/baselines/reference/mergedInheritedClassInterface.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/classes/classDeclarations/mergedInheritedClassInterface.ts === +interface BaseInterface { +>BaseInterface : BaseInterface + + required: number; +>required : number + + optional?: number; +>optional : number +} + +class BaseClass { +>BaseClass : BaseClass + + baseMethod() { } +>baseMethod : () => void + + baseNumber: number; +>baseNumber : number +} + +interface Child extends BaseInterface { +>Child : Child +>BaseInterface : BaseInterface + + additional: number; +>additional : number +} + +class Child extends BaseClass { +>Child : Child +>BaseClass : BaseClass + + classNumber: number; +>classNumber : number + + method() { } +>method : () => void +} + +interface ChildNoBaseClass extends BaseInterface { +>ChildNoBaseClass : ChildNoBaseClass +>BaseInterface : BaseInterface + + additional2: string; +>additional2 : string +} +class ChildNoBaseClass { +>ChildNoBaseClass : ChildNoBaseClass + + classString: string; +>classString : string + + method2() { } +>method2 : () => void +} +class Grandchild extends ChildNoBaseClass { +>Grandchild : Grandchild +>ChildNoBaseClass : ChildNoBaseClass +} + +// checks if properties actually were merged +var child : Child; +>child : Child +>Child : Child + +child.required; +>child.required : number +>child : Child +>required : number + +child.optional; +>child.optional : number +>child : Child +>optional : number + +child.additional; +>child.additional : number +>child : Child +>additional : number + +child.baseNumber; +>child.baseNumber : number +>child : Child +>baseNumber : number + +child.classNumber; +>child.classNumber : number +>child : Child +>classNumber : number + +child.baseMethod(); +>child.baseMethod() : void +>child.baseMethod : () => void +>child : Child +>baseMethod : () => void + +child.method(); +>child.method() : void +>child.method : () => void +>child : Child +>method : () => void + +var grandchild: Grandchild; +>grandchild : Grandchild +>Grandchild : Grandchild + +grandchild.required; +>grandchild.required : number +>grandchild : Grandchild +>required : number + +grandchild.optional; +>grandchild.optional : number +>grandchild : Grandchild +>optional : number + +grandchild.additional2; +>grandchild.additional2 : string +>grandchild : Grandchild +>additional2 : string + +grandchild.classString; +>grandchild.classString : string +>grandchild : Grandchild +>classString : string + +grandchild.method2(); +>grandchild.method2() : void +>grandchild.method2 : () => void +>grandchild : Grandchild +>method2 : () => void + diff --git a/tests/baselines/reference/systemModule1.js b/tests/baselines/reference/systemModule1.js index 573a7ae04c8..8d99e84ae9f 100644 --- a/tests/baselines/reference/systemModule1.js +++ b/tests/baselines/reference/systemModule1.js @@ -8,7 +8,7 @@ System.register([], function(exports_1) { return { setters:[], execute: function() { - x = 1; + exports_1("x", x = 1); } } }); diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index 94ab5028647..e6910840d39 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{}'. +tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{ [x: number]: undefined; }'. ==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2 f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{}'. +!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index f410d408482..ac30556a235 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. - Property 'raw' is missing in type '{}'. +tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type '{ [x: number]: undefined; }'. ==== tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error T f({}, 10, 10); ~~ -!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. -!!! error TS2345: Property 'raw' is missing in type '{}'. +!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'. f `abcdef${ 1234 }${ 5678 }ghijkl`; \ No newline at end of file diff --git a/tests/baselines/reference/typeAliasDeclareKeyword01.d.symbols b/tests/baselines/reference/typeAliasDeclareKeyword01.d.symbols new file mode 100644 index 00000000000..86c1ae8f40c --- /dev/null +++ b/tests/baselines/reference/typeAliasDeclareKeyword01.d.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/typeAliasDeclareKeyword01.d.ts === +type Foo = number; +>Foo : Symbol(Foo, Decl(typeAliasDeclareKeyword01.d.ts, 0, 0)) + +declare type Bar = string; +>Bar : Symbol(Bar, Decl(typeAliasDeclareKeyword01.d.ts, 0, 18)) + diff --git a/tests/baselines/reference/typeAliasDeclareKeyword01.d.types b/tests/baselines/reference/typeAliasDeclareKeyword01.d.types new file mode 100644 index 00000000000..588fdd9012c --- /dev/null +++ b/tests/baselines/reference/typeAliasDeclareKeyword01.d.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/typeAliasDeclareKeyword01.d.ts === +type Foo = number; +>Foo : number + +declare type Bar = string; +>Bar : string + diff --git a/tests/baselines/reference/unionTypeCallSignatures.errors.txt b/tests/baselines/reference/unionTypeCallSignatures.errors.txt index ebe38a589ee..bf1de6ff8e8 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.errors.txt +++ b/tests/baselines/reference/unionTypeCallSignatures.errors.txt @@ -28,9 +28,10 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(67,12): error TS2 tests/cases/conformance/types/union/unionTypeCallSignatures.ts(68,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(69,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(73,12): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (30 errors) ==== +==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (31 errors) ==== var numOrDate: number | Date; var strOrBoolean: string | boolean; var strOrNum: string | number; @@ -162,4 +163,9 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2 ~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. + var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; + strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + strOrNum = unionWithRestParameter4("hello", "world"); \ No newline at end of file diff --git a/tests/baselines/reference/unionTypeCallSignatures.js b/tests/baselines/reference/unionTypeCallSignatures.js index fc3dfc8ebbc..103d92fbef3 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.js +++ b/tests/baselines/reference/unionTypeCallSignatures.js @@ -70,6 +70,9 @@ strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature strOrNum = unionWithRestParameter3(); // error no call signature +var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; +strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature +strOrNum = unionWithRestParameter4("hello", "world"); //// [unionTypeCallSignatures.js] @@ -132,3 +135,6 @@ strOrNum = unionWithRestParameter3('hello', 10); // error no call signature strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature strOrNum = unionWithRestParameter3(); // error no call signature +var unionWithRestParameter4; +strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature +strOrNum = unionWithRestParameter4("hello", "world"); diff --git a/tests/cases/compiler/typeAliasDeclareKeyword01.d.ts b/tests/cases/compiler/typeAliasDeclareKeyword01.d.ts new file mode 100644 index 00000000000..cf2a5061937 --- /dev/null +++ b/tests/cases/compiler/typeAliasDeclareKeyword01.d.ts @@ -0,0 +1,2 @@ +type Foo = number; +declare type Bar = string; \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/mergedInheritedClassInterface.ts b/tests/cases/conformance/classes/classDeclarations/mergedInheritedClassInterface.ts new file mode 100644 index 00000000000..e3bc08e3307 --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/mergedInheritedClassInterface.ts @@ -0,0 +1,45 @@ +interface BaseInterface { + required: number; + optional?: number; +} + +class BaseClass { + baseMethod() { } + baseNumber: number; +} + +interface Child extends BaseInterface { + additional: number; +} + +class Child extends BaseClass { + classNumber: number; + method() { } +} + +interface ChildNoBaseClass extends BaseInterface { + additional2: string; +} +class ChildNoBaseClass { + classString: string; + method2() { } +} +class Grandchild extends ChildNoBaseClass { +} + +// checks if properties actually were merged +var child : Child; +child.required; +child.optional; +child.additional; +child.baseNumber; +child.classNumber; +child.baseMethod(); +child.method(); + +var grandchild: Grandchild; +grandchild.required; +grandchild.optional; +grandchild.additional2; +grandchild.classString; +grandchild.method2(); diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts index ca599329743..a25d27d9a29 100644 --- a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts @@ -69,3 +69,6 @@ strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature strOrNum = unionWithRestParameter3(); // error no call signature +var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; +strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature +strOrNum = unionWithRestParameter4("hello", "world");