From 30fa715c2c768d36fbf200e0bb701a452ce6386c Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Wed, 14 Jan 2015 22:52:07 +0100 Subject: [PATCH 01/71] Remove src\services\compiler\diagnostics.ts It contains the Logger interface but src\services\services.ts is the one which is used (also has more methods) --- src/services/compiler/diagnostics.ts | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/services/compiler/diagnostics.ts diff --git a/src/services/compiler/diagnostics.ts b/src/services/compiler/diagnostics.ts deleted file mode 100644 index 5114f83f9e5..00000000000 --- a/src/services/compiler/diagnostics.ts +++ /dev/null @@ -1,27 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/// - -module TypeScript { - export interface Logger { - log(s: string): void; - } - - export class NullLogger implements Logger { - public log(s: string): void { - } - } -} \ No newline at end of file From e69573b4798a96eb09fe894a59e7cf5270ae2b6e Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Wed, 14 Jan 2015 23:06:46 +0100 Subject: [PATCH 02/71] compiler\tsc.ts isn't used DiagnosticCode.Specify_module_code_generation_0_or_1 doesn't even exist and it doesn't understand es6 --- src/services/compiler/tsc.ts | 736 ----------------------------------- 1 file changed, 736 deletions(-) delete mode 100644 src/services/compiler/tsc.ts diff --git a/src/services/compiler/tsc.ts b/src/services/compiler/tsc.ts deleted file mode 100644 index acd4fb40e6a..00000000000 --- a/src/services/compiler/tsc.ts +++ /dev/null @@ -1,736 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/// -/// -/// - -module TypeScript { - class SourceFile { - constructor(public scriptSnapshot: IScriptSnapshot, public byteOrderMark: ByteOrderMark) { - } - } - - class DiagnosticsLogger implements ILogger { - constructor(public ioHost: IEnvironment) { - } - public information(): boolean { return false; } - public debug(): boolean { return false; } - public warning(): boolean { return false; } - public error(): boolean { return false; } - public fatal(): boolean { return false; } - public log(s: string): void { - this.ioHost.standardOut.WriteLine(s); - } - } - - export class BatchCompiler implements IReferenceResolverHost { - public compilerVersion = "1.0.1.0"; - private inputFiles: string[] = []; - private compilationSettings: ImmutableCompilationSettings; - private resolvedFiles: IResolvedFile[] = []; - private fileNameToSourceFile = new StringHashTable(); - private hasErrors: boolean = false; - private logger: ILogger = null; - - constructor(private ioHost: IEnvironment) { - } - - // Begin batch compilation - public batchCompile() { - // Parse command line options - if (this.parseOptions()) { - var start = new Date().getTime(); - - if (this.compilationSettings.gatherDiagnostics()) { - this.logger = new DiagnosticsLogger(this.ioHost); - } else { - this.logger = new NullLogger(); - } - - if (this.compilationSettings.watch()) { - // Watch will cause the program to stick around as long as the files exist - this.watchFiles(); - return; - } - - // Resolve the compilation environemnt - this.resolve(); - - this.compile(); - - if (this.compilationSettings.gatherDiagnostics()) { - this.logger.log(""); - this.logger.log("File resolution time: " + TypeScript.fileResolutionTime); - this.logger.log(" file read: " + TypeScript.fileResolutionIOTime); - this.logger.log(" scan imports: " + TypeScript.fileResolutionScanImportsTime); - this.logger.log(" import search: " + TypeScript.fileResolutionImportFileSearchTime); - this.logger.log(" get lib.d.ts: " + TypeScript.fileResolutionGetDefaultLibraryTime); - - this.logger.log("SyntaxTree parse time: " + TypeScript.syntaxTreeParseTime); - this.logger.log("Syntax Diagnostics time: " + TypeScript.syntaxDiagnosticsTime); - this.logger.log("Create declarations time: " + TypeScript.createDeclarationsTime); - this.logger.log(""); - this.logger.log("Type check time: " + TypeScript.typeCheckTime); - this.logger.log(""); - this.logger.log("Emit time: " + TypeScript.emitTime); - this.logger.log("Declaration emit time: " + TypeScript.declarationEmitTime); - - this.logger.log("Total number of symbols created: " + TypeScript.pullSymbolID); - this.logger.log("Specialized types created: " + TypeScript.nSpecializationsCreated); - this.logger.log("Specialized signatures created: " + TypeScript.nSpecializedSignaturesCreated); - - this.logger.log(" IsExternallyVisibleTime: " + TypeScript.declarationEmitIsExternallyVisibleTime); - this.logger.log(" TypeSignatureTime: " + TypeScript.declarationEmitTypeSignatureTime); - this.logger.log(" GetBoundDeclTypeTime: " + TypeScript.declarationEmitGetBoundDeclTypeTime); - this.logger.log(" IsOverloadedCallSignatureTime: " + TypeScript.declarationEmitIsOverloadedCallSignatureTime); - this.logger.log(" FunctionDeclarationGetSymbolTime: " + TypeScript.declarationEmitFunctionDeclarationGetSymbolTime); - this.logger.log(" GetBaseTypeTime: " + TypeScript.declarationEmitGetBaseTypeTime); - this.logger.log(" GetAccessorFunctionTime: " + TypeScript.declarationEmitGetAccessorFunctionTime); - this.logger.log(" GetTypeParameterSymbolTime: " + TypeScript.declarationEmitGetTypeParameterSymbolTime); - this.logger.log(" GetImportDeclarationSymbolTime: " + TypeScript.declarationEmitGetImportDeclarationSymbolTime); - - this.logger.log("Emit write file time: " + TypeScript.emitWriteFileTime); - - this.logger.log("Compiler resolve path time: " + TypeScript.compilerResolvePathTime); - this.logger.log("Compiler directory name time: " + TypeScript.compilerDirectoryNameTime); - this.logger.log("Compiler directory exists time: " + TypeScript.compilerDirectoryExistsTime); - this.logger.log("Compiler file exists time: " + TypeScript.compilerFileExistsTime); - - this.logger.log("IO host resolve path time: " + TypeScript.ioHostResolvePathTime); - this.logger.log("IO host directory name time: " + TypeScript.ioHostDirectoryNameTime); - this.logger.log("IO host create directory structure time: " + TypeScript.ioHostCreateDirectoryStructureTime); - this.logger.log("IO host write file time: " + TypeScript.ioHostWriteFileTime); - - this.logger.log("Node make directory time: " + TypeScript.nodeMakeDirectoryTime); - this.logger.log("Node writeFileSync time: " + TypeScript.nodeWriteFileSyncTime); - this.logger.log("Node createBuffer time: " + TypeScript.nodeCreateBufferTime); - - this.logger.log("Total time: " + (new Date().getTime() - start)); - } - } - - // Exit with the appropriate error code - this.ioHost.quit(this.hasErrors ? 1 : 0); - } - - private resolve() { - // Resolve file dependencies, if requested - var includeDefaultLibrary = !this.compilationSettings.noLib(); - var resolvedFiles: IResolvedFile[] = []; - - var start = new Date().getTime(); - - if (!this.compilationSettings.noResolve()) { - // Resolve references - var resolutionResults = ReferenceResolver.resolve(this.inputFiles, this, this.compilationSettings.useCaseSensitiveFileResolution()); - resolvedFiles = resolutionResults.resolvedFiles; - - // Only include the library if useDefaultLib is set to true and did not see any 'no-default-lib' comments - includeDefaultLibrary = !this.compilationSettings.noLib() && !resolutionResults.seenNoDefaultLibTag; - - // Populate any diagnostic messages generated during resolution - resolutionResults.diagnostics.forEach(d => this.addDiagnostic(d)); - } - else { - for (var i = 0, n = this.inputFiles.length; i < n; i++) { - var inputFile = this.inputFiles[i]; - var referencedFiles: string[] = []; - var importedFiles: string[] = []; - - // If declaration files are going to be emitted, preprocess the file contents and add in referenced files as well - if (this.compilationSettings.generateDeclarationFiles()) { - var references = getReferencedFiles(inputFile, this.getScriptSnapshot(inputFile)); - for (var j = 0; j < references.length; j++) { - referencedFiles.push(references[j].path); - } - - inputFile = this.resolvePath(inputFile); - } - - resolvedFiles.push({ - path: inputFile, - referencedFiles: referencedFiles, - importedFiles: importedFiles - }); - } - } - - var defaultLibStart = new Date().getTime(); - if (includeDefaultLibrary) { - var libraryResolvedFile: IResolvedFile = { - path: this.getDefaultLibraryFilePath(), - referencedFiles: [], - importedFiles: [] - }; - - // Prepend the library to the resolved list - resolvedFiles = [libraryResolvedFile].concat(resolvedFiles); - } - TypeScript.fileResolutionGetDefaultLibraryTime += new Date().getTime() - defaultLibStart; - - this.resolvedFiles = resolvedFiles; - - TypeScript.fileResolutionTime = new Date().getTime() - start; - } - - // Returns true if compilation failed from some reason. - private compile(): void { - var compiler = new TypeScriptCompiler(this.logger, this.compilationSettings); - - this.resolvedFiles.forEach(resolvedFile => { - var sourceFile = this.getSourceFile(resolvedFile.path); - compiler.addFile(resolvedFile.path, sourceFile.scriptSnapshot, sourceFile.byteOrderMark, /*version:*/ 0, /*isOpen:*/ false, resolvedFile.referencedFiles); - }); - - for (var it = compiler.compile((path: string) => this.resolvePath(path)); it.moveNext();) { - var result = it.current(); - - result.diagnostics.forEach(d => this.addDiagnostic(d)); - if (!this.tryWriteOutputFiles(result.outputFiles)) { - return; - } - } - } - - // Parse command line options - private parseOptions() { - var opts = new OptionsParser(this.ioHost, this.compilerVersion); - - var mutableSettings = new CompilationSettings(); - opts.option('out', { - usage: { - locCode: DiagnosticCode.Concatenate_and_emit_output_to_single_file, - args: null - }, - type: DiagnosticCode.file2, - set: (str) => { - mutableSettings.outFileOption = str; - } - }); - - opts.option('outDir', { - usage: { - locCode: DiagnosticCode.Redirect_output_structure_to_the_directory, - args: null - }, - type: DiagnosticCode.DIRECTORY, - set: (str) => { - mutableSettings.outDirOption = str; - } - }); - - opts.flag('sourcemap', { - usage: { - locCode: DiagnosticCode.Generates_corresponding_0_file, - args: ['.map'] - }, - set: () => { - mutableSettings.mapSourceFiles = true; - } - }); - - opts.option('mapRoot', { - usage: { - locCode: DiagnosticCode.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, - args: null - }, - type: DiagnosticCode.LOCATION, - set: (str) => { - mutableSettings.mapRoot = str; - } - }); - - opts.option('sourceRoot', { - usage: { - locCode: DiagnosticCode.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, - args: null - }, - type: DiagnosticCode.LOCATION, - set: (str) => { - mutableSettings.sourceRoot = str; - } - }); - - opts.flag('declaration', { - usage: { - locCode: DiagnosticCode.Generates_corresponding_0_file, - args: ['.d.ts'] - }, - set: () => { - mutableSettings.generateDeclarationFiles = true; - } - }, 'd'); - - if (this.ioHost.watchFile) { - opts.flag('watch', { - usage: { - locCode: DiagnosticCode.Watch_input_files, - args: null - }, - set: () => { - mutableSettings.watch = true; - } - }, 'w'); - } - - opts.flag('propagateEnumConstants', { - experimental: true, - set: () => { mutableSettings.propagateEnumConstants = true; } - }); - - opts.flag('removeComments', { - usage: { - locCode: DiagnosticCode.Do_not_emit_comments_to_output, - args: null - }, - set: () => { - mutableSettings.removeComments = true; - } - }); - - opts.flag('noResolve', { - experimental: true, - usage: { - locCode: DiagnosticCode.Skip_resolution_and_preprocessing, - args: null - }, - set: () => { - mutableSettings.noResolve = true; - } - }); - - opts.flag('noLib', { - experimental: true, - set: () => { - mutableSettings.noLib = true; - } - }); - - opts.flag('diagnostics', { - experimental: true, - set: () => { - mutableSettings.gatherDiagnostics = true; - } - }); - - opts.option('target', { - usage: { - locCode: DiagnosticCode.Specify_ECMAScript_target_version_0_default_or_1, - args: ['ES3', 'ES5'] - }, - type: DiagnosticCode.VERSION, - set: (type) => { - type = type.toLowerCase(); - - if (type === 'es3') { - mutableSettings.codeGenTarget = LanguageVersion.EcmaScript3; - } - else if (type === 'es5') { - mutableSettings.codeGenTarget = LanguageVersion.EcmaScript5; - } - else { - this.addDiagnostic( - new Diagnostic(null, null, 0, 0, DiagnosticCode.Argument_for_0_option_must_be_1_or_2, ["target", "ES3", "ES5"])); - } - } - }, 't'); - - opts.option('module', { - usage: { - locCode: DiagnosticCode.Specify_module_code_generation_0_or_1, - args: ['commonjs', 'amd'] - }, - type: DiagnosticCode.KIND, - set: (type) => { - type = type.toLowerCase(); - - if (type === 'commonjs') { - mutableSettings.moduleGenTarget = ModuleGenTarget.Synchronous; - } - else if (type === 'amd') { - mutableSettings.moduleGenTarget = ModuleGenTarget.Asynchronous; - } - else { - this.addDiagnostic( - new Diagnostic(null, null, 0, 0, DiagnosticCode.Argument_for_0_option_must_be_1_or_2, ["module", "commonjs", "amd"])); - } - } - }, 'm'); - - var needsHelp = false; - opts.flag('help', { - usage: { - locCode: DiagnosticCode.Print_this_message, - args: null - }, - set: () => { - needsHelp = true; - } - }, 'h'); - - opts.flag('useCaseSensitiveFileResolution', { - experimental: true, - set: () => { - mutableSettings.useCaseSensitiveFileResolution = true; - } - }); - var shouldPrintVersionOnly = false; - opts.flag('version', { - usage: { - locCode: DiagnosticCode.Print_the_compiler_s_version_0, - args: [this.compilerVersion] - }, - set: () => { - shouldPrintVersionOnly = true; - } - }, 'v'); - - var locale: string = null; - opts.option('locale', { - experimental: true, - usage: { - locCode: DiagnosticCode.Specify_locale_for_errors_and_messages_For_example_0_or_1, - args: ['en', 'ja-jp'] - }, - type: DiagnosticCode.STRING, - set: (value) => { - locale = value; - } - }); - - opts.flag('noImplicitAny', { - usage: { - locCode: DiagnosticCode.Raise_error_on_expressions_and_declarations_with_an_implied_any_type, - args: null - }, - set: () => { - mutableSettings.noImplicitAny = true; - } - }); - - if (Environment.supportsCodePage()) { - opts.option('codepage', { - usage: { - locCode: DiagnosticCode.Specify_the_codepage_to_use_when_opening_source_files, - args: null - }, - type: DiagnosticCode.NUMBER, - set: (arg) => { - mutableSettings.codepage = parseInt(arg, 10); - } - }); - } - - opts.parse(this.ioHost.arguments); - - this.compilationSettings = ImmutableCompilationSettings.fromCompilationSettings(mutableSettings); - - if (locale) { - if (!this.setLocale(locale)) { - return false; - } - } - - this.inputFiles.push.apply(this.inputFiles, opts.unnamed); - - if (shouldPrintVersionOnly) { - opts.printVersion(); - return false; - } - // If no source files provided to compiler - print usage information - else if (this.inputFiles.length === 0 || needsHelp) { - opts.printUsage(); - return false; - } - - return !this.hasErrors; - } - - private setLocale(locale: string): boolean { - var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); - if (!matchResult) { - this.addDiagnostic(new Diagnostic(null, null, 0, 0, DiagnosticCode.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, ['en', 'ja-jp'])); - return false; - } - - var language = matchResult[1]; - var territory = matchResult[3]; - - // First try the entire locale, then fall back to just language if that's all we have. - if (!this.setLanguageAndTerritory(language, territory) && - !this.setLanguageAndTerritory(language, null)) { - - this.addDiagnostic(new Diagnostic(null, null, 0, 0, DiagnosticCode.Unsupported_locale_0, [locale])); - return false; - } - - return true; - } - - private setLanguageAndTerritory(language: string, territory: string): boolean { - - var compilerFilePath = this.ioHost.executingFilePath(); - var containingDirectoryPath = this.ioHost.directoryName(compilerFilePath); - - var filePath = IOUtils.combine(containingDirectoryPath, language); - if (territory) { - filePath = filePath + "-" + territory; - } - - filePath = this.resolvePath(IOUtils.combine(filePath, "diagnosticMessages.generated.json")); - - if (!this.fileExists(filePath)) { - return false; - } - - var fileContents = this.ioHost.readFile(filePath, this.compilationSettings.codepage()); - TypeScript.LocalizedDiagnosticMessages = JSON.parse(fileContents.contents); - return true; - } - - // Handle -watch switch - private watchFiles() { - if (!this.ioHost.watchFile) { - this.addDiagnostic( - new Diagnostic(null, null, 0, 0, DiagnosticCode.Current_host_does_not_support_0_option, ['-w[atch]'])); - return; - } - - var lastResolvedFileSet: string[] = [] - var watchers: { [x: string]: IFileWatcher; } = {}; - var firstTime = true; - - var addWatcher = (fileName: string) => { - if (!watchers[fileName]) { - var watcher = this.ioHost.watchFile(fileName, onWatchedFileChange); - watchers[fileName] = watcher; - } - }; - - var removeWatcher = (fileName: string) => { - if (watchers[fileName]) { - watchers[fileName].close(); - delete watchers[fileName]; - } - }; - - var onWatchedFileChange = () => { - // Clean errors for previous compilation - this.hasErrors = false; - - // Clear out any source file data we've cached. - this.fileNameToSourceFile = new StringHashTable(); - - // Resolve file dependencies, if requested - this.resolve(); - - // Check if any new files were added to the environment as a result of the file change - var oldFiles = lastResolvedFileSet; - var newFiles = this.resolvedFiles.map(resolvedFile => resolvedFile.path).sort(); - - var i = 0, j = 0; - while (i < oldFiles.length && j < newFiles.length) { - - var compareResult = oldFiles[i].localeCompare(newFiles[j]); - if (compareResult === 0) { - // No change here - i++; - j++; - } - else if (compareResult < 0) { - // Entry in old list does not exist in the new one, it was removed - removeWatcher(oldFiles[i]); - i++; - } - else { - // Entry in new list does exist in the new one, it was added - addWatcher(newFiles[j]); - j++; - } - } - - // All remaining unmatched items in the old list have been removed - for (var k = i; k < oldFiles.length; k++) { - removeWatcher(oldFiles[k]); - } - - // All remaing unmatched items in the new list have been added - for (k = j; k < newFiles.length; k++) { - addWatcher(newFiles[k]); - } - - // Update the state - lastResolvedFileSet = newFiles; - - // Print header - if (!firstTime) { - var fileNames = ""; - for (var k = 0; k < lastResolvedFileSet.length; k++) { - fileNames += Environment.newLine + " " + lastResolvedFileSet[k]; - } - this.ioHost.standardError.WriteLine(getLocalizedText(DiagnosticCode.NL_Recompiling_0, [fileNames])); - } - else { - firstTime = false; - } - - // Trigger a new compilation - this.compile(); - }; - - // Switch to using stdout for all error messages - this.ioHost.standardOut = this.ioHost.standardOut; - - onWatchedFileChange(); - } - - private getSourceFile(fileName: string): SourceFile { - var sourceFile: SourceFile = this.fileNameToSourceFile.lookup(fileName); - if (!sourceFile) { - // Attempt to read the file - var fileInformation: FileInformation; - - try { - fileInformation = this.ioHost.readFile(fileName, this.compilationSettings.codepage()); - } - catch (e) { - this.addDiagnostic(new Diagnostic(null, null, 0, 0, DiagnosticCode.Cannot_read_file_0_1, [fileName, e.message])); - fileInformation = new FileInformation("", ByteOrderMark.None); - } - - var snapshot = ScriptSnapshot.fromString(fileInformation.contents); - var sourceFile = new SourceFile(snapshot, fileInformation.byteOrderMark); - this.fileNameToSourceFile.add(fileName, sourceFile); - } - - return sourceFile; - } - - private getDefaultLibraryFilePath(): string { - var compilerFilePath = this.ioHost.executingFilePath(); - var containingDirectoryPath = this.ioHost.directoryName(compilerFilePath); - var libraryFilePath = this.resolvePath(IOUtils.combine(containingDirectoryPath, "lib.d.ts")); - - return libraryFilePath; - } - - /// IReferenceResolverHost methods - getScriptSnapshot(fileName: string): IScriptSnapshot { - return this.getSourceFile(fileName).scriptSnapshot; - } - - resolveRelativePath(path: string, directory: string): string { - var unQuotedPath = stripStartAndEndQuotes(path); - var normalizedPath: string; - - if (isRooted(unQuotedPath) || !directory) { - normalizedPath = unQuotedPath; - } else { - normalizedPath = IOUtils.combine(directory, unQuotedPath); - } - - // get the absolute path - normalizedPath = this.resolvePath(normalizedPath); - - // Switch to forward slashes - normalizedPath = switchToForwardSlashes(normalizedPath); - - return normalizedPath; - } - - private fileExistsCache = createIntrinsicsObject(); - - fileExists(path: string): boolean { - var exists = this.fileExistsCache[path]; - if (exists === undefined) { - var start = new Date().getTime(); - exists = this.ioHost.fileExists(path); - this.fileExistsCache[path] = exists; - TypeScript.compilerFileExistsTime += new Date().getTime() - start; - } - - return exists; - } - - getParentDirectory(path: string): string { - var start = new Date().getTime(); - var result = this.ioHost.directoryName(path); - TypeScript.compilerDirectoryNameTime += new Date().getTime() - start; - - return result; - } - - - private addDiagnostic(diagnostic: Diagnostic): void { - var diagnosticInfo = diagnostic.info(); - if (diagnosticInfo.category === DiagnosticCategory.Error) { - this.hasErrors = true; - } - - this.ioHost.standardError.Write(TypeScriptCompiler.getFullDiagnosticText(diagnostic, path => this.resolvePath(path))); - } - - private tryWriteOutputFiles(outputFiles: OutputFile[]): boolean { - for (var i = 0, n = outputFiles.length; i < n; i++) { - var outputFile = outputFiles[i]; - - try { - this.writeFile(outputFile.name, outputFile.text, outputFile.writeByteOrderMark); - } - catch (e) { - this.addDiagnostic( - new Diagnostic(outputFile.name, null, 0, 0, DiagnosticCode.Emit_Error_0, [e.message])); - return false; - } - } - - return true; - } - - writeFile(fileName: string, contents: string, writeByteOrderMark: boolean): void { - var start = new Date().getTime(); - IOUtils.writeFileAndFolderStructure(this.ioHost, fileName, contents, writeByteOrderMark); - TypeScript.emitWriteFileTime += new Date().getTime() - start; - } - - directoryExists(path: string): boolean { - var start = new Date().getTime(); - var result = this.ioHost.directoryExists(path); - TypeScript.compilerDirectoryExistsTime += new Date().getTime() - start; - return result; - } - - // For performance reasons we cache the results of resolvePath. This avoids costly lookup - // on the disk once we've already resolved a path once. - private resolvePathCache = createIntrinsicsObject(); - - resolvePath(path: string): string { - var cachedValue = this.resolvePathCache[path]; - if (!cachedValue) { - var start = new Date().getTime(); - cachedValue = this.ioHost.absolutePath(path); - this.resolvePathCache[path] = cachedValue; - TypeScript.compilerResolvePathTime += new Date().getTime() - start; - } - - return cachedValue; - } - } - - // Start the batch compilation using the current hosts IO - var batch = new TypeScript.BatchCompiler(Environment); - batch.batchCompile(); -} From 186c04cebc2043961bd85f7961d7ddf847b248fb Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Wed, 14 Jan 2015 23:07:10 +0100 Subject: [PATCH 03/71] Remove now unused diagnostics keys --- src/services/resources/diagnosticCode.generated.ts | 7 ------- src/services/syntax/SyntaxGenerator.d.ts | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/services/resources/diagnosticCode.generated.ts b/src/services/resources/diagnosticCode.generated.ts index 86509fdd63b..1a0ac12e165 100644 --- a/src/services/resources/diagnosticCode.generated.ts +++ b/src/services/resources/diagnosticCode.generated.ts @@ -402,19 +402,13 @@ module TypeScript { Option_0_specified_without_1: "Option '{0}' specified without '{1}'", codepage_option_not_supported_on_current_platform: "'codepage' option not supported on current platform.", Concatenate_and_emit_output_to_single_file: "Concatenate and emit output to single file.", - Generates_corresponding_0_file: "Generates corresponding {0} file.", Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: "Specifies the location where debugger should locate map files instead of generated locations.", Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: "Specifies the location where debugger should locate TypeScript files instead of source locations.", Watch_input_files: "Watch input files.", Redirect_output_structure_to_the_directory: "Redirect output structure to the directory.", Do_not_emit_comments_to_output: "Do not emit comments to output.", - Skip_resolution_and_preprocessing: "Skip resolution and preprocessing.", - Specify_ECMAScript_target_version_0_default_or_1: "Specify ECMAScript target version: '{0}' (default), or '{1}'", - Specify_module_code_generation_0_or_1: "Specify module code generation: '{0}' or '{1}'", Print_this_message: "Print this message.", - Print_the_compiler_s_version_0: "Print the compiler's version: {0}", Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: "Allow use of deprecated '{0}' keyword when referencing an external module.", - Specify_locale_for_errors_and_messages_For_example_0_or_1: "Specify locale for errors and messages. For example '{0}' or '{1}'", Syntax_0: "Syntax: {0}", options: "options", file1: "file", @@ -431,7 +425,6 @@ module TypeScript { LOCATION: "LOCATION", DIRECTORY: "DIRECTORY", NUMBER: "NUMBER", - Specify_the_codepage_to_use_when_opening_source_files: "Specify the codepage to use when opening source files.", Additional_locations: "Additional locations:", This_version_of_the_Javascript_runtime_does_not_support_the_0_function: "This version of the Javascript runtime does not support the '{0}' function.", Unknown_rule: "Unknown rule.", diff --git a/src/services/syntax/SyntaxGenerator.d.ts b/src/services/syntax/SyntaxGenerator.d.ts index d01d227b786..783ecb436ed 100644 --- a/src/services/syntax/SyntaxGenerator.d.ts +++ b/src/services/syntax/SyntaxGenerator.d.ts @@ -383,19 +383,13 @@ declare module TypeScript { Option_0_specified_without_1: string; codepage_option_not_supported_on_current_platform: string; Concatenate_and_emit_output_to_single_file: string; - Generates_corresponding_0_file: string; Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: string; Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: string; Watch_input_files: string; Redirect_output_structure_to_the_directory: string; Do_not_emit_comments_to_output: string; - Skip_resolution_and_preprocessing: string; - Specify_ECMAScript_target_version_0_default_or_1: string; - Specify_module_code_generation_0_or_1: string; Print_this_message: string; - Print_the_compiler_s_version_0: string; Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: string; - Specify_locale_for_errors_and_messages_For_example_0_or_1: string; Syntax_0: string; options: string; file1: string; @@ -412,7 +406,6 @@ declare module TypeScript { LOCATION: string; DIRECTORY: string; NUMBER: string; - Specify_the_codepage_to_use_when_opening_source_files: string; Additional_locations: string; This_version_of_the_Javascript_runtime_does_not_support_the_0_function: string; Unknown_rule: string; From b4bab03353843d7904d7c22d2d1cb3b22e2391df Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Wed, 14 Jan 2015 23:09:48 +0100 Subject: [PATCH 04/71] Removed services/compiler/optionsParser.ts Code is also defined here: src\compiler\tsc.ts --- src/services/compiler/optionsParser.ts | 266 ------------------------- 1 file changed, 266 deletions(-) delete mode 100644 src/services/compiler/optionsParser.ts diff --git a/src/services/compiler/optionsParser.ts b/src/services/compiler/optionsParser.ts deleted file mode 100644 index 6c2a15813d5..00000000000 --- a/src/services/compiler/optionsParser.ts +++ /dev/null @@ -1,266 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/// - -module TypeScript { - export interface IOptions { - name?: string; - flag?: boolean; - short?: string; - usage?: { - locCode: string; // DiagnosticCode - args: string[] - }; - set?: (s: string) => void; - type?: string; // DiagnosticCode - experimental?: boolean; - } - - export class OptionsParser { - private DEFAULT_SHORT_FLAG = "-"; - private DEFAULT_LONG_FLAG = "--"; - - private printedVersion: boolean = false; - - // Find the option record for the given string. Returns null if not found. - private findOption(arg: string) { - var upperCaseArg = arg && arg.toUpperCase(); - - for (var i = 0; i < this.options.length; i++) { - var current = this.options[i]; - - if (upperCaseArg === (current.short && current.short.toUpperCase()) || - upperCaseArg === (current.name && current.name.toUpperCase())) { - return current; - } - } - - return null; - } - - public unnamed: string[] = []; - - public options: IOptions[] = []; - - constructor(public host: IEnvironment, public version: string) { - } - - public printUsage() { - this.printVersion(); - - var optionsWord = getLocalizedText(DiagnosticCode.options, null); - var fileWord = getLocalizedText(DiagnosticCode.file1, null); - var tscSyntax = "tsc [" + optionsWord + "] [" + fileWord + " ..]"; - var syntaxHelp = getLocalizedText(DiagnosticCode.Syntax_0, [tscSyntax]); - this.host.standardOut.WriteLine(syntaxHelp); - this.host.standardOut.WriteLine(""); - this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Examples, null) + " tsc hello.ts"); - this.host.standardOut.WriteLine(" tsc --out foo.js foo.ts"); - this.host.standardOut.WriteLine(" tsc @args.txt"); - this.host.standardOut.WriteLine(""); - this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Options, null)); - - var output: string[][] = []; - var maxLength = 0; - var i = 0; - - this.options = this.options.sort(function (a, b) { - var aName = a.name.toLowerCase(); - var bName = b.name.toLowerCase(); - - if (aName > bName) { - return 1; - } else if (aName < bName) { - return -1; - } else { - return 0; - } - }); - - // Build up output array - for (i = 0; i < this.options.length; i++) { - var option = this.options[i]; - - if (option.experimental) { - continue; - } - - if (!option.usage) { - break; - } - - var usageString = " "; - var type = option.type ? (" " + TypeScript.getLocalizedText(option.type, null)) : ""; - - if (option.short) { - usageString += this.DEFAULT_SHORT_FLAG + option.short + type + ", "; - } - - usageString += this.DEFAULT_LONG_FLAG + option.name + type; - - output.push([usageString, TypeScript.getLocalizedText(option.usage.locCode, option.usage.args)]); - - if (usageString.length > maxLength) { - maxLength = usageString.length; - } - } - - var fileDescription = getLocalizedText(DiagnosticCode.Insert_command_line_options_and_files_from_a_file, null); - output.push([" @<" + fileWord + ">", fileDescription]); - - // Print padded output - for (i = 0; i < output.length; i++) { - this.host.standardOut.WriteLine(output[i][0] + (new Array(maxLength - output[i][0].length + 3)).join(" ") + output[i][1]); - } - } - - public printVersion() { - if (!this.printedVersion) { - this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Version_0, [this.version])); - this.printedVersion = true; - } - } - - public option(name: string, config: IOptions, short?: string) { - if (!config) { - config = short; - short = null; - } - - config.name = name; - config.short = short; - config.flag = false; - - this.options.push(config); - } - - public flag(name: string, config: IOptions, short?: string) { - if (!config) { - config = short; - short = null; - } - - config.name = name; - config.short = short; - config.flag = true; - - this.options.push(config); - } - - // Parse an arguments string - public parseString(argString: string) { - var position = 0; - var tokens = argString.match(/\s+|"|[^\s"]+/g); - - function peek() { - return tokens[position]; - } - - function consume() { - return tokens[position++]; - } - - function consumeQuotedString() { - var value = ''; - consume(); // skip opening quote. - - var token = peek(); - - while (token && token !== '"') { - consume(); - - value += token; - - token = peek(); - } - - consume(); // skip ending quote; - - return value; - } - - var args: string[] = []; - var currentArg = ''; - - while (position < tokens.length) { - var token = peek(); - - if (token === '"') { - currentArg += consumeQuotedString(); - } else if (token.match(/\s/)) { - if (currentArg.length > 0) { - args.push(currentArg); - currentArg = ''; - } - - consume(); - } else { - consume(); - currentArg += token; - } - } - - if (currentArg.length > 0) { - args.push(currentArg); - } - - this.parse(args); - } - - // Parse arguments as they come from the platform: split into arguments. - public parse(args: string[]) { - var position = 0; - - function consume() { - return args[position++]; - } - - while (position < args.length) { - var current = consume(); - var match = current.match(/^(--?|@)(.*)/); - var value: any = null; - - if (match) { - if (match[1] === '@') { - this.parseString(this.host.readFile(match[2], null).contents); - } else { - var arg = match[2]; - var option = this.findOption(arg); - - if (option === null) { - this.host.standardOut.WriteLine(getDiagnosticMessage(DiagnosticCode.Unknown_compiler_option_0, [arg])); - this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Use_the_0_flag_to_see_options, ["--help"])); - } else { - if (!option.flag) { - value = consume(); - if (value === undefined) { - // No value provided - this.host.standardOut.WriteLine(getDiagnosticMessage(DiagnosticCode.Option_0_specified_without_1, [arg, getLocalizedText(option.type, null)])); - this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Use_the_0_flag_to_see_options, ["--help"])); - continue; - } - } - - option.set(value); - } - } - } else { - this.unnamed.push(current); - } - } - } - } -} \ No newline at end of file From 868cbb6d76d6d365c93f8d1513ffc3d018f29f83 Mon Sep 17 00:00:00 2001 From: Dick van den Brink Date: Wed, 14 Jan 2015 23:15:05 +0100 Subject: [PATCH 05/71] Removed services/compiler/emitter.ts This one is replaced by src/compiler/emitter.ts --- src/services/compiler/emitter.ts | 3797 ------------------------------ 1 file changed, 3797 deletions(-) delete mode 100644 src/services/compiler/emitter.ts diff --git a/src/services/compiler/emitter.ts b/src/services/compiler/emitter.ts deleted file mode 100644 index 8de5e64dbba..00000000000 --- a/src/services/compiler/emitter.ts +++ /dev/null @@ -1,3797 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/// - -module TypeScript { - export enum EmitContainer { - Prog, - Module, - DynamicModule, - Class, - Constructor, - Function, - Args, - Interface, - } - - export class EmitState { - public column: number; - public line: number; - public container: EmitContainer; - - constructor() { - this.column = 0; - this.line = 0; - this.container = EmitContainer.Prog; - } - } - - export class EmitOptions { - private _diagnostic: Diagnostic = null; - - private _settings: ImmutableCompilationSettings = null; - private _commonDirectoryPath = ""; - private _sharedOutputFile = ""; - private _sourceRootDirectory = ""; - private _sourceMapRootDirectory = ""; - private _outputDirectory = ""; - - public diagnostic(): Diagnostic { return this._diagnostic; } - - public commonDirectoryPath() { return this._commonDirectoryPath; } - public sharedOutputFile() { return this._sharedOutputFile; } - public sourceRootDirectory() { return this._sourceRootDirectory; } - public sourceMapRootDirectory() { return this._sourceMapRootDirectory; } - public outputDirectory() { return this._outputDirectory; } - - public compilationSettings() { return this._settings; } - - constructor(compiler: TypeScriptCompiler, public resolvePath: (path: string) => string) { - var settings = compiler.compilationSettings(); - this._settings = settings; - - // If the document is an external module, then report if the the user has not - // provided the right command line option. - if (settings.moduleGenTarget() === ModuleGenTarget.Unspecified) { - var fileNames = compiler.fileNames(); - for (var i = 0, n = fileNames.length; i < n; i++) { - var document = compiler.getDocument(fileNames[i]); - if (!document.isDeclareFile() && document.syntaxTree().isExternalModule()) { - var errorSpan = externalModuleIndicatorSpan(document.syntaxTree()); - this._diagnostic = new Diagnostic(document.fileName, document.lineMap(), errorSpan.start(), errorSpan.length(), - DiagnosticCode.Cannot_compile_external_modules_unless_the_module_flag_is_provided); - - return; - } - } - } - - if (!settings.mapSourceFiles()) { - // Error to specify --mapRoot or --sourceRoot without mapSourceFiles - if (settings.mapRoot()) { - if (settings.sourceRoot()) { - this._diagnostic = new Diagnostic(null, null, 0, 0, DiagnosticCode.Options_mapRoot_and_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option, null); - return; - } - else { - this._diagnostic = new Diagnostic(null, null, 0, 0, DiagnosticCode.Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option, null); - return; - } - } - else if (settings.sourceRoot()) { - this._diagnostic = new Diagnostic(null, null, 0, 0, DiagnosticCode.Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option, null); - return; - } - } - - this._sourceMapRootDirectory = convertToDirectoryPath(switchToForwardSlashes(settings.mapRoot())); - this._sourceRootDirectory = convertToDirectoryPath(switchToForwardSlashes(settings.sourceRoot())); - - if (settings.outFileOption() || - settings.outDirOption() || - settings.mapRoot() || - settings.sourceRoot()) { - - if (settings.outFileOption()) { - this._sharedOutputFile = switchToForwardSlashes(resolvePath(settings.outFileOption())); - } - - if (settings.outDirOption()) { - this._outputDirectory = convertToDirectoryPath(switchToForwardSlashes(resolvePath(settings.outDirOption()))); - } - - // Parse the directory structure - if (this._outputDirectory || this._sourceMapRootDirectory || this.sourceRootDirectory) { - this.determineCommonDirectoryPath(compiler); - } - } - } - - private determineCommonDirectoryPath(compiler: TypeScriptCompiler): void { - var commonComponents: string[] = []; - var commonComponentsLength = -1; - - var fileNames = compiler.fileNames(); - for (var i = 0, len = fileNames.length; i < len; i++) { - var fileName = fileNames[i]; - var document = compiler.getDocument(fileNames[i]); - var sourceUnit = document.sourceUnit(); - - if (!document.isDeclareFile()) { - var fileComponents = filePathComponents(fileName); - if (commonComponentsLength === -1) { - // First time at finding common path - // So common path = directory of file - commonComponents = fileComponents; - commonComponentsLength = commonComponents.length; - } - else { - var updatedPath = false; - for (var j = 0; j < commonComponentsLength && j < fileComponents.length; j++) { - if (commonComponents[j] !== fileComponents[j]) { - // The new components = 0 ... j -1 - commonComponentsLength = j; - updatedPath = true; - - if (j === 0) { - var isDynamicModuleCompilation = ArrayUtilities.any(fileNames, fileName => { - document = compiler.getDocument(fileName); - return !document.isDeclareFile() && document.syntaxTree().isExternalModule(); - }); - - if (this._outputDirectory || // there is --outDir specified - this._sourceRootDirectory || // there is --sourceRoot specified - (this._sourceMapRootDirectory && // there is --map Specified and there would be multiple js files generated - (!this._sharedOutputFile || isDynamicModuleCompilation))) { - // Its error to not have common path - this._diagnostic = new Diagnostic(null, null, 0, 0, DiagnosticCode.Cannot_find_the_common_subdirectory_path_for_the_input_files, null); - return; - } - - return; - } - - break; - } - } - - // If the fileComponent path completely matched and less than already found update the length - if (!updatedPath && fileComponents.length < commonComponentsLength) { - commonComponentsLength = fileComponents.length; - } - } - } - } - - this._commonDirectoryPath = commonComponents.slice(0, commonComponentsLength).join("/") + "/"; - } - } - - export class Indenter { - static indentStep: number = 4; - static indentStepString: string = " "; - static indentStrings: string[] = []; - public indentAmt: number = 0; - - public increaseIndent() { - this.indentAmt += Indenter.indentStep; - } - - public decreaseIndent() { - this.indentAmt -= Indenter.indentStep; - } - - public getIndent() { - var indentString = Indenter.indentStrings[this.indentAmt]; - if (indentString === undefined) { - indentString = ""; - for (var i = 0; i < this.indentAmt; i = i + Indenter.indentStep) { - indentString += Indenter.indentStepString; - } - Indenter.indentStrings[this.indentAmt] = indentString; - } - return indentString; - } - } - - export function lastParameterIsRest(parameters: ParameterSyntax[]): boolean { - return parameters.length > 0 && (parameters[parameters.length - 1]).dotDotDotToken !== null; - } - - export class Emitter { - public globalThisCapturePrologueEmitted = false; - public extendsPrologueEmitted = false; - public thisClassNode: ClassDeclarationSyntax = null; - public inArrowFunction: boolean = false; - public moduleName = ""; - public emitState = new EmitState(); - public indenter = new Indenter(); - public sourceMapper: SourceMapper = null; - public captureThisStmtString = "var _this = this;"; - private currentVariableDeclaration: VariableDeclarationSyntax; - private declStack: PullDecl[] = []; - private exportAssignment: ExportAssignmentSyntax = null; - private inWithBlock = false; - - public document: Document = null; - - // If we choose to detach comments from an element (for example, the Copyright comments), - // then keep track of that element so that we don't emit all on the comments on it when - // we visit it. - private detachedCommentsElement: ISyntaxElement = null; - - constructor(public emittingFileName: string, - public outfile: TextWriter, - public emitOptions: EmitOptions, - private semanticInfoChain: SemanticInfoChain) { - } - - private pushDecl(decl: PullDecl) { - if (decl) { - this.declStack[this.declStack.length] = decl; - } - } - - private popDecl(decl: PullDecl) { - if (decl) { - this.declStack.length--; - } - } - - private getEnclosingDecl() { - var declStackLen = this.declStack.length; - var enclosingDecl = declStackLen > 0 ? this.declStack[declStackLen - 1] : null; - return enclosingDecl; - } - - public setExportAssignment(exportAssignment: ExportAssignmentSyntax) { - this.exportAssignment = exportAssignment; - } - - public getExportAssignment() { - return this.exportAssignment; - } - - public setDocument(document: Document) { - this.document = document; - } - - public shouldEmitImportDeclaration(importDeclAST: ImportDeclarationSyntax) { - var isExternalModuleReference = importDeclAST.moduleReference.kind() === SyntaxKind.ExternalModuleReference; - var importDecl = this.semanticInfoChain.getDeclForAST(importDeclAST); - var isExported = hasFlag(importDecl.flags, PullElementFlags.Exported); - var isAmdCodeGen = this.emitOptions.compilationSettings().moduleGenTarget() === ModuleGenTarget.Asynchronous; - - // 1) Any internal reference needs to check if the emit can happen - // 2) External module reference with export modifier always needs to be emitted - // 3) commonjs needs the var declaration for the import declaration - if (isExternalModuleReference && !isExported && isAmdCodeGen) { - return false; - } - - var importSymbol = importDecl.getSymbol(this.semanticInfoChain); - if (importSymbol.isUsedAsValue()) { - return true; - } - - if (importDeclAST.moduleReference.kind() !== SyntaxKind.ExternalModuleReference) { - var canBeUsedExternally = isExported || importSymbol.typeUsedExternally() || importSymbol.isUsedInExportedAlias(); - if (!canBeUsedExternally && !this.document.syntaxTree().isExternalModule()) { - // top level import in non-external module are visible across the whole global module - canBeUsedExternally = hasFlag(importDecl.getParentDecl().kind, PullElementKind.Script | PullElementKind.DynamicModule); - } - - if (canBeUsedExternally) { - if (importSymbol.getExportAssignedValueSymbol()) { - return true; - } - - var containerSymbol = importSymbol.getExportAssignedContainerSymbol(); - if (containerSymbol && containerSymbol.getInstanceSymbol()) { - return true; - } - } - } - - return false; - } - - public emitImportDeclaration(importDeclAST: ImportDeclarationSyntax) { - var isExternalModuleReference = importDeclAST.moduleReference.kind() === SyntaxKind.ExternalModuleReference; - var importDecl = this.semanticInfoChain.getDeclForAST(importDeclAST); - var isExported = hasFlag(importDecl.flags, PullElementFlags.Exported); - var isAmdCodeGen = this.emitOptions.compilationSettings().moduleGenTarget() === ModuleGenTarget.Asynchronous; - - this.emitComments(importDeclAST, true); - - var importSymbol = importDecl.getSymbol(this.semanticInfoChain); - - var parentSymbol = importSymbol.getContainer(); - var parentKind = parentSymbol ? parentSymbol.kind : PullElementKind.None; - var associatedParentSymbol = parentSymbol ? parentSymbol.getAssociatedContainerType() : null; - var associatedParentSymbolKind = associatedParentSymbol ? associatedParentSymbol.kind : PullElementKind.None; - - var needsPropertyAssignment = false; - var usePropertyAssignmentInsteadOfVarDecl = false; - var moduleNamePrefix: string; - - if (isExported && - (parentKind === PullElementKind.Container || - parentKind === PullElementKind.DynamicModule || - associatedParentSymbolKind === PullElementKind.Container || - associatedParentSymbolKind === PullElementKind.DynamicModule)) { - if (importSymbol.getExportAssignedTypeSymbol() || importSymbol.getExportAssignedContainerSymbol()) { - // Type or container assignment that is exported - needsPropertyAssignment = true; - } - else { - var valueSymbol = importSymbol.getExportAssignedValueSymbol(); - if (valueSymbol && - (valueSymbol.kind === PullElementKind.Method || valueSymbol.kind === PullElementKind.Function)) { - needsPropertyAssignment = true; - } - else { - usePropertyAssignmentInsteadOfVarDecl = true; - } - } - - // Calculate what name prefix to use - if (this.emitState.container === EmitContainer.DynamicModule) { - moduleNamePrefix = "exports." - } - else { - moduleNamePrefix = this.moduleName + "."; - } - } - - if (isAmdCodeGen && isExternalModuleReference) { - // For amdCode gen of exported external module reference, do not emit var declaration - // Emit the property assignment since it is exported - needsPropertyAssignment = true; - } - else { - this.recordSourceMappingStart(importDeclAST); - if (usePropertyAssignmentInsteadOfVarDecl) { - this.writeToOutput(moduleNamePrefix); - } - else { - this.writeToOutput("var "); - } - this.writeToOutput(importDeclAST.identifier.text() + " = "); - var aliasAST = importDeclAST.moduleReference; - - if (isExternalModuleReference) { - this.writeToOutput("require(" + (aliasAST).stringLiteral.text() + ")"); - } - else { - this.emitJavascript((aliasAST).moduleName, false); - } - - this.recordSourceMappingEnd(importDeclAST); - this.writeToOutput(";"); - - if (needsPropertyAssignment) { - this.writeLineToOutput(""); - this.emitIndent(); - } - } - - if (needsPropertyAssignment) { - this.writeToOutputWithSourceMapRecord(moduleNamePrefix + importDeclAST.identifier.text() + " = " + importDeclAST.identifier.text(), importDeclAST); - this.writeToOutput(";"); - } - this.emitComments(importDeclAST, false); - } - - public createSourceMapper(document: Document, jsFileName: string, jsFile: TextWriter, sourceMapOut: TextWriter, resolvePath: (path: string) => string) { - this.sourceMapper = new SourceMapper(jsFile, sourceMapOut, document, jsFileName, this.emitOptions, resolvePath); - } - - public setSourceMapperNewSourceFile(document: Document) { - this.sourceMapper.setNewSourceFile(document, this.emitOptions); - } - - private updateLineAndColumn(s: string) { - var lineNumbers = TextUtilities.parseLineStarts(s); - if (lineNumbers.length > 1) { - // There are new lines in the string, update the line and column number accordingly - this.emitState.line += lineNumbers.length - 1; - this.emitState.column = s.length - lineNumbers[lineNumbers.length - 1]; - } - else { - // No new lines in the string - this.emitState.column += s.length; - } - } - - public writeToOutputWithSourceMapRecord(s: string, astSpan: ISyntaxElement) { - if (astSpan) { - this.recordSourceMappingStart(astSpan); - } - - this.writeToOutput(s); - - if (astSpan) { - this.recordSourceMappingEnd(astSpan); - } - } - - public writeToOutput(s: string) { - this.outfile.Write(s); - this.updateLineAndColumn(s); - } - - public writeLineToOutput(s: string, force = false) { - // No need to print a newline if we're already at the start of the line. - if (!force && s === "" && this.emitState.column === 0) { - return; - } - - this.outfile.WriteLine(s); - this.updateLineAndColumn(s); - this.emitState.column = 0; - this.emitState.line++; - } - - public writeCaptureThisStatement(ast: ISyntaxElement) { - this.emitIndent(); - this.writeToOutputWithSourceMapRecord(this.captureThisStmtString, ast); - this.writeLineToOutput(""); - } - - public setContainer(c: number): number { - var temp = this.emitState.container; - this.emitState.container = c; - return temp; - } - - private getIndentString() { - return this.indenter.getIndent(); - } - - public emitIndent() { - this.writeToOutput(this.getIndentString()); - } - - public emitComment(comment: Comment, trailing: boolean, first: boolean, noLeadingSpace = false) { - if (this.emitOptions.compilationSettings().removeComments()) { - return; - } - - var text = getTrimmedTextLines(comment); - var emitColumn = this.emitState.column; - - if (emitColumn === 0) { - this.emitIndent(); - } - else if (trailing && first && !noLeadingSpace) { - this.writeToOutput(" "); - } - - if (comment.kind() === SyntaxKind.MultiLineCommentTrivia) { - this.recordSourceMappingCommentStart(comment); - this.writeToOutput(text[0]); - - if (text.length > 1 || comment.endsLine) { - for (var i = 1; i < text.length; i++) { - this.writeLineToOutput(""); - this.emitIndent(); - this.writeToOutput(text[i]); - } - this.recordSourceMappingCommentEnd(comment); - this.writeLineToOutput(""); - // Fall through - } - else { - this.recordSourceMappingCommentEnd(comment); - this.writeToOutput(" "); - return; - } - } - else { - this.recordSourceMappingCommentStart(comment); - this.writeToOutput(text[0]); - this.recordSourceMappingCommentEnd(comment); - this.writeLineToOutput(""); - // Fall through - } - - if (!trailing && emitColumn !== 0) { - // If we were indented before, stay indented after. - this.emitIndent(); - } - } - - private text(): ISimpleText { - return this.document.syntaxTree().text; - } - - public emitComments(ast: ISyntaxElement, pre: boolean, onlyPinnedOrTripleSlashComments: boolean = false) { - // Emitting the comments for the exprssion inside an arrow function is handled specially - // in emitFunctionBodyStatements. We don't want to emit those comments a second time. - if (ast && !isShared(ast) && ast.kind() !== SyntaxKind.Block) { - if (ast.parent.kind() === SyntaxKind.SimpleArrowFunctionExpression || ast.parent.kind() === SyntaxKind.ParenthesizedArrowFunctionExpression) { - return; - } - } - - if (pre) { - var preComments = TypeScript.ASTHelpers.preComments(ast, this.text()); - - if (preComments && ast === this.detachedCommentsElement) { - // We're emitting the comments for the first script element. Skip any - // copyright comments, as we'll already have emitted those. - var detachedComments = this.getDetachedComments(ast); - preComments = preComments.slice(detachedComments.length); - this.detachedCommentsElement = null; - } - - // We're emitting comments on an elided element. Only keep the comment if it is - // a triple slash or pinned comment. - if (preComments && onlyPinnedOrTripleSlashComments) { - preComments = ArrayUtilities.where(preComments, c => this.isPinnedOrTripleSlash(c)); - } - - this.emitCommentsArray(preComments, /*trailing:*/ false); - } - else { - this.emitCommentsArray(ASTHelpers.postComments(ast, this.text()), /*trailing:*/ true); - } - } - - private isPinnedOrTripleSlash(comment: Comment): boolean { - var fullText = comment.fullText(); - if (fullText.match(tripleSlashReferenceRegExp)) { - return true; - } - else { - return fullText.indexOf("/*!") === 0; - } - } - - private emitCommentsArray(comments: Comment[], trailing: boolean, noLeadingSpace = false): void { - if (!this.emitOptions.compilationSettings().removeComments() && comments) { - for (var i = 0, n = comments.length; i < n; i++) { - this.emitComment(comments[i], trailing, /*first:*/ i === 0, noLeadingSpace); - } - } - } - - public emitObjectLiteralExpression(objectLiteral: ObjectLiteralExpressionSyntax) { - this.recordSourceMappingStart(objectLiteral); - - // Try to preserve the newlines between elements that the user had. - this.writeToken(objectLiteral.openBraceToken); - this.emitCommaSeparatedList(objectLiteral, objectLiteral.propertyAssignments, /*buffer:*/ " ", /*preserveNewLines:*/ true); - this.writeToken(objectLiteral.closeBraceToken); - - this.recordSourceMappingEnd(objectLiteral); - } - - public emitArrayLiteralExpression(arrayLiteral: ArrayLiteralExpressionSyntax) { - this.recordSourceMappingStart(arrayLiteral); - - // Try to preserve the newlines between elements that the user had. - this.writeToken(arrayLiteral.openBracketToken); - this.emitCommaSeparatedList(arrayLiteral, arrayLiteral.expressions, /*buffer:*/ "", /*preserveNewLines:*/ true); - this.writeToken(arrayLiteral.closeBracketToken); - - this.recordSourceMappingEnd(arrayLiteral); - } - - public emitObjectCreationExpression(objectCreationExpression: ObjectCreationExpressionSyntax) { - this.recordSourceMappingStart(objectCreationExpression); - this.writeToken(objectCreationExpression.newKeyword); - this.writeToOutput(" "); - var target = objectCreationExpression.expression; - - this.emit(target); - if (objectCreationExpression.argumentList) { - this.recordSourceMappingStart(objectCreationExpression.argumentList); - this.writeToken(objectCreationExpression.argumentList.openParenToken); - this.emitCommaSeparatedList(objectCreationExpression.argumentList, objectCreationExpression.argumentList.arguments, /*buffer:*/ "", /*preserveNewLines:*/ false); - this.writeToken(objectCreationExpression.argumentList.closeParenToken); - this.recordSourceMappingEnd(objectCreationExpression.argumentList); - } - - this.recordSourceMappingEnd(objectCreationExpression); - } - - public getConstantDecl(dotExpr: MemberAccessExpressionSyntax): PullEnumElementDecl { - var pullSymbol = this.semanticInfoChain.getSymbolForAST(dotExpr); - if (pullSymbol && pullSymbol.kind === PullElementKind.EnumMember) { - var pullDecls = pullSymbol.getDeclarations(); - if (pullDecls.length === 1) { - var pullDecl = pullDecls[0]; - if (pullDecl.kind === PullElementKind.EnumMember) { - return pullDecl; - } - } - } - - return null; - } - - public tryEmitConstant(dotExpr: MemberAccessExpressionSyntax) { - var propertyName = dotExpr.name; - var boundDecl = this.getConstantDecl(dotExpr); - if (boundDecl) { - var value = boundDecl.constantValue; - if (value !== null) { - this.recordSourceMappingStart(dotExpr); - this.writeToOutput(value.toString()); - var comment = " /* "; - comment += propertyName.text(); - comment += " */"; - this.writeToOutput(comment); - this.recordSourceMappingEnd(dotExpr); - return true; - } - } - - return false; - } - - public emitInvocationExpression(callNode: InvocationExpressionSyntax) { - this.recordSourceMappingStart(callNode); - var target = callNode.expression; - var args = callNode.argumentList.arguments; - - if (target.kind() === SyntaxKind.MemberAccessExpression && (target).expression.kind() === SyntaxKind.SuperKeyword) { - this.emit(target); - this.writeToOutput(".call"); - this.recordSourceMappingStart(args); - this.writeToken(callNode.argumentList.openParenToken); - this.emitThis(); - if (args && args.length > 0) { - this.writeToOutput(", "); - this.emitCommaSeparatedList(callNode.argumentList, args, /*buffer:*/ "", /*preserveNewLines:*/ false); - } - } - else { - if (callNode.expression.kind() === SyntaxKind.SuperKeyword && this.emitState.container === EmitContainer.Constructor) { - this.writeToOutput("_super.call"); - } - else { - this.emitJavascript(target, false); - } - this.recordSourceMappingStart(args); - this.writeToken(callNode.argumentList.openParenToken); - if (callNode.expression.kind() === SyntaxKind.SuperKeyword && this.emitState.container === EmitContainer.Constructor) { - this.writeToOutput("this"); - if (args && args.length > 0) { - this.writeToOutput(", "); - } - } - this.emitCommaSeparatedList(callNode.argumentList, args, /*buffer:*/ "", /*preserveNewLines:*/ false); - } - - this.writeToken(callNode.argumentList.closeParenToken); - this.recordSourceMappingEnd(args); - this.recordSourceMappingEnd(callNode); - } - - private emitParameterList(list: ParameterListSyntax): void { - this.writeToken(list.openParenToken); - this.emitCommentsArray(ASTHelpers.convertTokenTrailingComments(list.openParenToken, this.text()), /*trailing:*/ true, /*noLeadingSpace:*/ true); - this.emitFunctionParameters(list.parameters, list.parameters); - this.writeToken(list.closeParenToken); - } - - private emitFunctionParameters(ast: ISyntaxElement, parameters: ParameterSyntax[]): void { - var argsLen = 0; - - if (parameters) { - this.emitComments(ast, true); - - var tempContainer = this.setContainer(EmitContainer.Args); - argsLen = parameters.length; - var printLen = argsLen; - if (lastParameterIsRest(parameters)) { - printLen--; - } - for (var i = 0; i < printLen; i++) { - var arg = parameters[i]; - this.emit(arg); - - if (i < (printLen - 1)) { - this.writeToOutput(", "); - if (parameters) { - this.emitCommentsArray(ASTHelpers.convertTokenTrailingComments(parameters.separatorAt(i), this.text()), /*trailing:*/ true, /*noLeadingSpace:*/ true); - } - } - } - this.setContainer(tempContainer); - - this.emitComments(ast, false); - } - } - - private emitFunctionBodyStatements(name: string, funcDecl: ISyntaxElement, parameters: ParameterSyntax[], block: BlockSyntax, bodyExpression: ISyntaxElement): void { - this.writeLineToOutput(" {"); - if (name) { - this.recordSourceMappingNameStart(name); - } - - this.indenter.increaseIndent(); - - if (block) { - // We want any detached statements at the start of hte block to stay at the start. - // This is important for features like VSDoc which place their comments inside a - // block, but can't have them preceded by things like "var _this = this" when we - // emit. - - this.emitDetachedComments(block.statements); - } - - // Parameter list parameters with defaults could capture this - if (this.shouldCaptureThis(funcDecl)) { - this.writeCaptureThisStatement(funcDecl); - } - - if (parameters) { - this.emitDefaultValueAssignments(parameters); - this.emitRestParameterInitializer(parameters); - } - - if (block) { - this.emitList(block.statements); - this.emitCommentsArray(ASTHelpers.convertTokenLeadingComments(block.closeBraceToken, this.text()), /*trailing:*/ false); - } - else { - // Copy any comments before the body of the arrow function to the return statement. - // This is necessary for emitting correctness so we don't emit something like this: - // - // return - // // foo - // this.foo(); - // - // Because of ASI, this gets parsed as "return;" which is *not* what we want for - // proper semantics. - //var preComments = bodyExpression.preComments(); - //var postComments = bodyExpression.postComments(); - - //bodyExpression.setPreComments(null); - //bodyExpression.setPostComments(null); - - this.emitIndent(); - this.emitCommentsArray(ASTHelpers.preComments(bodyExpression, this.text()), /*trailing:*/ false); - this.writeToOutput("return "); - this.emit(bodyExpression); - this.writeLineToOutput(";"); - this.emitCommentsArray(ASTHelpers.preComments(bodyExpression, this.text()), /*trailing:*/ true); - - //bodyExpression.setPreComments(preComments); - //bodyExpression.setPostComments(postComments); - } - - this.indenter.decreaseIndent(); - this.emitIndent(); - - if (block) { - this.writeToken(block.closeBraceToken); - } - else { - this.writeToOutputWithSourceMapRecord("}", bodyExpression); - } - - if (name) { - this.recordSourceMappingNameEnd(); - } - } - - private emitDefaultValueAssignments(parameters: ParameterSyntax[]): void { - var n = parameters.length; - if (lastParameterIsRest(parameters)) { - n--; - } - - for (var i = 0; i < n; i++) { - var arg = parameters[i]; - var id = arg.identifier; - var equalsValueClause = arg.equalsValueClause; - if (equalsValueClause) { - this.emitIndent(); - this.recordSourceMappingStart(arg); - this.writeToOutput("if (typeof " + id.text() + " === \"undefined\") { ");// - this.writeToken(id); - this.emitJavascript(equalsValueClause, false); - this.writeLineToOutput("; }"); - this.recordSourceMappingEnd(arg); - } - } - } - - private emitRestParameterInitializer(parameters: ParameterSyntax[]): void { - if (lastParameterIsRest(parameters)) { - var n = parameters.length; - var lastArg = parameters[n - 1]; - var id = lastArg.identifier; - this.emitIndent(); - this.recordSourceMappingStart(lastArg); - this.writeToOutput("var "); - this.writeToken(id); - this.writeLineToOutput(" = [];"); - this.recordSourceMappingEnd(lastArg); - this.emitIndent(); - this.writeToOutput("for ("); - this.writeToOutputWithSourceMapRecord("var _i = 0;", lastArg); - this.writeToOutput(" "); - this.writeToOutputWithSourceMapRecord("_i < (arguments.length - " + (n - 1) + ")", lastArg); - this.writeToOutput("; "); - this.writeToOutputWithSourceMapRecord("_i++", lastArg); - this.writeLineToOutput(") {"); - this.indenter.increaseIndent(); - this.emitIndent(); - - this.writeToOutputWithSourceMapRecord(id.text() + "[_i] = arguments[_i + " + (n - 1) + "];", lastArg); - this.writeLineToOutput(""); - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeLineToOutput("}"); - } - } - - private getImportDecls(fileName: string): PullDecl[] { - var topLevelDecl = this.semanticInfoChain.topLevelDecl(this.document.fileName); - var result: PullDecl[] = []; - - var dynamicModuleDecl = topLevelDecl.getChildDecls()[0]; // Dynamic module declaration has to be present - var queue: PullDecl[] = dynamicModuleDecl.getChildDecls(); - - for (var i = 0, n = queue.length; i < n; i++) { - var decl = queue[i]; - - if (decl.kind & PullElementKind.TypeAlias) { - var importStatementAST = this.semanticInfoChain.getASTForDecl(decl); - if (importStatementAST.moduleReference.kind() === SyntaxKind.ExternalModuleReference) { // external module - var symbol = decl.getSymbol(this.semanticInfoChain); - var typeSymbol = symbol && symbol.type; - if (typeSymbol && typeSymbol !== this.semanticInfoChain.anyTypeSymbol && !typeSymbol.isError()) { - result.push(decl); - } - } - } - } - - return result; - } - - public getModuleImportAndDependencyList(sourceUnit: SourceUnitSyntax) { - var importList = ""; - var dependencyList = ""; - - var importDecls = this.getImportDecls(this.document.fileName); - - // all dependencies are quoted - if (importDecls.length) { - for (var i = 0; i < importDecls.length; i++) { - var importStatementDecl = importDecls[i]; - var importStatementSymbol = importStatementDecl.getSymbol(this.semanticInfoChain); - var importStatementAST = this.semanticInfoChain.getASTForDecl(importStatementDecl); - - if (importStatementSymbol.isUsedAsValue()) { - if (i <= importDecls.length - 1) { - dependencyList += ", "; - importList += ", "; - } - - importList += importStatementDecl.name; - dependencyList += (importStatementAST.moduleReference).stringLiteral.text(); - } - } - } - - // emit any potential amd dependencies - var amdDependencies = this.document.syntaxTree().amdDependencies(); - for (var i = 0; i < amdDependencies.length; i++) { - dependencyList += ", \"" + amdDependencies[i] + "\""; - } - - return { - importList: importList, - dependencyList: dependencyList - }; - } - - public shouldCaptureThis(ast: ISyntaxElement) { - if (ast.kind() === SyntaxKind.SourceUnit) { - var scriptDecl = this.semanticInfoChain.topLevelDecl(this.document.fileName); - return hasFlag(scriptDecl.flags, PullElementFlags.MustCaptureThis); - } - - var decl = this.semanticInfoChain.getDeclForAST(ast); - if (decl) { - return hasFlag(decl.flags, PullElementFlags.MustCaptureThis); - } - - return false; - } - - public emitEnum(moduleDecl: EnumDeclarationSyntax) { - var pullDecl = this.semanticInfoChain.getDeclForAST(moduleDecl); - this.pushDecl(pullDecl); - - var svModuleName = this.moduleName; - this.moduleName = moduleDecl.identifier.text(); - - var temp = this.setContainer(EmitContainer.Module); - var isExported = hasFlag(pullDecl.flags, PullElementFlags.Exported); - - if (!isExported) { - this.recordSourceMappingStart(moduleDecl); - this.writeToOutput("var "); - this.writeToOutputWithSourceMapRecord(this.moduleName, moduleDecl.identifier); - this.writeLineToOutput(";"); - this.recordSourceMappingEnd(moduleDecl); - this.emitIndent(); - } - - this.writeToOutput("("); - this.recordSourceMappingStart(moduleDecl); - this.writeToOutput("function ("); - this.writeToOutputWithSourceMapRecord(this.moduleName, moduleDecl.identifier); - this.writeLineToOutput(") {"); - - this.recordSourceMappingNameStart(this.moduleName); - - this.indenter.increaseIndent(); - - if (this.shouldCaptureThis(moduleDecl)) { - this.writeCaptureThisStatement(moduleDecl); - } - - this.emitSeparatedList(moduleDecl.enumElements); - this.indenter.decreaseIndent(); - this.emitIndent(); - - var parentIsDynamic = temp === EmitContainer.DynamicModule; - if (temp === EmitContainer.Prog && isExported) { - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.writeToOutput(")(this." + this.moduleName + " || (this." + this.moduleName + " = {}));"); - } - else if (isExported || temp === EmitContainer.Prog) { - var dotMod = svModuleName !== "" ? (parentIsDynamic ? "exports" : svModuleName) + "." : svModuleName; - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.writeToOutput(")(" + dotMod + this.moduleName + " || (" + dotMod + this.moduleName + " = {}));"); - } - else if (!isExported && temp !== EmitContainer.Prog) { - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.writeToOutput(")(" + this.moduleName + " || (" + this.moduleName + " = {}));"); - } - else { - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.writeToOutput(")();"); - } - - this.recordSourceMappingEnd(moduleDecl); - if (temp !== EmitContainer.Prog && isExported) { - this.recordSourceMappingStart(moduleDecl); - if (parentIsDynamic) { - this.writeLineToOutput(""); - this.emitIndent(); - this.writeToOutput("var " + this.moduleName + " = exports." + this.moduleName + ";"); - } - else { - this.writeLineToOutput(""); - this.emitIndent(); - this.writeToOutput("var " + this.moduleName + " = " + svModuleName + "." + this.moduleName + ";"); - } - this.recordSourceMappingEnd(moduleDecl); - } - - this.setContainer(temp); - this.moduleName = svModuleName; - - this.popDecl(pullDecl); - } - - private getModuleDeclToVerifyChildNameCollision(moduleDecl: PullDecl, changeNameIfAnyDeclarationInContext: boolean) { - if (ArrayUtilities.contains(this.declStack, moduleDecl)) { - // Given decl is in the scope, we would need to check for child name collision - return moduleDecl; - } - else if (changeNameIfAnyDeclarationInContext) { - // Check if any other declaration of the given symbol is in scope - // (eg. when emitting expression of type defined from different declaration in reopened module) - var symbol = moduleDecl.getSymbol(this.semanticInfoChain); - if (symbol) { - var otherDecls = symbol.getDeclarations(); - for (var i = 0; i < otherDecls.length; i++) { - // If the other decl is in the scope, use this decl to determine which name to display - if (ArrayUtilities.contains(this.declStack, otherDecls[i])) { - return otherDecls[i]; - } - } - } - } - - return null; - } - - private hasChildNameCollision(moduleName: string, parentDecl: PullDecl) { - var childDecls = parentDecl.getChildDecls(); - return ArrayUtilities.any(childDecls, (childDecl: PullDecl) => { - var childAST = this.semanticInfoChain.getASTForDecl(childDecl); - // Enum member it can never conflict with module name as it is property of the enum - // Only if this child would be emitted we need to look further in - if (childDecl.kind != PullElementKind.EnumMember && this.shouldEmit(childAST)) { - // same name child - if (childDecl.name === moduleName) { - // collision if the parent was not class - if (parentDecl.kind != PullElementKind.Class) { - return true; - } - - // If the parent was class, we would find name collision if this was not a property/method/accessor - if (!(childDecl.kind == PullElementKind.Method || - childDecl.kind == PullElementKind.Property || - childDecl.kind == PullElementKind.SetAccessor || - childDecl.kind == PullElementKind.GetAccessor)) { - return true; - } - } - - // Check if the name collision exists in any of the children - if (this.hasChildNameCollision(moduleName, childDecl)) { - return true; - } - } - return false; - }); - } - - // Get the moduleName to write in js file - // If changeNameIfAnyDeclarationInContext is true, verify if any of the declarations for the symbol would need rename. - private getModuleName(moduleDecl: PullDecl, changeNameIfAnyDeclarationInContext?: boolean) { - var moduleName = moduleDecl.name; - var moduleDisplayName = moduleDecl.getDisplayName(); - - // If the decl is in stack it may need name change in the js file - moduleDecl = this.getModuleDeclToVerifyChildNameCollision(moduleDecl, changeNameIfAnyDeclarationInContext); - if (moduleDecl && moduleDecl.kind != PullElementKind.Enum) { - // If there is any child that would be emitted with same name as module, js files would need to use rename for the module - while (this.hasChildNameCollision(moduleName, moduleDecl)) { - // there was name collision with member which could result in faulty codegen, try rename with prepend of '_' - moduleName = "_" + moduleName; - moduleDisplayName = "_" + moduleDisplayName; - } - } - - return moduleDisplayName; - } - - private emitModuleDeclarationWorker(moduleDecl: ModuleDeclarationSyntax) { - if (moduleDecl.stringLiteral) { - this.emitSingleModuleDeclaration(moduleDecl, moduleDecl.stringLiteral); - } - else { - var moduleNames = ASTHelpers.getModuleNames(moduleDecl.name); - this.emitSingleModuleDeclaration(moduleDecl, moduleNames[0]); - } - } - - private writeToken(token: ISyntaxToken) { - if (token) { - this.writeToOutputWithSourceMapRecord(token.text(), token); - } - } - - public emitSingleModuleDeclaration(moduleDecl: ModuleDeclarationSyntax, moduleName: ISyntaxToken) { - var isLastName = ASTHelpers.isLastNameOfModule(moduleDecl, moduleName); - - if (isLastName) { - // Doc Comments on the ast belong to the innermost module being emitted. - this.emitComments(moduleDecl, true); - } - - var pullDecl = this.semanticInfoChain.getDeclForAST(moduleName); - this.pushDecl(pullDecl); - - var svModuleName = this.moduleName; - - if (moduleDecl.stringLiteral) { - this.moduleName = tokenValueText(moduleDecl.stringLiteral); - if (isTSFile(this.moduleName)) { - this.moduleName = this.moduleName.substring(0, this.moduleName.length - ".ts".length); - } - } - else { - this.moduleName = moduleName.text(); - } - - var temp = this.setContainer(EmitContainer.Module); - var isExported = hasFlag(pullDecl.flags, PullElementFlags.Exported); - - // prologue - - if (!isExported) { - this.recordSourceMappingStart(moduleDecl); - this.writeToOutput("var "); - this.writeToOutputWithSourceMapRecord(this.moduleName, moduleName); - this.writeLineToOutput(";"); - this.recordSourceMappingEnd(moduleDecl); - this.emitIndent(); - } - - this.writeToOutput("("); - this.recordSourceMappingStart(moduleDecl); - this.writeToOutput("function ("); - // Use the name that doesnt conflict with its members, - // this.moduleName needs to be updated to make sure that export member declaration is emitted correctly - this.moduleName = this.getModuleName(pullDecl); - this.writeToOutputWithSourceMapRecord(this.moduleName, moduleName); - this.writeLineToOutput(") {"); - - this.recordSourceMappingNameStart(moduleName.text()); - - this.indenter.increaseIndent(); - - if (this.shouldCaptureThis(moduleDecl)) { - this.writeCaptureThisStatement(moduleDecl); - } - - if (moduleName === moduleDecl.stringLiteral) { - this.emitList(moduleDecl.moduleElements); - } - else { - var moduleNames = ASTHelpers.getModuleNames(moduleDecl.name); - var nameIndex = moduleNames.indexOf(moduleName); - - Debug.assert(nameIndex >= 0); - - if (isLastName) { - // If we're on the innermost module, we can emit the module elements. - this.emitList(moduleDecl.moduleElements); - } - else { - // otherwise, just recurse and emit the next module in the A.B.C module name. - this.emitIndent(); - this.emitSingleModuleDeclaration(moduleDecl, moduleNames[nameIndex + 1]); - this.writeLineToOutput(""); - } - } - - this.moduleName = moduleName.text(); - this.indenter.decreaseIndent(); - this.emitIndent(); - - // epilogue - var parentIsDynamic = temp === EmitContainer.DynamicModule; - this.recordSourceMappingStart(moduleDecl.closeBraceToken); - if (temp === EmitContainer.Prog && isExported) { - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.recordSourceMappingEnd(moduleDecl.closeBraceToken); - this.writeToOutput(")(this." + this.moduleName + " || (this." + this.moduleName + " = {}));"); - } - else if (isExported || temp === EmitContainer.Prog) { - var dotMod = svModuleName !== "" ? (parentIsDynamic ? "exports" : svModuleName) + "." : svModuleName; - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.recordSourceMappingEnd(moduleDecl.closeBraceToken); - this.writeToOutput(")(" + dotMod + this.moduleName + " || (" + dotMod + this.moduleName + " = {}));"); - } - else if (!isExported && temp !== EmitContainer.Prog) { - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.recordSourceMappingEnd(moduleDecl.closeBraceToken); - this.writeToOutput(")(" + this.moduleName + " || (" + this.moduleName + " = {}));"); - } - else { - this.writeToOutput("}"); - this.recordSourceMappingNameEnd(); - this.recordSourceMappingEnd(moduleDecl.closeBraceToken); - this.writeToOutput(")();"); - } - - this.recordSourceMappingEnd(moduleDecl); - if (temp !== EmitContainer.Prog && isExported) { - this.recordSourceMappingStart(moduleDecl); - if (parentIsDynamic) { - this.writeLineToOutput(""); - this.emitIndent(); - this.writeToOutput("var " + this.moduleName + " = exports." + this.moduleName + ";"); - } - else { - this.writeLineToOutput(""); - this.emitIndent(); - this.writeToOutput("var " + this.moduleName + " = " + svModuleName + "." + this.moduleName + ";"); - } - this.recordSourceMappingEnd(moduleDecl); - } - - this.setContainer(temp); - this.moduleName = svModuleName; - - this.popDecl(pullDecl); - - if (isLastName) { - // Comments on the module ast belong to the innermost module being emitted. - this.emitComments(moduleDecl, false); - } - } - - public emitEnumElement(varDecl: EnumElementSyntax): void { - // [[""] = ] = ""; - var pullDecl = this.semanticInfoChain.getDeclForAST(varDecl); - Debug.assert(pullDecl && pullDecl.kind === PullElementKind.EnumMember); - - this.emitComments(varDecl, true); - this.recordSourceMappingStart(varDecl); - - var representation = (varDecl.propertyName.kind() === SyntaxKind.StringLiteral) - ? varDecl.propertyName.text() - : ('"' + tokenValueText(varDecl.propertyName) + '"'); - - this.writeToOutput(this.moduleName); - this.writeToOutput('['); - this.writeToOutput(this.moduleName); - this.writeToOutput('['); - this.writeToOutput(representation); - this.writeToOutput(']'); - - if (varDecl.equalsValueClause) { - this.emit(varDecl.equalsValueClause); - } - else if (pullDecl.constantValue !== null) { - this.writeToOutput(' = '); - this.writeToOutput(pullDecl.constantValue.toString()); - } - else { - this.writeToOutput(' = null'); - } - - this.writeToOutput('] = '); - this.writeToOutput(representation); - this.recordSourceMappingEnd(varDecl); - this.emitComments(varDecl, false); - this.writeToOutput(';'); - } - - public emitElementAccessExpression(expression: ElementAccessExpressionSyntax) { - this.recordSourceMappingStart(expression); - this.emit(expression.expression); - this.writeToken(expression.openBracketToken); - this.emit(expression.argumentExpression); - this.writeToken(expression.closeBracketToken); - this.recordSourceMappingEnd(expression); - } - - public emitSimpleArrowFunctionExpression(arrowFunction: SimpleArrowFunctionExpressionSyntax): void { - this.emitAnyArrowFunctionExpression(arrowFunction, arrowFunction.block, arrowFunction.expression); - } - - public emitParenthesizedArrowFunctionExpression(arrowFunction: ParenthesizedArrowFunctionExpressionSyntax): void { - this.emitAnyArrowFunctionExpression(arrowFunction, arrowFunction.block, arrowFunction.expression); - } - - private emitAnyArrowFunctionExpression(arrowFunction: ISyntaxElement, block: BlockSyntax, expression: ISyntaxElement): void { - var savedInArrowFunction = this.inArrowFunction; - this.inArrowFunction = true; - - var temp = this.setContainer(EmitContainer.Function); - - this.recordSourceMappingStart(arrowFunction); - - // Start - var pullDecl = this.semanticInfoChain.getDeclForAST(arrowFunction); - this.pushDecl(pullDecl); - - this.emitComments(arrowFunction, true); - - this.recordSourceMappingStart(arrowFunction); - this.writeToOutput("function "); - - var parameters: ParameterSyntax[] = null; - if (arrowFunction.kind() === SyntaxKind.ParenthesizedArrowFunctionExpression) { - var parenthesizedArrowFunction = arrowFunction; - - parameters = parenthesizedArrowFunction.callSignature.parameterList.parameters; - this.emitParameterList(parenthesizedArrowFunction.callSignature.parameterList); - } - else { - var parameter = (arrowFunction).parameter; - parameters = [parameter]; - this.writeToOutput("("); - this.emitFunctionParameters(parameter, parameters); - this.writeToOutput(")"); - } - - this.emitFunctionBodyStatements(/*funcName:*/ null, arrowFunction, parameters, block, expression); - - this.recordSourceMappingEnd(arrowFunction); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(arrowFunction); - - this.emitComments(arrowFunction, false); - - this.popDecl(pullDecl); - this.setContainer(temp); - this.inArrowFunction = savedInArrowFunction; - } - - public emitConstructor(funcDecl: ConstructorDeclarationSyntax) { - if (!funcDecl.block) { - return; - } - var temp = this.setContainer(EmitContainer.Constructor); - - this.recordSourceMappingStart(funcDecl); - - var pullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - this.pushDecl(pullDecl); - - this.emitComments(funcDecl, true); - - this.recordSourceMappingStart(funcDecl); - this.writeToOutput("function "); - this.writeToOutput(this.thisClassNode.identifier.text()); - - this.emitParameterList(funcDecl.callSignature.parameterList); - this.writeLineToOutput(" {"); - - this.recordSourceMappingNameStart("constructor"); - this.indenter.increaseIndent(); - - var parameters = funcDecl.callSignature.parameterList.parameters; - this.emitDefaultValueAssignments(parameters); - this.emitRestParameterInitializer(parameters); - - if (this.shouldCaptureThis(funcDecl)) { - this.writeCaptureThisStatement(funcDecl); - } - - this.emitConstructorStatements(funcDecl); - this.emitCommentsArray(ASTHelpers.convertTokenLeadingComments(funcDecl.block.closeBraceToken, this.text()), /*trailing:*/ false); - - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeToken(funcDecl.block.closeBraceToken); - - this.recordSourceMappingNameEnd(); - this.recordSourceMappingEnd(funcDecl); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(funcDecl); - - this.emitComments(funcDecl, false); - - this.popDecl(pullDecl); - this.setContainer(temp); - } - - public emitGetAccessor(accessor: GetAccessorSyntax): void { - this.recordSourceMappingStart(accessor); - this.writeToOutput("get "); - - var temp = this.setContainer(EmitContainer.Function); - - this.recordSourceMappingStart(accessor); - - var pullDecl = this.semanticInfoChain.getDeclForAST(accessor); - this.pushDecl(pullDecl); - - this.recordSourceMappingStart(accessor); - - var accessorSymbol = PullHelpers.getAccessorSymbol(accessor, this.semanticInfoChain); - var container = accessorSymbol.getContainer(); - var containerKind = container.kind; - - this.recordSourceMappingNameStart(accessor.propertyName.text()); - this.writeToOutput(accessor.propertyName.text()); - this.emitParameterList(accessor.callSignature.parameterList); - - this.emitFunctionBodyStatements(null, accessor, accessor.callSignature.parameterList.parameters, accessor.block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(accessor); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(accessor); - - this.popDecl(pullDecl); - this.setContainer(temp); - this.recordSourceMappingEnd(accessor); - } - - public emitSetAccessor(accessor: SetAccessorSyntax): void { - this.recordSourceMappingStart(accessor); - this.writeToOutput("set "); - - var temp = this.setContainer(EmitContainer.Function); - - this.recordSourceMappingStart(accessor); - - var pullDecl = this.semanticInfoChain.getDeclForAST(accessor); - this.pushDecl(pullDecl); - - this.recordSourceMappingStart(accessor); - - var accessorSymbol = PullHelpers.getAccessorSymbol(accessor, this.semanticInfoChain); - var container = accessorSymbol.getContainer(); - var containerKind = container.kind; - - this.recordSourceMappingNameStart(accessor.propertyName.text()); - this.writeToOutput(accessor.propertyName.text()); - - this.emitParameterList(accessor.callSignature.parameterList); - - this.emitFunctionBodyStatements(null, accessor, accessor.callSignature.parameterList.parameters, accessor.block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(accessor); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(accessor); - - this.popDecl(pullDecl); - this.setContainer(temp); - this.recordSourceMappingEnd(accessor); - } - - public emitFunctionExpression(funcDecl: FunctionExpressionSyntax): void { - var savedInArrowFunction = this.inArrowFunction; - this.inArrowFunction = false; - - var temp = this.setContainer(EmitContainer.Function); - - var funcName = funcDecl.identifier ? funcDecl.identifier.text() : null;//.getNameText(); - - this.recordSourceMappingStart(funcDecl); - - var pullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - this.pushDecl(pullDecl); - - this.recordSourceMappingStart(funcDecl); - this.writeToken(funcDecl.functionKeyword); - this.writeToOutput(" "); - - //var id = funcDecl.getNameText(); - if (funcDecl.identifier) { - this.writeToOutputWithSourceMapRecord(funcDecl.identifier.text(), funcDecl.identifier); - } - - this.emitParameterList(funcDecl.callSignature.parameterList); - this.emitFunctionBodyStatements(funcName, funcDecl, funcDecl.callSignature.parameterList.parameters, funcDecl.block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(funcDecl); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(funcDecl); - - this.emitComments(funcDecl, false); - - this.popDecl(pullDecl); - - this.setContainer(temp); - this.inArrowFunction = savedInArrowFunction; - } - - public emitFunction(funcDecl: FunctionDeclarationSyntax) { - if (funcDecl.block === null) { - return; - } - var savedInArrowFunction = this.inArrowFunction; - this.inArrowFunction = false; - - var temp = this.setContainer(EmitContainer.Function); - - var funcName = funcDecl.identifier.text(); - - this.recordSourceMappingStart(funcDecl); - - var printName = funcDecl.identifier !== null - var pullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - this.pushDecl(pullDecl); - - this.emitComments(funcDecl, true); - - this.recordSourceMappingStart(funcDecl); - this.writeToken(funcDecl.functionKeyword); - this.writeToOutput(" "); - - if (printName) { - var id = funcDecl.identifier.text(); - if (id) { - if (funcDecl.identifier) { - this.recordSourceMappingStart(funcDecl.identifier); - } - this.writeToOutput(id); - if (funcDecl.identifier) { - this.recordSourceMappingEnd(funcDecl.identifier); - } - } - } - - this.emitParameterList(funcDecl.callSignature.parameterList); - - var parameters = funcDecl.callSignature.parameterList.parameters; - this.emitFunctionBodyStatements(funcDecl.identifier.text(), funcDecl, parameters, funcDecl.block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(funcDecl); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(funcDecl); - - this.emitComments(funcDecl, false); - - this.popDecl(pullDecl); - - this.setContainer(temp); - this.inArrowFunction = savedInArrowFunction; - - if (funcDecl.block) { - var pullFunctionDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - if ((this.emitState.container === EmitContainer.Module || this.emitState.container === EmitContainer.DynamicModule) && pullFunctionDecl && hasFlag(pullFunctionDecl.flags, PullElementFlags.Exported)) { - this.writeLineToOutput(""); - this.emitIndent(); - var modName = this.emitState.container === EmitContainer.Module ? this.moduleName : "exports"; - this.recordSourceMappingStart(funcDecl); - this.writeToOutput(modName + "." + funcName + " = " + funcName + ";"); - this.recordSourceMappingEnd(funcDecl); - } - } - } - - public emitAmbientVarDecl(varDecl: VariableDeclaratorSyntax) { - this.recordSourceMappingStart(this.currentVariableDeclaration); - if (varDecl.equalsValueClause) { - this.emitComments(varDecl, true); - this.recordSourceMappingStart(varDecl); - this.writeToOutputWithSourceMapRecord(varDecl.propertyName.text(), varDecl.propertyName); - this.emitJavascript(varDecl.equalsValueClause, false); - this.recordSourceMappingEnd(varDecl); - this.emitComments(varDecl, false); - } - } - - // Emits "var " if it is allowed - public emitVarDeclVar() { - if (this.currentVariableDeclaration) { - this.writeToOutput("var "); - } - } - - public emitVariableDeclaration(declaration: VariableDeclarationSyntax) { - var varDecl = declaration.variableDeclarators[0]; - - var symbol = this.semanticInfoChain.getSymbolForAST(varDecl); - - var parentSymbol = symbol ? symbol.getContainer() : null; - var parentKind = parentSymbol ? parentSymbol.kind : PullElementKind.None; - - this.emitComments(declaration, true); - - var pullVarDecl = this.semanticInfoChain.getDeclForAST(varDecl); - var isAmbientWithoutInit = pullVarDecl && hasFlag(pullVarDecl.flags, PullElementFlags.Ambient) && varDecl.equalsValueClause === null; - if (!isAmbientWithoutInit) { - var prevVariableDeclaration = this.currentVariableDeclaration; - this.currentVariableDeclaration = declaration; - - for (var i = 0, n = declaration.variableDeclarators.length; i < n; i++) { - var declarator = declaration.variableDeclarators[i]; - - if (i > 0) { - this.writeToOutput(", "); - } - - this.emit(declarator); - } - this.currentVariableDeclaration = prevVariableDeclaration; - - // Declarator emit would take care of emitting start of the variable declaration start - this.recordSourceMappingEnd(declaration); - } - - this.emitComments(declaration, false); - } - - private emitMemberVariableDeclaration(varDecl: MemberVariableDeclarationSyntax) { - Debug.assert(!hasModifier(varDecl.modifiers, PullElementFlags.Static) && varDecl.variableDeclarator.equalsValueClause); - - var pullDecl = this.semanticInfoChain.getDeclForAST(varDecl); - this.pushDecl(pullDecl); - - this.emitComments(varDecl, true); - this.recordSourceMappingStart(varDecl); - - var varDeclName = varDecl.variableDeclarator.propertyName.text(); - var quotedOrNumber = isQuoted(varDeclName) || varDecl.variableDeclarator.propertyName.kind() !== SyntaxKind.IdentifierName; - - var symbol = this.semanticInfoChain.getSymbolForAST(varDecl); - var parentSymbol = symbol ? symbol.getContainer() : null; - var parentDecl = pullDecl && pullDecl.getParentDecl(); - - if (quotedOrNumber) { - this.writeToOutput("this["); - } - else { - this.writeToOutput("this."); - } - - this.writeToOutputWithSourceMapRecord(varDecl.variableDeclarator.propertyName.text(), varDecl.variableDeclarator.propertyName); - - if (quotedOrNumber) { - this.writeToOutput("]"); - } - - if (varDecl.variableDeclarator.equalsValueClause) { - // Ensure we have a fresh var list count when recursing into the variable - // initializer. We don't want our current list of variables to affect how we - // emit nested variable lists. - var prevVariableDeclaration = this.currentVariableDeclaration; - this.emit(varDecl.variableDeclarator.equalsValueClause); - this.currentVariableDeclaration = prevVariableDeclaration; - } - - // class - if (this.emitState.container !== EmitContainer.Args) { - this.writeToOutput(";"); - } - - this.recordSourceMappingEnd(varDecl); - this.emitComments(varDecl, false); - - this.popDecl(pullDecl); - } - - public emitVariableDeclarator(varDecl: VariableDeclaratorSyntax) { - var pullDecl = this.semanticInfoChain.getDeclForAST(varDecl); - this.pushDecl(pullDecl); - if (pullDecl && (pullDecl.flags & PullElementFlags.Ambient) === PullElementFlags.Ambient) { - this.emitAmbientVarDecl(varDecl); - } - else { - this.emitComments(varDecl, true); - this.recordSourceMappingStart(this.currentVariableDeclaration); - this.recordSourceMappingStart(varDecl); - - var varDeclName = varDecl.propertyName.text(); - - var symbol = this.semanticInfoChain.getSymbolForAST(varDecl); - var parentSymbol = symbol ? symbol.getContainer() : null; - var parentDecl = pullDecl && pullDecl.getParentDecl(); - var parentIsModule = parentDecl && (parentDecl.flags & PullElementFlags.SomeInitializedModule); - - if (parentIsModule) { - // module - if (!hasFlag(pullDecl.flags, PullElementFlags.Exported)/* && !varDecl.isProperty() */) { - this.emitVarDeclVar(); - } - else { - if (this.emitState.container === EmitContainer.DynamicModule) { - this.writeToOutput("exports."); - } - else { - this.writeToOutput(this.moduleName + "."); - } - } - } - else { - this.emitVarDeclVar(); - } - - this.writeToOutputWithSourceMapRecord(varDecl.propertyName.text(), varDecl.propertyName); - - if (varDecl.equalsValueClause) { - // Ensure we have a fresh var list count when recursing into the variable - // initializer. We don't want our current list of variables to affect how we - // emit nested variable lists. - var prevVariableDeclaration = this.currentVariableDeclaration; - this.emit(varDecl.equalsValueClause); - this.currentVariableDeclaration = prevVariableDeclaration; - } - - this.recordSourceMappingEnd(varDecl); - this.emitComments(varDecl, false); - } - this.currentVariableDeclaration = undefined; - this.popDecl(pullDecl); - } - - private symbolIsUsedInItsEnclosingContainer(symbol: PullSymbol, dynamic = false) { - var symDecls = symbol.getDeclarations(); - - if (symDecls.length) { - var enclosingDecl = this.getEnclosingDecl(); - if (enclosingDecl) { - var parentDecl = symDecls[0].getParentDecl(); - if (parentDecl) { - var symbolDeclarationEnclosingContainer = parentDecl; - var enclosingContainer = enclosingDecl; - - // compute the closing container of the symbol's declaration - while (symbolDeclarationEnclosingContainer) { - if (symbolDeclarationEnclosingContainer.kind === (dynamic ? PullElementKind.DynamicModule : PullElementKind.Container)) { - break; - } - symbolDeclarationEnclosingContainer = symbolDeclarationEnclosingContainer.getParentDecl(); - } - - // if the symbol in question is not a global, compute the nearest - // enclosing declaration from the point of usage - if (symbolDeclarationEnclosingContainer) { - while (enclosingContainer) { - if (enclosingContainer.kind === (dynamic ? PullElementKind.DynamicModule : PullElementKind.Container)) { - break; - } - - enclosingContainer = enclosingContainer.getParentDecl(); - } - } - - if (symbolDeclarationEnclosingContainer && enclosingContainer) { - var same = symbolDeclarationEnclosingContainer === enclosingContainer; - - // initialized module object variables are bound to their parent's decls - if (!same && symbol.anyDeclHasFlag(PullElementFlags.InitializedModule)) { - same = symbolDeclarationEnclosingContainer === enclosingContainer.getParentDecl(); - } - - return same; - } - } - } - } - - return false; - } - - // In some cases, when emitting a name, the emitter needs to qualify a symbol - // name by first emitting its parent's name. This generally happens when the - // name referenced is in scope in TypeScript, but not in Javascript. This is true - // in any of the following 3 cases: - // - It is an enum member, even if accessed from within the enum declaration in which it is defined - // - It is an exported var, even if accessed from within the module declaration in which it is defined - // - It is an exported member of the current module, but is never defined in this particular module - // declaration (i.e. it is only defined in other components of the same merged module) - private shouldQualifySymbolNameWithParentName(symbol: PullSymbol): boolean { - var enclosingContextDeclPath = this.declStack; - var symbolDeclarations = symbol.getDeclarations(); - for (var i = 0; i < symbolDeclarations.length; i++) { - var currentDecl = symbolDeclarations[i]; - var declParent = currentDecl.getParentDecl(); - - if (currentDecl.kind === PullElementKind.EnumMember) { - return true; - } - - // All decls of the same symbol must agree on whether they are exported - // If one decl is not exported, none of them are, and it is safe to - // assume it is just a local - if (!hasFlag(currentDecl.flags, PullElementFlags.Exported)) { - return false; - } - - // Section 10.6: - // When a variable is exported, all references to the variable in the body of the - // module are replaced with - // .< VariableName> - if (currentDecl.kind === PullElementKind.Variable && !hasFlag(currentDecl.flags, PullElementFlags.ImplicitVariable)) { - return true; - } - - if (ArrayUtilities.contains(this.declStack, declParent)) { - return false; - } - } - - return true; - } - - // Get the symbol information to be used for emitting the ast - private getSymbolForEmit(ast: ISyntaxElement) { - var pullSymbol = this.semanticInfoChain.getSymbolForAST(ast); - var pullSymbolAlias = this.semanticInfoChain.getAliasSymbolForAST(ast); - if (pullSymbol && pullSymbolAlias) { - var symbolToCompare = isTypesOnlyLocation(ast) ? - pullSymbolAlias.getExportAssignedTypeSymbol() : - pullSymbolAlias.getExportAssignedValueSymbol(); - - if (pullSymbol === symbolToCompare) { - pullSymbol = pullSymbolAlias; - pullSymbolAlias = null; - } - } - return { symbol: pullSymbol, aliasSymbol: pullSymbolAlias }; - } - - public emitName(name: ISyntaxToken, addThis: boolean) { - this.emitComments(name, true); - this.recordSourceMappingStart(name); - if (name.text().length > 0) { - var symbolForEmit = this.getSymbolForEmit(name); - var pullSymbol = symbolForEmit.symbol; - if (!pullSymbol) { - pullSymbol = this.semanticInfoChain.anyTypeSymbol; - } - var pullSymbolAlias = symbolForEmit.aliasSymbol; - var pullSymbolKind = pullSymbol.kind; - var isLocalAlias = pullSymbolAlias && (pullSymbolAlias.getDeclarations()[0].getParentDecl() === this.getEnclosingDecl()); - if (addThis && (this.emitState.container !== EmitContainer.Args) && pullSymbol) { - var pullSymbolContainer = pullSymbol.getContainer(); - - if (pullSymbolContainer) { - var pullSymbolContainerKind = pullSymbolContainer.kind; - - if (PullHelpers.symbolIsModule(pullSymbolContainer) || pullSymbolContainerKind === PullElementKind.Enum || - pullSymbolContainer.anyDeclHasFlag(PullElementFlags.InitializedModule | PullElementFlags.Enum)) { - var needToEmitParentName = this.shouldQualifySymbolNameWithParentName(pullSymbol); - if (needToEmitParentName) { - var parentDecl = pullSymbol.getDeclarations()[0].getParentDecl(); - Debug.assert(parentDecl && !parentDecl.isRootDecl()); - this.writeToOutput(this.getModuleName(parentDecl, /* changeNameIfAnyDeclarationInContext */ true) + "."); - } - } - else if (pullSymbolContainerKind === PullElementKind.DynamicModule || - pullSymbolContainer.anyDeclHasFlag(PullElementFlags.InitializedDynamicModule)) { - if (pullSymbolKind === PullElementKind.Property) { - // If dynamic module - this.writeToOutput("exports."); - } - else if (pullSymbol.anyDeclHasFlag(PullElementFlags.Exported) && - !isLocalAlias && - !pullSymbol.anyDeclHasFlag(PullElementFlags.ImplicitVariable) && - pullSymbol.kind !== PullElementKind.ConstructorMethod && - pullSymbol.kind !== PullElementKind.Class && - pullSymbol.kind !== PullElementKind.Enum) { - this.writeToOutput("exports."); - } - } - } - } - - this.writeToOutput(name.text()); - } - - this.recordSourceMappingEnd(name); - this.emitComments(name, false); - } - - public recordSourceMappingNameStart(name: string) { - if (this.sourceMapper) { - var nameIndex = -1; - if (name) { - if (this.sourceMapper.currentNameIndex.length > 0) { - var parentNameIndex = this.sourceMapper.currentNameIndex[this.sourceMapper.currentNameIndex.length - 1]; - if (parentNameIndex !== -1) { - name = this.sourceMapper.names[parentNameIndex] + "." + name; - } - } - - // Look if there already exists name - var nameIndex = this.sourceMapper.names.length - 1; - for (nameIndex; nameIndex >= 0; nameIndex--) { - if (this.sourceMapper.names[nameIndex] === name) { - break; - } - } - - if (nameIndex === -1) { - nameIndex = this.sourceMapper.names.length; - this.sourceMapper.names.push(name); - } - } - this.sourceMapper.currentNameIndex.push(nameIndex); - } - } - - public recordSourceMappingNameEnd() { - if (this.sourceMapper) { - this.sourceMapper.currentNameIndex.pop(); - } - } - - private recordSourceMappingStart(ast: ISyntaxElement) { - if (this.sourceMapper && ASTHelpers.isValidAstNode(ast)) { - var text = this.text(); - this.recordSourceMappingSpanStart(ast, start(ast, text), end(ast, text)); - } - } - - private recordSourceMappingCommentStart(comment: Comment) { - this.recordSourceMappingSpanStart(comment, comment.start(), comment.end()); - } - - private recordSourceMappingSpanStart(ast: any, start: number, end: number) { - if (this.sourceMapper && ast && start !== -1 && end !== -1) { - var lineCol = { line: -1, character: -1 }; - var sourceMapping = new SourceMapping(); - sourceMapping.start.emittedColumn = this.emitState.column; - sourceMapping.start.emittedLine = this.emitState.line; - // REVIEW: check time consumed by this binary search (about two per leaf statement) - var lineMap = this.document.lineMap(); - lineMap.fillLineAndCharacterFromPosition(start, lineCol); - sourceMapping.start.sourceColumn = lineCol.character; - sourceMapping.start.sourceLine = lineCol.line + 1; - lineMap.fillLineAndCharacterFromPosition(end, lineCol); - sourceMapping.end.sourceColumn = lineCol.character; - sourceMapping.end.sourceLine = lineCol.line + 1; - - Debug.assert(!isNaN(sourceMapping.start.emittedColumn)); - Debug.assert(!isNaN(sourceMapping.start.emittedLine)); - Debug.assert(!isNaN(sourceMapping.start.sourceColumn)); - Debug.assert(!isNaN(sourceMapping.start.sourceLine)); - Debug.assert(!isNaN(sourceMapping.end.sourceColumn)); - Debug.assert(!isNaN(sourceMapping.end.sourceLine)); - - if (this.sourceMapper.currentNameIndex.length > 0) { - sourceMapping.nameIndex = this.sourceMapper.currentNameIndex[this.sourceMapper.currentNameIndex.length - 1]; - } - // Set parent and child relationship - var siblings = this.sourceMapper.currentMappings[this.sourceMapper.currentMappings.length - 1]; - siblings.push(sourceMapping); - this.sourceMapper.currentMappings.push(sourceMapping.childMappings); - this.sourceMapper.increaseMappingLevel(ast); - } - } - - private recordSourceMappingEnd(ast: ISyntaxElement) { - if (this.sourceMapper && ASTHelpers.isValidAstNode(ast)) { - var text = this.text(); - this.recordSourceMappingSpanEnd(ast, start(ast, text), end(ast, text)); - } - } - - private recordSourceMappingCommentEnd(ast: Comment) { - if (this.sourceMapper && ASTHelpers.isValidSpan(ast)) { - this.recordSourceMappingSpanEnd(ast, ast.start(), ast.end()); - } - } - - private recordSourceMappingSpanEnd(ast: any, start: number, end: number) { - if (this.sourceMapper && ast && start !== -1 && end !== -1) { - // Pop source mapping childs - this.sourceMapper.currentMappings.pop(); - - // Get the last source mapping from sibling list = which is the one we are recording end for - var siblings = this.sourceMapper.currentMappings[this.sourceMapper.currentMappings.length - 1]; - var sourceMapping = siblings[siblings.length - 1]; - - sourceMapping.end.emittedColumn = this.emitState.column; - sourceMapping.end.emittedLine = this.emitState.line; - - Debug.assert(!isNaN(sourceMapping.end.emittedColumn)); - Debug.assert(!isNaN(sourceMapping.end.emittedLine)); - - this.sourceMapper.decreaseMappingLevel(ast); - } - } - - // Note: may throw exception. - public getOutputFiles(): OutputFile[] { - // Output a source mapping. As long as we haven't gotten any errors yet. - var result: OutputFile[] = []; - if (this.sourceMapper !== null) { - this.sourceMapper.emitSourceMapping(); - result.push(this.sourceMapper.getOutputFile()); - } - - result.push(this.outfile.getOutputFile()); - return result; - } - - private emitParameterPropertyAndMemberVariableAssignments(): void { - // emit any parameter properties first - var constructorDecl = getLastConstructor(this.thisClassNode); - - if (constructorDecl) { - for (var i = 0, n = constructorDecl.callSignature.parameterList.parameters.length; i < n; i++) { - var parameter = constructorDecl.callSignature.parameterList.parameters[i]; - - var parameterDecl = this.semanticInfoChain.getDeclForAST(parameter); - if (hasFlag(parameterDecl.flags, PullElementFlags.PropertyParameter)) { - this.emitIndent(); - this.recordSourceMappingStart(parameter); - this.writeToOutputWithSourceMapRecord("this." + parameter.identifier.text(), parameter.identifier); - this.writeToOutput(" = "); - this.writeToOutputWithSourceMapRecord(parameter.identifier.text(), parameter.identifier); - this.writeLineToOutput(";"); - this.recordSourceMappingEnd(parameter); - } - } - } - - for (var i = 0, n = this.thisClassNode.classElements.length; i < n; i++) { - if (this.thisClassNode.classElements[i].kind() === SyntaxKind.MemberVariableDeclaration) { - var varDecl = this.thisClassNode.classElements[i]; - if (!hasModifier(varDecl.modifiers, PullElementFlags.Static) && varDecl.variableDeclarator.equalsValueClause) { - this.emitIndent(); - this.emitMemberVariableDeclaration(varDecl); - this.writeLineToOutput(""); - } - } - } - } - - private isOnSameLine(pos1: number, pos2: number): boolean { - if (pos1 < 0 || pos2 < 0) { - // Missing element. Assume it's on the same line as the other element. - return true; - } - - var lineMap = this.document.lineMap(); - return lineMap.getLineNumberFromPosition(pos1) === lineMap.getLineNumberFromPosition(pos2); - } - - private emitCommaSeparatedList(parent: ISyntaxElement, list: T[], buffer: string, preserveNewLines: boolean): void { - if (list === null || list.length === 0) { - return; - } - - // If the first element isn't on hte same line as the parent node, then we need to - // start with a newline. - var text = this.text(); - var startLine = preserveNewLines && !this.isOnSameLine(end(parent, text), end(list[0], text)); - - if (preserveNewLines) { - // Any elements on a new line will have to be indented. - this.indenter.increaseIndent(); - } - - // If we're starting on a newline, then emit an actual newline. Otherwise write out - // the buffer character before hte first element. - if (startLine) { - this.writeLineToOutput(""); - } - else { - this.writeToOutput(buffer); - } - - for (var i = 0, n = list.length; i < n; i++) { - var emitNode = list[i]; - - // Write out the element, emitting an indent if we're on a new line. - this.emitJavascript(emitNode, startLine); - - if (i < (n - 1)) { - // If the next element start on a different line than this element ended on, - // then we want to start on a newline. Emit the comma with a newline. - // Otherwise, emit the comma with the space. - startLine = preserveNewLines && !this.isOnSameLine(end(emitNode, text), start(list[i + 1], text)); - if (startLine) { - this.writeLineToOutput(","); - } - else { - this.writeToOutput(", "); - } - } - } - - if (preserveNewLines) { - // We're done with all the elements. Return the indent back to where it was. - this.indenter.decreaseIndent(); - } - - // If the last element isn't on the same line as the parent, then emit a newline - // after the last element and emit our indent so the list's terminator will be - // on the right line. Otherwise, emit the buffer string between the last value - // and the terminator. - if (preserveNewLines && !this.isOnSameLine(end(parent, text), end(list[list.length - 1], text))) { - this.writeLineToOutput(""); - this.emitIndent(); - } - else { - this.writeToOutput(buffer); - } - } - - public emitList(list: T[], useNewLineSeparator = true, startInclusive = 0, endExclusive = list.length) { - if (list === null) { - return; - } - - this.emitComments(list, true); - var lastEmittedNode: ISyntaxElement = null; - - for (var i = startInclusive; i < endExclusive; i++) { - var node = list[i]; - - if (this.shouldEmit(node)) { - this.emitSpaceBetweenConstructs(lastEmittedNode, node); - - this.emitJavascript(node, true); - if (useNewLineSeparator) { - this.writeLineToOutput(""); - } - - lastEmittedNode = node; - } - } - - this.emitComments(list, false); - } - - public emitSeparatedList(list: T[], useNewLineSeparator = true, startInclusive = 0, endExclusive = list.length) { - if (list === null) { - return; - } - - this.emitComments(list, true); - var lastEmittedNode: ISyntaxElement = null; - - for (var i = startInclusive; i < endExclusive; i++) { - var node = list[i]; - - if (this.shouldEmit(node)) { - this.emitSpaceBetweenConstructs(lastEmittedNode, node); - - this.emitJavascript(node, true); - if (useNewLineSeparator) { - this.writeLineToOutput(""); - } - - lastEmittedNode = node; - } - } - - this.emitComments(list, false); - } - - private isDirectivePrologueElement(node: ISyntaxElement) { - if (node.kind() === SyntaxKind.ExpressionStatement) { - var exprStatement = node; - return exprStatement.expression.kind() === SyntaxKind.StringLiteral; - } - - return false; - } - - // If these two constructs had more than one line between them originally, then emit at - // least one blank line between them. - public emitSpaceBetweenConstructs(node1: ISyntaxElement, node2: ISyntaxElement): void { - if (node1 === null || node2 === null) { - return; - } - - var text = this.text(); - if (start(node1, text) === -1 || end(node1, text) === -1 || start(node2, text) === -1 || end(node2, text) === -1) { - return; - } - - var lineMap = this.document.lineMap(); - var node1EndLine = lineMap.getLineNumberFromPosition(end(node1, text)); - var node2StartLine = lineMap.getLineNumberFromPosition(start(node2, text)); - - if ((node2StartLine - node1EndLine) > 1) { - this.writeLineToOutput("", /*force:*/ true); - } - } - - // We consider a sequence of comments to be a detached from an ast if there are no blank lines - // between them, and there is a blank line after the last one and the node they're attached - // to. - private getDetachedComments(element: ISyntaxElement): Comment[] { - var text = this.text(); - var preComments = TypeScript.ASTHelpers.preComments(element, text); - if (preComments) { - var lineMap = this.document.lineMap(); - - var detachedComments: Comment[] = []; - var lastComment: Comment = null; - - for (var i = 0, n = preComments.length; i < n; i++) { - var comment = preComments[i]; - - if (lastComment) { - var lastCommentLine = lineMap.getLineNumberFromPosition(lastComment.end()); - var commentLine = lineMap.getLineNumberFromPosition(comment.start()); - - if (commentLine >= lastCommentLine + 2) { - // There was a blank line between the last comment and this comment. This - // comment is not part of the copyright comments. Return what we have so - // far. - return detachedComments; - } - } - - detachedComments.push(comment); - lastComment = comment; - } - - // All comments look like they could have been part of the copyright header. Make - // sure there is at least one blank line between it and the node. If not, it's not - // a copyright header. - var lastCommentLine = lineMap.getLineNumberFromPosition(ArrayUtilities.last(detachedComments).end()); - var astLine = lineMap.getLineNumberFromPosition(start(element, text)); - if (astLine >= lastCommentLine + 2) { - return detachedComments; - } - } - - // No usable copyright comments found. - return []; - } - - private emitPossibleCopyrightHeaders(script: SourceUnitSyntax): void { - this.emitDetachedComments(script.moduleElements); - } - - private emitDetachedComments(list: ISyntaxNodeOrToken[]): void { - if (list.length > 0) { - var firstElement = childAt(list, 0); - - this.detachedCommentsElement = firstElement; - this.emitCommentsArray(this.getDetachedComments(this.detachedCommentsElement), /*trailing:*/ false); - } - } - - public emitScriptElements(sourceUnit: SourceUnitSyntax) { - var list = sourceUnit.moduleElements; - - this.emitPossibleCopyrightHeaders(sourceUnit); - - // First, emit all the prologue elements. - for (var i = 0, n = list.length; i < n; i++) { - var node = list[i]; - - if (!this.isDirectivePrologueElement(node)) { - break; - } - - this.emitJavascript(node, true); - this.writeLineToOutput(""); - } - - // Now emit __extends or a _this capture if necessary. - this.emitPrologue(sourceUnit); - - var isExternalModule = this.document.syntaxTree().isExternalModule(); - var isNonElidedExternalModule = isExternalModule && !ASTHelpers.scriptIsElided(sourceUnit); - if (isNonElidedExternalModule) { - this.recordSourceMappingStart(sourceUnit); - - if (this.emitOptions.compilationSettings().moduleGenTarget() === ModuleGenTarget.Asynchronous) { // AMD - var dependencyList = "[\"require\", \"exports\""; - var importList = "require, exports"; - - var importAndDependencyList = this.getModuleImportAndDependencyList(sourceUnit); - importList += importAndDependencyList.importList; - dependencyList += importAndDependencyList.dependencyList + "]"; - - this.writeLineToOutput("define(" + dependencyList + "," + " function(" + importList + ") {"); - } - } - - if (isExternalModule) { - var temp = this.setContainer(EmitContainer.DynamicModule); - - var svModuleName = this.moduleName; - this.moduleName = syntaxTree(sourceUnit).fileName(); - if (TypeScript.isTSFile(this.moduleName)) { - this.moduleName = this.moduleName.substring(0, this.moduleName.length - ".ts".length); - } - - // if the external module has an "export =" identifier, we'll - // set it in the ExportAssignment emit method - this.setExportAssignment(null); - - if(this.emitOptions.compilationSettings().moduleGenTarget() === ModuleGenTarget.Asynchronous) { - this.indenter.increaseIndent(); - } - - var externalModule = this.semanticInfoChain.getDeclForAST(this.document.sourceUnit()); - - if (hasFlag(externalModule.flags, PullElementFlags.MustCaptureThis)) { - this.writeCaptureThisStatement(sourceUnit); - } - - this.pushDecl(externalModule); - } - - this.emitList(list, /*useNewLineSeparator:*/ true, /*startInclusive:*/ i, /*endExclusive:*/ n); - - if (isExternalModule) { - if (this.emitOptions.compilationSettings().moduleGenTarget() === ModuleGenTarget.Asynchronous) { - this.indenter.decreaseIndent(); - } - - if (isNonElidedExternalModule) { - var exportAssignment = this.getExportAssignment(); - var exportAssignmentIdentifierText = exportAssignment ? exportAssignment.identifier.text() : null; - var exportAssignmentValueSymbol = (externalModule.getSymbol(this.semanticInfoChain)).getExportAssignedValueSymbol(); - - if (this.emitOptions.compilationSettings().moduleGenTarget() === ModuleGenTarget.Asynchronous) { // AMD - if (exportAssignmentIdentifierText && exportAssignmentValueSymbol && !(exportAssignmentValueSymbol.kind & PullElementKind.SomeTypeReference)) { - // indent was decreased for AMD above - this.indenter.increaseIndent(); - this.emitIndent(); - this.writeToOutputWithSourceMapRecord("return " + exportAssignmentIdentifierText, exportAssignment); - this.writeLineToOutput(";"); - this.indenter.decreaseIndent(); - } - this.writeToOutput("});"); - } - else if (exportAssignmentIdentifierText && exportAssignmentValueSymbol && !(exportAssignmentValueSymbol.kind & PullElementKind.SomeTypeReference)) { - this.emitIndent(); - this.writeToOutputWithSourceMapRecord("module.exports = " + exportAssignmentIdentifierText, exportAssignment); - this.writeToOutput(";"); - } - - this.recordSourceMappingEnd(sourceUnit); - this.writeLineToOutput(""); - } - - this.setContainer(temp); - this.moduleName = svModuleName; - this.popDecl(externalModule); - } - } - - public emitConstructorStatements(funcDecl: ConstructorDeclarationSyntax) { - var list = funcDecl.block.statements; - - if (list === null) { - return; - } - - this.emitComments(list, true); - - var emitPropertyAssignmentsAfterSuperCall = ASTHelpers.getExtendsHeritageClause(this.thisClassNode.heritageClauses) !== null; - var propertyAssignmentIndex = emitPropertyAssignmentsAfterSuperCall ? 1 : 0; - var lastEmittedNode: ISyntaxElement = null; - - for (var i = 0, n = list.length; i < n; i++) { - // In some circumstances, class property initializers must be emitted immediately after the 'super' constructor - // call which, in these cases, must be the first statement in the constructor body - if (i === propertyAssignmentIndex) { - this.emitParameterPropertyAndMemberVariableAssignments(); - } - - var node = list[i]; - - if (this.shouldEmit(node)) { - this.emitSpaceBetweenConstructs(lastEmittedNode, node); - - this.emitJavascript(node, true); - this.writeLineToOutput(""); - - lastEmittedNode = node; - } - } - - if (i === propertyAssignmentIndex) { - this.emitParameterPropertyAndMemberVariableAssignments(); - } - - this.emitComments(list, false); - } - - // tokenId is the id the preceding token - public emitJavascript(ast: ISyntaxElement, startLine: boolean) { - if (ast === null) { - return; - } - - if (startLine && - this.indenter.indentAmt > 0) { - - this.emitIndent(); - } - - this.emit(ast); - } - - public emitAccessorMemberDeclaration(funcDecl: ISyntaxElement, name: ISyntaxToken, className: string, isProto: boolean) { - if (funcDecl.kind() !== SyntaxKind.GetAccessor) { - var accessorSymbol = PullHelpers.getAccessorSymbol(funcDecl, this.semanticInfoChain); - if (accessorSymbol.getGetter()) { - return; - } - } - - this.emitIndent(); - this.recordSourceMappingStart(funcDecl); - - this.writeToOutput("Object.defineProperty(" + className); - if (isProto) { - this.writeToOutput(".prototype, "); - } - else { - this.writeToOutput(", "); - } - - var functionName = name.text(); - if (isQuoted(functionName)) { - this.writeToOutput(functionName); - } - else { - this.writeToOutput('"' + functionName + '"'); - } - - this.writeLineToOutput(", {"); - - this.indenter.increaseIndent(); - - var accessors = PullHelpers.getGetterAndSetterFunction(funcDecl, this.semanticInfoChain); - if (accessors.getter) { - this.emitIndent(); - this.recordSourceMappingStart(accessors.getter); - this.emitComments(accessors.getter, true); - this.writeToOutput("get: "); - this.emitAccessorBody(accessors.getter, accessors.getter.callSignature.parameterList, accessors.getter.block); - this.writeLineToOutput(","); - } - - if (accessors.setter) { - this.emitIndent(); - this.recordSourceMappingStart(accessors.setter); - this.emitComments(accessors.setter, true); - this.writeToOutput("set: "); - this.emitAccessorBody(accessors.setter, accessors.setter.callSignature.parameterList, accessors.setter.block); - this.writeLineToOutput(","); - } - - this.emitIndent(); - this.writeLineToOutput("enumerable: true,"); - this.emitIndent(); - this.writeLineToOutput("configurable: true"); - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeLineToOutput("});"); - this.recordSourceMappingEnd(funcDecl); - } - - private emitAccessorBody(funcDecl: ISyntaxElement, parameterList: ParameterListSyntax, block: BlockSyntax): void { - var pullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - this.pushDecl(pullDecl); - - this.recordSourceMappingStart(funcDecl); - this.writeToOutput("function "); - this.emitParameterList(parameterList); - - var parameters = parameterList.parameters; - this.emitFunctionBodyStatements(null, funcDecl, parameters, block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(funcDecl); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(funcDecl); - this.popDecl(pullDecl); - } - - public emitClass(classDecl: ClassDeclarationSyntax) { - var pullDecl = this.semanticInfoChain.getDeclForAST(classDecl); - this.pushDecl(pullDecl); - - var svClassNode = this.thisClassNode; - this.thisClassNode = classDecl; - var className = classDecl.identifier.text(); - this.emitComments(classDecl, true); - var temp = this.setContainer(EmitContainer.Class); - - this.recordSourceMappingStart(classDecl); - this.writeToOutput("var " + className); - - var hasBaseClass = ASTHelpers.getExtendsHeritageClause(classDecl.heritageClauses) !== null; - var baseTypeReference: ISyntaxElement = null; - var varDecl: VariableDeclaratorSyntax = null; - - if (hasBaseClass) { - this.writeLineToOutput(" = (function (_super) {"); - } - else { - this.writeLineToOutput(" = (function () {"); - } - - this.recordSourceMappingNameStart(className); - this.indenter.increaseIndent(); - - if (hasBaseClass) { - baseTypeReference = ASTHelpers.getExtendsHeritageClause(classDecl.heritageClauses).typeNames[0]; - this.emitIndent(); - this.writeToOutputWithSourceMapRecord("__extends(" + className + ", _super)", baseTypeReference); - this.writeLineToOutput(";"); - } - - this.emitIndent(); - - var constrDecl = getLastConstructor(classDecl); - - // output constructor - if (constrDecl) { - // declared constructor - this.emit(constrDecl); - this.writeLineToOutput(""); - } - else { - this.recordSourceMappingStart(classDecl); - // default constructor - this.indenter.increaseIndent(); - this.writeLineToOutput("function " + classDecl.identifier.text() + "() {"); - this.recordSourceMappingNameStart("constructor"); - if (hasBaseClass) { - this.emitIndent(); - this.writeToOutputWithSourceMapRecord("_super.apply(this, arguments)", baseTypeReference); - this.writeLineToOutput(";"); - } - - if (this.shouldCaptureThis(classDecl)) { - this.writeCaptureThisStatement(classDecl); - } - - this.emitParameterPropertyAndMemberVariableAssignments(); - - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeToken(classDecl.closeBraceToken); - this.writeLineToOutput(""); - - this.recordSourceMappingNameEnd(); - this.recordSourceMappingEnd(classDecl); - } - - this.emitClassMembers(classDecl); - - this.emitIndent(); - this.writeToOutputWithSourceMapRecord("return " + className + ";", classDecl.closeBraceToken); - this.writeLineToOutput(""); - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeToken(classDecl.closeBraceToken); - this.recordSourceMappingNameEnd(); - this.recordSourceMappingStart(classDecl); - this.writeToOutput(")("); - if (hasBaseClass) { - this.emitJavascript(baseTypeReference, /*startLine:*/ false); - } - this.writeToOutput(");"); - this.recordSourceMappingEnd(classDecl); - - if ((temp === EmitContainer.Module || temp === EmitContainer.DynamicModule) && hasFlag(pullDecl.flags, PullElementFlags.Exported)) { - this.writeLineToOutput(""); - this.emitIndent(); - var modName = temp === EmitContainer.Module ? this.moduleName : "exports"; - this.writeToOutputWithSourceMapRecord(modName + "." + className + " = " + className + ";", classDecl); - } - - this.recordSourceMappingEnd(classDecl); - this.emitComments(classDecl, false); - this.setContainer(temp); - this.thisClassNode = svClassNode; - - this.popDecl(pullDecl); - } - - private emitClassMembers(classDecl: ClassDeclarationSyntax): void { - // First, emit all the functions. - var lastEmittedMember: ISyntaxElement = null; - - for (var i = 0, n = classDecl.classElements.length; i < n; i++) { - var memberDecl = classDecl.classElements[i]; - - if (memberDecl.kind() === SyntaxKind.GetAccessor) { - this.emitSpaceBetweenConstructs(lastEmittedMember, memberDecl); - var getter = memberDecl; - this.emitAccessorMemberDeclaration(getter, getter.propertyName, classDecl.identifier.text(), - !hasModifier(getter.modifiers, PullElementFlags.Static)); - lastEmittedMember = memberDecl; - } - else if (memberDecl.kind() === SyntaxKind.SetAccessor) { - this.emitSpaceBetweenConstructs(lastEmittedMember, memberDecl); - var setter = memberDecl; - this.emitAccessorMemberDeclaration(setter, setter.propertyName, classDecl.identifier.text(), - !hasModifier(setter.modifiers, PullElementFlags.Static)); - lastEmittedMember = memberDecl; - } - else if (memberDecl.kind() === SyntaxKind.MemberFunctionDeclaration) { - - var memberFunction = memberDecl; - - if (memberFunction.block) { - this.emitSpaceBetweenConstructs(lastEmittedMember, memberDecl); - - this.emitClassMemberFunctionDeclaration(classDecl, memberFunction); - lastEmittedMember = memberDecl; - } - } - } - - // Now emit all the statics. - for (var i = 0, n = classDecl.classElements.length; i < n; i++) { - var memberDecl = classDecl.classElements[i]; - - if (memberDecl.kind() === SyntaxKind.MemberVariableDeclaration) { - var varDecl = memberDecl; - - if (hasModifier(varDecl.modifiers, PullElementFlags.Static) && varDecl.variableDeclarator.equalsValueClause) { - this.emitSpaceBetweenConstructs(lastEmittedMember, varDecl); - - this.emitIndent(); - this.recordSourceMappingStart(varDecl); - - this.emitComments(varDecl, true); - var varDeclName = varDecl.variableDeclarator.propertyName.text(); - if (isQuoted(varDeclName) || varDecl.variableDeclarator.propertyName.kind() !== SyntaxKind.IdentifierName) { - this.writeToOutput(classDecl.identifier.text() + "[" + varDeclName + "]"); - } - else { - this.writeToOutput(classDecl.identifier.text() + "." + varDeclName); - } - - this.emit(varDecl.variableDeclarator.equalsValueClause); - - this.recordSourceMappingEnd(varDecl); - this.writeLineToOutput(";"); - - lastEmittedMember = varDecl; - } - } - } - } - - private emitClassMemberFunctionDeclaration(classDecl: ClassDeclarationSyntax, funcDecl: MemberFunctionDeclarationSyntax): void { - this.emitIndent(); - this.recordSourceMappingStart(funcDecl); - this.emitComments(funcDecl, true); - var functionName = funcDecl.propertyName.text(); - - this.writeToOutput(classDecl.identifier.text()); - - if (!hasModifier(funcDecl.modifiers, PullElementFlags.Static)) { - this.writeToOutput(".prototype"); - } - - if (isQuoted(functionName) || funcDecl.propertyName.kind() !== SyntaxKind.IdentifierName) { - this.writeToOutput("[" + functionName + "] = "); - } - else { - this.writeToOutput("." + functionName + " = "); - } - - var pullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - this.pushDecl(pullDecl); - - this.recordSourceMappingStart(funcDecl); - this.writeToOutput("function "); - - this.emitParameterList(funcDecl.callSignature.parameterList); - - var parameters = funcDecl.callSignature.parameterList.parameters; - this.emitFunctionBodyStatements(funcDecl.propertyName.text(), funcDecl, parameters, funcDecl.block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(funcDecl); - - this.emitComments(funcDecl, false); - - this.recordSourceMappingEnd(funcDecl); - this.popDecl(pullDecl); - - this.writeLineToOutput(";"); - } - - private requiresExtendsBlock(moduleElements: IModuleElementSyntax[]): boolean { - for (var i = 0, n = moduleElements.length; i < n; i++) { - var moduleElement = moduleElements[i]; - - if (moduleElement.kind() === SyntaxKind.ModuleDeclaration) { - var moduleAST = moduleElement; - - if (!hasModifier(moduleAST.modifiers, PullElementFlags.Ambient) && this.requiresExtendsBlock(moduleAST.moduleElements)) { - return true; - } - } - else if (moduleElement.kind() === SyntaxKind.ClassDeclaration) { - var classDeclaration = moduleElement; - - if (!hasModifier(classDeclaration.modifiers, PullElementFlags.Ambient) && ASTHelpers.getExtendsHeritageClause(classDeclaration.heritageClauses) !== null) { - return true; - } - } - } - - return false; - } - - public emitPrologue(sourceUnit: SourceUnitSyntax) { - if (!this.extendsPrologueEmitted) { - if (this.requiresExtendsBlock(sourceUnit.moduleElements)) { - this.extendsPrologueEmitted = true; - this.writeLineToOutput("var __extends = this.__extends || function (d, b) {"); - this.writeLineToOutput(" for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); - this.writeLineToOutput(" function __() { this.constructor = d; }"); - this.writeLineToOutput(" __.prototype = b.prototype;"); - this.writeLineToOutput(" d.prototype = new __();"); - this.writeLineToOutput("};"); - } - } - - if (!this.globalThisCapturePrologueEmitted) { - if (this.shouldCaptureThis(sourceUnit)) { - this.globalThisCapturePrologueEmitted = true; - this.writeLineToOutput(this.captureThisStmtString); - } - } - } - - public emitThis() { - if (!this.inWithBlock && this.inArrowFunction) { - this.writeToOutput("_this"); - } - else { - this.writeToOutput("this"); - } - } - - public emitBlockOrStatement(node: ISyntaxElement): void { - if (node.kind() === SyntaxKind.Block) { - this.emit(node); - } - else { - this.writeLineToOutput(""); - this.indenter.increaseIndent(); - this.emitJavascript(node, true); - this.indenter.decreaseIndent(); - } - } - - public emitLiteralExpression(expression: ISyntaxToken): void { - switch (expression.kind()) { - case SyntaxKind.NullKeyword: - this.writeToken(expression); - break; - case SyntaxKind.FalseKeyword: - this.writeToken(expression); - break; - case SyntaxKind.TrueKeyword: - this.writeToken(expression); - break; - default: - throw Errors.abstract(); - } - } - - public emitThisExpression(expression: ISyntaxToken): void { - if (!this.inWithBlock && this.inArrowFunction) { - this.writeToOutputWithSourceMapRecord("_this", expression); - } - else { - this.writeToken(expression); - } - } - - public emitSuperExpression(expression: ISyntaxToken): void { - if (PullHelpers.isInStaticMemberContext(expression, this.semanticInfoChain)) { - this.writeToOutputWithSourceMapRecord("_super", expression); - } - else { - this.writeToOutputWithSourceMapRecord("_super.prototype", expression); - } - } - - private hasTrailingComment(token: ISyntaxToken) { - return token.hasTrailingTrivia() && token.trailingTrivia().hasComment(); - } - - public emitParenthesizedExpression(parenthesizedExpression: ParenthesizedExpressionSyntax): void { - var omitParentheses = false; - - if (parenthesizedExpression.expression.kind() === SyntaxKind.CastExpression && !this.hasTrailingComment(parenthesizedExpression.openParenToken)) { - var castedExpression = (parenthesizedExpression.expression).expression; - - // Make sure we consider all nested cast expressions, e.g.: - // (-A).x; - while (castedExpression.kind() == SyntaxKind.CastExpression) { - castedExpression = (castedExpression).expression; - } - - // We have an expression of the form: (SubExpr) - // Emitting this as (SubExpr) is really not desirable. Just emit the subexpr as is. - // We cannot generalize this rule however, as omitting the parentheses could cause change in the semantics of the generated - // code if the casted expression has a lower precedence than the rest of the expression, e.g.: - // (new A).foo should be emitted as (new A).foo and not new A.foo - // (typeof A).toString() should be emitted as (typeof A).toString() and not typeof A.toString() - // (function foo() { })() should be emitted as an IIF (function foo(){})() and not declaration function foo(){} () - // Parenthesis can be safelly removed from: - // Literals - // MemberAccessExpressions - // ElementAccessExpressions - // InvocationExpression, only if they are not part of an object creation (new) expression; e.g.: - // new (A()) removing the parentheses would result in calling A as a constructor, instead of calling the - // result of the function invocation A() as a constructor - switch (castedExpression.kind()) { - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.IdentifierName: - case SyntaxKind.NullKeyword: - case SyntaxKind.ThisKeyword: - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - case SyntaxKind.RegularExpressionLiteral: - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.MemberAccessExpression: - case SyntaxKind.ElementAccessExpression: - omitParentheses = true; - break; - - case SyntaxKind.InvocationExpression: - if (parenthesizedExpression.parent.kind() !== SyntaxKind.ObjectCreationExpression) { - omitParentheses = true; - } - - break; - } - } - - if (omitParentheses) { - this.emit(parenthesizedExpression.expression); - } - else { - this.recordSourceMappingStart(parenthesizedExpression); - this.writeToken(parenthesizedExpression.openParenToken); - this.emitCommentsArray(ASTHelpers.convertTokenTrailingComments(parenthesizedExpression.openParenToken, this.text()), /*trailing:*/ false); - this.emit(parenthesizedExpression.expression); - this.writeToken(parenthesizedExpression.closeParenToken); - this.recordSourceMappingEnd(parenthesizedExpression); - } - } - - public emitCastExpression(expression: CastExpressionSyntax): void { - this.emit(expression.expression); - } - - public emitPrefixUnaryExpression(expression: PrefixUnaryExpressionSyntax): void { - var nodeType = expression.kind(); - - this.recordSourceMappingStart(expression); - switch (nodeType) { - case SyntaxKind.LogicalNotExpression: - this.writeToken(expression.operatorToken); - this.emit(expression.operand); - break; - case SyntaxKind.BitwiseNotExpression: - this.writeToken(expression.operatorToken); - this.emit(expression.operand); - break; - case SyntaxKind.NegateExpression: - this.writeToken(expression.operatorToken); - if (expression.operand.kind() === SyntaxKind.NegateExpression || expression.operand.kind() === SyntaxKind.PreDecrementExpression) { - this.writeToOutput(" "); - } - this.emit(expression.operand); - break; - case SyntaxKind.PlusExpression: - this.writeToken(expression.operatorToken); - if (expression.operand.kind() === SyntaxKind.PlusExpression || expression.operand.kind() === SyntaxKind.PreIncrementExpression) { - this.writeToOutput(" "); - } - this.emit(expression.operand); - break; - case SyntaxKind.PreIncrementExpression: - this.writeToOutputWithSourceMapRecord("++", expression.operatorToken); - this.emit(expression.operand); - break; - case SyntaxKind.PreDecrementExpression: - this.writeToOutputWithSourceMapRecord("--", expression.operatorToken); - this.emit(expression.operand); - break; - default: - throw Errors.abstract(); - } - - this.recordSourceMappingEnd(expression); - } - - public emitPostfixUnaryExpression(expression: PostfixUnaryExpressionSyntax): void { - var nodeType = expression.kind(); - - this.recordSourceMappingStart(expression); - switch (nodeType) { - case SyntaxKind.PostIncrementExpression: - this.emit(expression.operand); - this.writeToOutputWithSourceMapRecord("++", expression.operatorToken); - break; - case SyntaxKind.PostDecrementExpression: - this.emit(expression.operand); - this.writeToOutputWithSourceMapRecord("--", expression.operatorToken); - break; - default: - throw Errors.abstract(); - } - - this.recordSourceMappingEnd(expression); - } - - public emitTypeOfExpression(expression: TypeOfExpressionSyntax): void { - this.recordSourceMappingStart(expression); - this.writeToken(expression.typeOfKeyword); - this.writeToOutput(" "); - this.emit(expression.expression); - this.recordSourceMappingEnd(expression); - } - - public emitDeleteExpression(expression: DeleteExpressionSyntax): void { - this.recordSourceMappingStart(expression); - this.writeToken(expression.deleteKeyword); - this.writeToOutput(" "); - this.emit(expression.expression); - this.recordSourceMappingEnd(expression); - } - - public emitVoidExpression(expression: VoidExpressionSyntax): void { - this.recordSourceMappingStart(expression); - this.writeToken(expression.voidKeyword); - this.writeToOutput(" "); - this.emit(expression.expression); - this.recordSourceMappingEnd(expression); - } - - private canEmitDottedNameMemberAccessExpression(expression: MemberAccessExpressionSyntax) { - var memberExpressionNodeType = expression.expression.kind(); - - // If the memberAccess is of Name or another member access, we could potentially emit the symbol using the this memberAccessSymol - if (memberExpressionNodeType === SyntaxKind.IdentifierName || memberExpressionNodeType == SyntaxKind.MemberAccessExpression) { - var memberAccessSymbol = this.getSymbolForEmit(expression).symbol; - var memberAccessExpressionSymbol = this.getSymbolForEmit(expression.expression).symbol; - if (memberAccessSymbol && memberAccessExpressionSymbol // We have symbols resolved for this expression and access - && !this.semanticInfoChain.getAliasSymbolForAST(expression.expression) // The access is not off alias - && (PullHelpers.symbolIsModule(memberAccessExpressionSymbol) || memberAccessExpressionSymbol.kind === PullElementKind.Enum || - memberAccessExpressionSymbol.anyDeclHasFlag(PullElementFlags.InitializedModule | PullElementFlags.Enum))) { // container is module - - // If the memberAccess is in the context of the container, we could use the symbol to emit this expression - var memberAccessSymbolKind = memberAccessSymbol.kind; - if (memberAccessSymbolKind === PullElementKind.Property - || memberAccessSymbolKind === PullElementKind.EnumMember - || (memberAccessSymbol.anyDeclHasFlag(PullElementFlags.Exported) && memberAccessSymbolKind === PullElementKind.Variable && !memberAccessSymbol.anyDeclHasFlag(PullElementFlags.InitializedModule | PullElementFlags.Enum)) - || ((memberAccessSymbol.anyDeclHasFlag(PullElementFlags.Exported) && !this.symbolIsUsedInItsEnclosingContainer(memberAccessSymbol)))) { - - // If the expression is member access, we need to verify it as well - if (memberExpressionNodeType === SyntaxKind.MemberAccessExpression) { - return this.canEmitDottedNameMemberAccessExpression(expression.expression); - } - - return true; - } - } - } - - return false; - } - - // Emit the member access expression using the declPath - private emitDottedNameMemberAccessExpression(expression: MemberAccessExpressionSyntax) { - this.recordSourceMappingStart(expression); - if (expression.expression.kind() === SyntaxKind.MemberAccessExpression) { - // Emit the dotted name access expression - this.emitDottedNameMemberAccessExpressionRecurse(expression.expression); - } - else { // Name - this.emitName(expression.expression, /*addThis*/ true); - } - - this.writeToken(expression.dotToken); - this.emitName(expression.name, /*addThis*/ false); - - this.recordSourceMappingEnd(expression); - } - - // Set the right indices for the recursive member access expression before emitting it using the decl path - private emitDottedNameMemberAccessExpressionRecurse(expression: MemberAccessExpressionSyntax) { - this.emitComments(expression, true); - this.emitDottedNameMemberAccessExpression(expression); - this.emitComments(expression, false); - } - - public emitMemberAccessExpression(expression: MemberAccessExpressionSyntax): void { - if (!this.tryEmitConstant(expression)) { - // If the expression is dotted name of the modules, emit it using decl path so the name could be resolved correctly. - if (this.canEmitDottedNameMemberAccessExpression(expression)) { - this.emitDottedNameMemberAccessExpression(expression); - } - else { - this.recordSourceMappingStart(expression); - this.emit(expression.expression); - this.writeToken(expression.dotToken); - this.emitName(expression.name, false); - this.recordSourceMappingEnd(expression); - } - } - } - - public emitQualifiedName(name: QualifiedNameSyntax): void { - this.recordSourceMappingStart(name); - - this.emit(name.left); - this.writeToken(name.dotToken); - this.emitName(name.right, false); - - this.recordSourceMappingEnd(name); - } - - public emitBinaryExpression(expression: BinaryExpressionSyntax): void { - this.recordSourceMappingStart(expression); - switch (expression.kind()) { - case SyntaxKind.CommaExpression: - this.emit(expression.left); - this.writeToken(expression.operatorToken); - this.writeToOutput(" "); - this.emit(expression.right); - break; - default: - { - this.emit(expression.left); - var binOp = SyntaxFacts.getText(SyntaxFacts.getOperatorTokenFromBinaryExpression(expression.kind())); - this.writeToOutput(" "); - this.writeToOutputWithSourceMapRecord(binOp, expression.operatorToken); - this.writeToOutput(" "); - this.emit(expression.right); - } - } - this.recordSourceMappingEnd(expression); - } - - public emitSimplePropertyAssignment(property: SimplePropertyAssignmentSyntax): void { - this.recordSourceMappingStart(property); - this.emit(property.propertyName); - - this.writeToken(property.colonToken); - this.writeToOutput(" "); - this.emitCommentsArray(ASTHelpers.convertTokenTrailingComments(property.colonToken, this.text()), /*trailing:*/ true, /*noLeadingSpace:*/ true); - - this.emit(property.expression); - this.recordSourceMappingEnd(property); - } - - public emitFunctionPropertyAssignment(funcProp: FunctionPropertyAssignmentSyntax): void { - this.recordSourceMappingStart(funcProp); - - this.emit(funcProp.propertyName); - this.writeToOutput(": "); - - var pullFunctionDecl = this.semanticInfoChain.getDeclForAST(funcProp); - - var savedInArrowFunction = this.inArrowFunction; - this.inArrowFunction = false; - - var temp = this.setContainer(EmitContainer.Function); - var funcName = funcProp.propertyName; - - var pullDecl = this.semanticInfoChain.getDeclForAST(funcProp); - this.pushDecl(pullDecl); - - this.recordSourceMappingStart(funcProp); - this.writeToOutput("function "); - - //this.recordSourceMappingStart(funcProp.propertyName); - //this.writeToOutput(funcProp.propertyName.actualText); - //this.recordSourceMappingEnd(funcProp.propertyName); - - this.emitParameterList(funcProp.callSignature.parameterList); - - this.emitFunctionBodyStatements(funcProp.propertyName.text(), funcProp, - funcProp.callSignature.parameterList.parameters, funcProp.block, /*bodyExpression:*/ null); - - this.recordSourceMappingEnd(funcProp); - - // The extra call is to make sure the caller's funcDecl end is recorded, since caller wont be able to record it - this.recordSourceMappingEnd(funcProp); - - this.emitComments(funcProp, false); - - this.popDecl(pullDecl); - - this.setContainer(temp); - this.inArrowFunction = savedInArrowFunction; - } - - public emitConditionalExpression(expression: ConditionalExpressionSyntax): void { - this.emit(expression.condition); - this.writeToOutput(" "); - this.writeToken(expression.questionToken); - this.writeToOutput(" "); - this.emit(expression.whenTrue); - this.writeToOutput(" "); - this.writeToken(expression.colonToken); - this.writeToOutput(" "); - this.emit(expression.whenFalse); - } - - public emitThrowStatement(statement: ThrowStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.throwKeyword); - this.writeToOutput(" "); - this.emit(statement.expression); - this.writeToOutputWithSourceMapRecord(";", statement.semicolonToken); - this.recordSourceMappingEnd(statement); - } - - public emitExpressionStatement(statement: ExpressionStatementSyntax): void { - var isArrowExpression = statement.expression.kind() === SyntaxKind.SimpleArrowFunctionExpression || statement.expression.kind() === SyntaxKind.ParenthesizedArrowFunctionExpression; - - this.recordSourceMappingStart(statement); - if (isArrowExpression) { - this.writeToOutput("("); - } - - this.emit(statement.expression); - - if (isArrowExpression) { - this.writeToOutput(")"); - } - - this.writeToOutputWithSourceMapRecord(";", statement.semicolonToken); - this.recordSourceMappingEnd(statement); - } - - public emitLabeledStatement(statement: LabeledStatementSyntax): void { - this.writeToOutputWithSourceMapRecord(statement.identifier.text(), statement.identifier); - this.writeToken(statement.colonToken); - this.writeLineToOutput(""); - this.emitJavascript(statement.statement, /*startLine:*/ true); - } - - public emitBlock(block: BlockSyntax): void { - this.recordSourceMappingStart(block); - this.writeLineToOutput(" {"); - this.indenter.increaseIndent(); - if (block.statements) { - this.emitList(block.statements); - } - this.emitCommentsArray(ASTHelpers.convertTokenLeadingComments(block.closeBraceToken, this.text()), /*trailing:*/ false); - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeToken(block.closeBraceToken); - this.recordSourceMappingEnd(block); - } - - public emitBreakStatement(jump: BreakStatementSyntax): void { - this.recordSourceMappingStart(jump); - this.writeToken(jump.breakKeyword); - - if (jump.identifier) { - this.writeToOutput(" "); - this.writeToOutputWithSourceMapRecord(jump.identifier.text(), jump.identifier); - } - - this.writeToOutputWithSourceMapRecord(";", jump.semicolonToken); - this.recordSourceMappingEnd(jump); - } - - public emitContinueStatement(jump: ContinueStatementSyntax): void { - this.recordSourceMappingStart(jump); - this.writeToken(jump.continueKeyword); - - if (jump.identifier) { - this.writeToOutput(" "); - this.writeToOutputWithSourceMapRecord(jump.identifier.text(), jump.identifier); - } - - this.writeToOutputWithSourceMapRecord(";", jump.semicolonToken); - this.recordSourceMappingEnd(jump); - } - - public emitWhileStatement(statement: WhileStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.whileKeyword); - this.writeToOutput(" "); - this.writeToken(statement.openParenToken); - this.emit(statement.condition); - this.writeToken(statement.closeParenToken); - this.emitBlockOrStatement(statement.statement); - this.recordSourceMappingEnd(statement); - } - - public emitDoStatement(statement: DoStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.doKeyword); - this.emitBlockOrStatement(statement.statement); - this.writeToOutput(" "); - this.writeToken(statement.whileKeyword); - this.writeToken(statement.openParenToken); - this.emit(statement.condition); - this.writeToken(statement.closeParenToken); - this.writeToOutputWithSourceMapRecord(";", statement.semicolonToken); - this.recordSourceMappingEnd(statement); - } - - public emitIfStatement(statement: IfStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.ifKeyword); - this.writeToOutput(" "); - this.writeToken(statement.openParenToken); - this.emit(statement.condition); - this.writeToken(statement.closeParenToken); - - this.emitBlockOrStatement(statement.statement); - - if (statement.elseClause) { - if (statement.statement.kind() !== SyntaxKind.Block) { - this.writeLineToOutput(""); - this.emitIndent(); - } - else { - this.writeToOutput(" "); - } - - this.emit(statement.elseClause); - } - this.recordSourceMappingEnd(statement); - } - - public emitElseClause(elseClause: ElseClauseSyntax): void { - this.writeToken(elseClause.elseKeyword); - if (elseClause.statement.kind() === SyntaxKind.IfStatement) { - this.writeToOutput(" "); - this.emit(elseClause.statement); - } - else { - this.emitBlockOrStatement(elseClause.statement); - } - } - - public emitReturnStatement(statement: ReturnStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.returnKeyword); - if (statement.expression) { - this.writeToOutput(" "); - this.emit(statement.expression); - } - - this.writeToOutputWithSourceMapRecord(";", statement.semicolonToken); - this.recordSourceMappingEnd(statement); - } - - public emitForInStatement(statement: ForInStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.forKeyword); - this.writeToOutput(" "); - this.writeToken(statement.openParenToken); - - if (statement.left) { - this.emit(statement.left); - } - else { - this.emit(statement.variableDeclaration); - } - this.writeToOutput(" "); - this.writeToken(statement.inKeyword); - this.writeToOutput(" "); - this.emit(statement.expression); - this.writeToken(statement.closeParenToken); - this.emitBlockOrStatement(statement.statement); - this.recordSourceMappingEnd(statement); - } - - public emitForStatement(statement: ForStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.forKeyword); - this.writeToOutput(" "); - this.writeToken(statement.openParenToken); - - if (statement.variableDeclaration) { - this.emit(statement.variableDeclaration); - } - else if (statement.initializer) { - this.emit(statement.initializer); - } - - this.writeToken(statement.firstSemicolonToken); - this.writeToOutput(" "); - this.emitJavascript(statement.condition, false); - this.writeToken(statement.secondSemicolonToken); - if (statement.incrementor) { - this.writeToOutput(" "); - this.emitJavascript(statement.incrementor, false); - } - this.writeToken(statement.closeParenToken); - this.emitBlockOrStatement(statement.statement); - this.recordSourceMappingEnd(statement); - } - - public emitWithStatement(statement: WithStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.withKeyword); - this.writeToOutput(" "); - this.writeToken(statement.openParenToken); - if (statement.condition) { - this.emit(statement.condition); - } - - this.writeToken(statement.closeParenToken); - var prevInWithBlock = this.inWithBlock; - this.inWithBlock = true; - this.emitBlockOrStatement(statement.statement); - this.inWithBlock = prevInWithBlock; - this.recordSourceMappingEnd(statement); - } - - public emitSwitchStatement(statement: SwitchStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.switchKeyword); - this.writeToOutput(" "); - this.writeToken(statement.openParenToken); - this.emit(statement.expression); - this.writeToken(statement.closeParenToken); - this.writeLineToOutput(" {"); - this.indenter.increaseIndent(); - this.emitList(statement.switchClauses, /*useNewLineSeparator:*/ false); - this.indenter.decreaseIndent(); - this.emitIndent(); - this.writeToken(statement.closeBraceToken); - this.recordSourceMappingEnd(statement); - } - - public emitCaseSwitchClause(clause: CaseSwitchClauseSyntax): void { - this.recordSourceMappingStart(clause); - this.writeToken(clause.caseKeyword); - this.writeToOutput(" "); - this.emit(clause.expression); - this.writeToken(clause.colonToken); - - this.emitSwitchClauseBody(clause.colonToken, clause.statements); - this.recordSourceMappingEnd(clause); - } - - private emitSwitchClauseBody(colonToken: ISyntaxToken, body: IStatementSyntax[]): void { - var text = this.text(); - if (body.length === 1 && childAt(body, 0).kind() === SyntaxKind.Block) { - // The case statement was written with curly braces, so emit it with the appropriate formatting - this.emit(childAt(body, 0)); - this.writeLineToOutput(""); - } - else if (body.length === 1 && this.isOnSameLine(end(colonToken, text), start(body[0], text))) { - this.writeToOutput(" "); - this.emit(childAt(body, 0)); - this.writeLineToOutput(""); - } - else { - // No curly braces. Format in the expected way - this.writeLineToOutput(""); - this.indenter.increaseIndent(); - this.emit(body); - this.indenter.decreaseIndent(); - } - } - - public emitDefaultSwitchClause(clause: DefaultSwitchClauseSyntax): void { - this.recordSourceMappingStart(clause); - this.writeToken(clause.defaultKeyword); - this.writeToken(clause.colonToken); - - this.emitSwitchClauseBody(clause.colonToken, clause.statements); - this.recordSourceMappingEnd(clause); - } - - public emitTryStatement(statement: TryStatementSyntax): void { - this.recordSourceMappingStart(statement); - this.writeToken(statement.tryKeyword); - this.writeToOutput(" "); - this.emit(statement.block); - this.emitJavascript(statement.catchClause, false); - - if (statement.finallyClause) { - this.emit(statement.finallyClause); - } - this.recordSourceMappingEnd(statement); - } - - public emitCatchClause(clause: CatchClauseSyntax): void { - this.writeToOutput(" "); - this.recordSourceMappingStart(clause); - this.writeToken(clause.catchKeyword); - this.writeToOutput(" "); - this.writeToken(clause.openParenToken); - this.emit(clause.identifier); - this.writeToken(clause.closeParenToken); - this.emit(clause.block); - this.recordSourceMappingEnd(clause); - } - - public emitFinallyClause(clause: FinallyClauseSyntax): void { - this.writeToOutput(" "); - this.writeToken(clause.finallyKeyword); - this.emit(clause.block); - } - - public emitDebuggerStatement(statement: DebuggerStatementSyntax): void { - this.writeToken(statement.debuggerKeyword); - this.writeToOutputWithSourceMapRecord(";", statement.semicolonToken); - } - - public emitNumericLiteral(literal: ISyntaxToken): void { - this.writeToOutputWithSourceMapRecord(literal.text(), literal); - } - - public emitRegularExpressionLiteral(literal: ISyntaxToken): void { - this.writeToOutputWithSourceMapRecord(literal.text(), literal); - } - - public emitStringLiteral(literal: ISyntaxToken): void { - this.writeToOutputWithSourceMapRecord(literal.text(), literal); - } - - public emitEqualsValueClause(clause: EqualsValueClauseSyntax): void { - this.writeToOutput(" "); - this.writeToken(clause.equalsToken); - this.writeToOutput(" "); - this.emitCommentsArray(ASTHelpers.convertTokenTrailingComments(clause.equalsToken, this.text()), /*trailing:*/ true, /*noLeadingSpace:*/ true); - - this.emit(clause.value); - } - - private emitParameter(parameter: ParameterSyntax): void { - this.writeToOutputWithSourceMapRecord(parameter.identifier.text(), parameter); - } - - public emitConstructorDeclaration(declaration: ConstructorDeclarationSyntax): void { - if (declaration.block) { - this.emitConstructor(declaration); - } - else { - this.emitComments(declaration, /*pre:*/ true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - } - - public shouldEmitFunctionDeclaration(declaration: FunctionDeclarationSyntax): boolean { - return ASTHelpers.preComments(declaration, this.text()) !== null || (!hasModifier(declaration.modifiers, PullElementFlags.Ambient) && declaration.block !== null); - } - - public emitFunctionDeclaration(declaration: FunctionDeclarationSyntax): void { - if (!hasModifier(declaration.modifiers, PullElementFlags.Ambient) && declaration.block !== null) { - this.emitFunction(declaration); - } - else { - this.emitComments(declaration, /*pre:*/ true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - } - - private emitSourceUnit(sourceUnit: SourceUnitSyntax): void { - if (!this.document.isDeclareFile()) { - var pullDecl = this.semanticInfoChain.getDeclForAST(sourceUnit); - this.pushDecl(pullDecl); - this.emitScriptElements(sourceUnit); - this.popDecl(pullDecl); - - this.emitCommentsArray(ASTHelpers.convertTokenLeadingComments(sourceUnit.endOfFileToken, this.text()), /*trailing:*/ false); - } - } - - public shouldEmitEnumDeclaration(declaration: EnumDeclarationSyntax): boolean { - return ASTHelpers.preComments(declaration, this.text()) !== null || !ASTHelpers.enumIsElided(declaration); - } - - public emitEnumDeclaration(declaration: EnumDeclarationSyntax): void { - if (!ASTHelpers.enumIsElided(declaration)) { - this.emitComments(declaration, true); - this.emitEnum(declaration); - this.emitComments(declaration, false); - } - else { - this.emitComments(declaration, true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - } - - public shouldEmitModuleDeclaration(declaration: ModuleDeclarationSyntax): boolean { - return ASTHelpers.preComments(declaration, this.text()) !== null || !ASTHelpers.moduleIsElided(declaration); - } - - private emitModuleDeclaration(declaration: ModuleDeclarationSyntax): void { - if (!ASTHelpers.moduleIsElided(declaration)) { - this.emitModuleDeclarationWorker(declaration); - } - else { - this.emitComments(declaration, true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - } - - public shouldEmitClassDeclaration(declaration: ClassDeclarationSyntax): boolean { - return ASTHelpers.preComments(declaration, this.text()) !== null || !hasModifier(declaration.modifiers, PullElementFlags.Ambient); - } - - public emitClassDeclaration(declaration: ClassDeclarationSyntax): void { - if (!hasModifier(declaration.modifiers, PullElementFlags.Ambient)) { - this.emitClass(declaration); - } - else { - this.emitComments(declaration, /*pre:*/ true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - } - - public shouldEmitInterfaceDeclaration(declaration: InterfaceDeclarationSyntax): boolean { - return ASTHelpers.preComments(declaration, this.text()) !== null; - } - - public emitInterfaceDeclaration(declaration: InterfaceDeclarationSyntax): void { - this.emitComments(declaration, /*pre:*/ true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - - private firstVariableDeclarator(statement: VariableStatementSyntax): VariableDeclaratorSyntax { - return statement.variableDeclaration.variableDeclarators[0]; - } - - private isNotAmbientOrHasInitializer(variableStatement: VariableStatementSyntax): boolean { - return !hasModifier(variableStatement.modifiers, PullElementFlags.Ambient) || this.firstVariableDeclarator(variableStatement).equalsValueClause !== null; - } - - public shouldEmitVariableStatement(statement: VariableStatementSyntax): boolean { - return ASTHelpers.preComments(statement, this.text()) !== null || this.isNotAmbientOrHasInitializer(statement); - } - - public emitVariableStatement(statement: VariableStatementSyntax): void { - if (this.isNotAmbientOrHasInitializer(statement)) { - this.emitComments(statement, true); - this.emit(statement.variableDeclaration); - this.writeToOutputWithSourceMapRecord(";", statement.semicolonToken); - this.emitComments(statement, false); - } - else { - this.emitComments(statement, /*pre:*/ true, /*onlyPinnedOrTripleSlashComments:*/ true); - } - } - - public emitGenericType(type: GenericTypeSyntax): void { - this.emit(type.name); - } - - private shouldEmit(ast: ISyntaxElement): boolean { - if (!ast) { - return false; - } - - switch (ast.kind()) { - case SyntaxKind.ImportDeclaration: - return this.shouldEmitImportDeclaration(ast); - case SyntaxKind.ClassDeclaration: - return this.shouldEmitClassDeclaration(ast); - case SyntaxKind.InterfaceDeclaration: - return this.shouldEmitInterfaceDeclaration(ast); - case SyntaxKind.FunctionDeclaration: - return this.shouldEmitFunctionDeclaration(ast); - case SyntaxKind.ModuleDeclaration: - return this.shouldEmitModuleDeclaration(ast); - case SyntaxKind.VariableStatement: - return this.shouldEmitVariableStatement(ast); - case SyntaxKind.OmittedExpression: - return false; - case SyntaxKind.EnumDeclaration: - return this.shouldEmitEnumDeclaration(ast); - } - - return true; - } - - private emit(ast: ISyntaxElement): void { - if (!ast) { - return; - } - - switch (ast.kind()) { - case SyntaxKind.SeparatedList: - return this.emitSeparatedList(ast); - case SyntaxKind.List: - return this.emitList(ast); - case SyntaxKind.SourceUnit: - return this.emitSourceUnit(ast); - case SyntaxKind.ImportDeclaration: - return this.emitImportDeclaration(ast); - case SyntaxKind.ExportAssignment: - return this.setExportAssignment(ast); - case SyntaxKind.ClassDeclaration: - return this.emitClassDeclaration(ast); - case SyntaxKind.InterfaceDeclaration: - return this.emitInterfaceDeclaration(ast); - case SyntaxKind.IdentifierName: - return this.emitName(ast, true); - case SyntaxKind.VariableDeclarator: - return this.emitVariableDeclarator(ast); - case SyntaxKind.SimpleArrowFunctionExpression: - return this.emitSimpleArrowFunctionExpression(ast); - case SyntaxKind.ParenthesizedArrowFunctionExpression: - return this.emitParenthesizedArrowFunctionExpression(ast); - case SyntaxKind.FunctionDeclaration: - return this.emitFunctionDeclaration(ast); - case SyntaxKind.ModuleDeclaration: - return this.emitModuleDeclaration(ast); - case SyntaxKind.VariableDeclaration: - return this.emitVariableDeclaration(ast); - case SyntaxKind.GenericType: - return this.emitGenericType(ast); - case SyntaxKind.ConstructorDeclaration: - return this.emitConstructorDeclaration(ast); - case SyntaxKind.EnumDeclaration: - return this.emitEnumDeclaration(ast); - case SyntaxKind.EnumElement: - return this.emitEnumElement(ast); - case SyntaxKind.FunctionExpression: - return this.emitFunctionExpression(ast); - case SyntaxKind.VariableStatement: - return this.emitVariableStatement(ast); - } - - this.emitComments(ast, true); - this.emitWorker(ast); - this.emitComments(ast, false); - } - - private emitWorker(ast: ISyntaxElement): void { - if (!ast) { - return; - } - - switch (ast.kind()) { - case SyntaxKind.NumericLiteral: - return this.emitNumericLiteral(ast); - case SyntaxKind.RegularExpressionLiteral: - return this.emitRegularExpressionLiteral(ast); - case SyntaxKind.StringLiteral: - return this.emitStringLiteral(ast); - case SyntaxKind.FalseKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.TrueKeyword: - return this.emitLiteralExpression(ast); - case SyntaxKind.ThisKeyword: - return this.emitThisExpression(ast); - case SyntaxKind.SuperKeyword: - return this.emitSuperExpression(ast); - case SyntaxKind.ParenthesizedExpression: - return this.emitParenthesizedExpression(ast); - case SyntaxKind.ArrayLiteralExpression: - return this.emitArrayLiteralExpression(ast); - case SyntaxKind.PostDecrementExpression: - case SyntaxKind.PostIncrementExpression: - return this.emitPostfixUnaryExpression(ast); - case SyntaxKind.LogicalNotExpression: - case SyntaxKind.BitwiseNotExpression: - case SyntaxKind.NegateExpression: - case SyntaxKind.PlusExpression: - case SyntaxKind.PreIncrementExpression: - case SyntaxKind.PreDecrementExpression: - return this.emitPrefixUnaryExpression(ast); - case SyntaxKind.InvocationExpression: - return this.emitInvocationExpression(ast); - case SyntaxKind.ElementAccessExpression: - return this.emitElementAccessExpression(ast); - case SyntaxKind.MemberAccessExpression: - return this.emitMemberAccessExpression(ast); - case SyntaxKind.QualifiedName: - return this.emitQualifiedName(ast); - case SyntaxKind.CommaExpression: - case SyntaxKind.AssignmentExpression: - case SyntaxKind.AddAssignmentExpression: - case SyntaxKind.SubtractAssignmentExpression: - case SyntaxKind.MultiplyAssignmentExpression: - case SyntaxKind.DivideAssignmentExpression: - case SyntaxKind.ModuloAssignmentExpression: - case SyntaxKind.AndAssignmentExpression: - case SyntaxKind.ExclusiveOrAssignmentExpression: - case SyntaxKind.OrAssignmentExpression: - case SyntaxKind.LeftShiftAssignmentExpression: - case SyntaxKind.SignedRightShiftAssignmentExpression: - case SyntaxKind.UnsignedRightShiftAssignmentExpression: - case SyntaxKind.LogicalOrExpression: - case SyntaxKind.LogicalAndExpression: - case SyntaxKind.BitwiseOrExpression: - case SyntaxKind.BitwiseExclusiveOrExpression: - case SyntaxKind.BitwiseAndExpression: - case SyntaxKind.EqualsWithTypeConversionExpression: - case SyntaxKind.NotEqualsWithTypeConversionExpression: - case SyntaxKind.EqualsExpression: - case SyntaxKind.NotEqualsExpression: - case SyntaxKind.LessThanExpression: - case SyntaxKind.GreaterThanExpression: - case SyntaxKind.LessThanOrEqualExpression: - case SyntaxKind.GreaterThanOrEqualExpression: - case SyntaxKind.InstanceOfExpression: - case SyntaxKind.InExpression: - case SyntaxKind.LeftShiftExpression: - case SyntaxKind.SignedRightShiftExpression: - case SyntaxKind.UnsignedRightShiftExpression: - case SyntaxKind.MultiplyExpression: - case SyntaxKind.DivideExpression: - case SyntaxKind.ModuloExpression: - case SyntaxKind.AddExpression: - case SyntaxKind.SubtractExpression: - return this.emitBinaryExpression(ast); - case SyntaxKind.ConditionalExpression: - return this.emitConditionalExpression(ast); - case SyntaxKind.EqualsValueClause: - return this.emitEqualsValueClause(ast); - case SyntaxKind.Parameter: - return this.emitParameter(ast); - case SyntaxKind.Block: - return this.emitBlock(ast); - case SyntaxKind.ElseClause: - return this.emitElseClause(ast); - case SyntaxKind.IfStatement: - return this.emitIfStatement(ast); - case SyntaxKind.ExpressionStatement: - return this.emitExpressionStatement(ast); - case SyntaxKind.GetAccessor: - return this.emitGetAccessor(ast); - case SyntaxKind.SetAccessor: - return this.emitSetAccessor(ast); - case SyntaxKind.ThrowStatement: - return this.emitThrowStatement(ast); - case SyntaxKind.ReturnStatement: - return this.emitReturnStatement(ast); - case SyntaxKind.ObjectCreationExpression: - return this.emitObjectCreationExpression(ast); - case SyntaxKind.SwitchStatement: - return this.emitSwitchStatement(ast); - case SyntaxKind.CaseSwitchClause: - return this.emitCaseSwitchClause(ast); - case SyntaxKind.DefaultSwitchClause: - return this.emitDefaultSwitchClause(ast); - case SyntaxKind.BreakStatement: - return this.emitBreakStatement(ast); - case SyntaxKind.ContinueStatement: - return this.emitContinueStatement(ast); - case SyntaxKind.ForStatement: - return this.emitForStatement(ast); - case SyntaxKind.ForInStatement: - return this.emitForInStatement(ast); - case SyntaxKind.WhileStatement: - return this.emitWhileStatement(ast); - case SyntaxKind.WithStatement: - return this.emitWithStatement(ast); - case SyntaxKind.CastExpression: - return this.emitCastExpression(ast); - case SyntaxKind.ObjectLiteralExpression: - return this.emitObjectLiteralExpression(ast); - case SyntaxKind.SimplePropertyAssignment: - return this.emitSimplePropertyAssignment(ast); - case SyntaxKind.FunctionPropertyAssignment: - return this.emitFunctionPropertyAssignment(ast); - case SyntaxKind.EmptyStatement: - return this.writeToken((ast).semicolonToken); - case SyntaxKind.TryStatement: - return this.emitTryStatement(ast); - case SyntaxKind.CatchClause: - return this.emitCatchClause(ast); - case SyntaxKind.FinallyClause: - return this.emitFinallyClause(ast); - case SyntaxKind.LabeledStatement: - return this.emitLabeledStatement(ast); - case SyntaxKind.DoStatement: - return this.emitDoStatement(ast); - case SyntaxKind.TypeOfExpression: - return this.emitTypeOfExpression(ast); - case SyntaxKind.DeleteExpression: - return this.emitDeleteExpression(ast); - case SyntaxKind.VoidExpression: - return this.emitVoidExpression(ast); - case SyntaxKind.DebuggerStatement: - return this.emitDebuggerStatement(ast); - } - } - } - - export function getLastConstructor(classDecl: ClassDeclarationSyntax): ConstructorDeclarationSyntax { - for (var i = classDecl.classElements.length - 1; i >= 0; i--) { - var child = classDecl.classElements[i]; - - if (child.kind() === SyntaxKind.ConstructorDeclaration) { - return child; - } - } - - return null; - } - - export function getTrimmedTextLines(comment: Comment): string[] { - if (comment.kind() === SyntaxKind.MultiLineCommentTrivia) { - return comment.fullText().split("\n").map(s => s.trim()); - } - else { - return [comment.fullText().trim()]; - } - } -} \ No newline at end of file From c46662fa7227115144d2e374fae7c376e7e683fc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 16 Jan 2015 12:58:10 -0800 Subject: [PATCH 06/71] Fixes the duplicate doc comment display in case of union property Handles #1237 --- src/services/services.ts | 65 ++++++++++++++------------ tests/cases/fourslash/commentsUnion.ts | 7 +++ 2 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 tests/cases/fourslash/commentsUnion.ts diff --git a/src/services/services.ts b/src/services/services.ts index 1618fb6e276..a88b31bd2fe 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -335,36 +335,43 @@ module ts { var paramTag = "@param"; var jsDocCommentParts: SymbolDisplayPart[] = []; - ts.forEach(declarations, declaration => { - var sourceFileOfDeclaration = getSourceFileOfNode(declaration); - // If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments - if (canUseParsedParamTagComments && declaration.kind === SyntaxKind.Parameter) { - ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => { - var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); - if (cleanedParamJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); - } - }); + ts.forEach(declarations,(declaration, indexOfDeclaration) => { + if (indexOf(declarations, declaration) === indexOfDeclaration) { + // Already collected the doc comments from this declaration. + // Eg. var a: Array | Array; a.length + // The property length will have two declarations of property length coming + // from Array - Array and Array + + var sourceFileOfDeclaration = getSourceFileOfNode(declaration); + // If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments + if (canUseParsedParamTagComments && declaration.kind === SyntaxKind.Parameter) { + ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => { + var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedParamJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + } + }); + } + + // If this is left side of dotted module declaration, there is no doc comments associated with this node + if (declaration.kind === SyntaxKind.ModuleDeclaration && (declaration).body.kind === SyntaxKind.ModuleDeclaration) { + return; + } + + // If this is dotted module name, get the doc comments from the parent + while (declaration.kind === SyntaxKind.ModuleDeclaration && declaration.parent.kind === SyntaxKind.ModuleDeclaration) { + declaration = declaration.parent; + } + + // Get the cleaned js doc comment text from the declaration + ts.forEach(getJsDocCommentTextRange( + declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { + var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); + } + }); } - - // If this is left side of dotted module declaration, there is no doc comments associated with this node - if (declaration.kind === SyntaxKind.ModuleDeclaration && (declaration).body.kind === SyntaxKind.ModuleDeclaration) { - return; - } - - // If this is dotted module name, get the doc comments from the parent - while (declaration.kind === SyntaxKind.ModuleDeclaration && declaration.parent.kind === SyntaxKind.ModuleDeclaration) { - declaration = declaration.parent; - } - - // Get the cleaned js doc comment text from the declaration - ts.forEach(getJsDocCommentTextRange( - declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { - var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); - if (cleanedJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); - } - }); }); return jsDocCommentParts; diff --git a/tests/cases/fourslash/commentsUnion.ts b/tests/cases/fourslash/commentsUnion.ts new file mode 100644 index 00000000000..568e0d93cde --- /dev/null +++ b/tests/cases/fourslash/commentsUnion.ts @@ -0,0 +1,7 @@ +/// + +////var a: Array | Array; +////a./*1*/length + +goTo.marker('1'); +verify.quickInfoIs("(property) length: number", "Gets or sets the length of the array. This is a number one higher than the highest element defined in an array."); \ No newline at end of file From 7b2579964ce8fcbdf65f66b30bb872b642abb1b1 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 19 Jan 2015 15:39:21 -0800 Subject: [PATCH 07/71] Automatic bisecting script --- scripts/bisect-test.ts | 48 ++++++++++++++++++++++++++++++++++++++++++ scripts/bisect.cmd | 30 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 scripts/bisect-test.ts create mode 100644 scripts/bisect.cmd diff --git a/scripts/bisect-test.ts b/scripts/bisect-test.ts new file mode 100644 index 00000000000..6ad53991462 --- /dev/null +++ b/scripts/bisect-test.ts @@ -0,0 +1,48 @@ +/// + +import cp = require('child_process'); +import fs = require('fs'); + +var args = process.argv.slice(2); + +var jake = cp.exec('jake clean local', () => void 0); +jake.on('close', code => { + if (code === 0) { + // See what we're being asked to do + if (args[1] === 'compiles' || args[1] === '!compiles') { + var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); + tsc.on('close', tscCode => { + if ((tscCode === 0) === (args[1] === 'compiles')) { + console.log('Good'); + process.exit(0); // Good + } else { + console.log('Bad'); + process.exit(1); // Bad + } + }); + } else if (args[1] === 'emits' || args[1] === '!emits') { + var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); + tsc.on('close', tscCode => { + fs.readFile(args[2], 'utf-8', (err, data) => { + var doesContains = data.indexOf(args[3]) >= 0; + if (doesContains === (args[1] === 'emits')) { + console.log('Good'); + process.exit(0); // Good + } else { + console.log('Bad'); + process.exit(1); // Bad + } + }); + }); + } else { + console.log('Unknown command line arguments.'); + console.log('Usage (compile errors): git bisect run scripts\bisect.js "foo.ts --module amd" compiles'); + console.log('Usage (emit check): git bisect run scripts\bisect.js bar.ts emits bar.js "_this = this"'); + process.exit(-1); + } + } else { + // Build failed + process.exit(125); // bisect skip + } +}); + \ No newline at end of file diff --git a/scripts/bisect.cmd b/scripts/bisect.cmd new file mode 100644 index 00000000000..148722665d4 --- /dev/null +++ b/scripts/bisect.cmd @@ -0,0 +1,30 @@ +echo off +IF NOT EXIST scripts\bisect.cmd GOTO :wrongdir +IF "%1" == "" GOTO :usage +IF "%1" == "GO" GOTO :run +GOTO :copy + +:usage +echo Usage: bisect GoodCommit BadCommit test.ts compiles +echo Usage: bisect GoodCommit BadCommit test.ts emits test.js "var x = 3" +GOTO :eof + +:copy +copy scripts\bisect.cmd scripts\bisect-fresh.cmd +scripts\bisect-fresh GO %* +GOTO :eof + +:run +call jake local +node built/local/tsc.js scripts/bisect-test.ts --module commonjs +git bisect start %2 %3 +git bisect run node scripts/bisect-test.js %4 %5 %6 %7 +del scripts\bisect-test.js +del scripts\bisect-fresh.cmd +GOTO :eof + +:wrongdir +@echo Run this file from the repo folder, not the scripts folder +GOTO :eof + +:eof \ No newline at end of file From 15187e5e1d42a073db08595ab8ac79710703b8e1 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 6 Jan 2015 14:19:43 -0800 Subject: [PATCH 08/71] Enable computed properties --- src/compiler/checker.ts | 12 ++--- .../diagnosticInformationMap.generated.ts | 1 - src/compiler/diagnosticMessages.json | 5 -- .../FunctionDeclaration8_es6.errors.txt | 4 +- .../FunctionDeclaration9_es6.errors.txt | 4 +- ...unctionPropertyAssignments5_es6.errors.txt | 4 +- .../computedPropertyNames1.errors.txt | 13 ----- .../reference/computedPropertyNames1.js | 14 ++++++ .../computedPropertyNames2.errors.txt | 20 +------- .../reference/computedPropertyNames2.js | 48 +++++++++++++++++++ .../computedPropertyNames3.errors.txt | 20 +------- .../reference/computedPropertyNames3.js | 47 ++++++++++++++++++ ...omputedPropertyNamesOnOverloads.errors.txt | 5 +- .../parserComputedPropertyName12.errors.txt | 9 ---- .../reference/parserComputedPropertyName12.js | 13 +++++ .../parserComputedPropertyName17.errors.txt | 7 --- .../reference/parserComputedPropertyName17.js | 6 +++ .../parserComputedPropertyName2.errors.txt | 7 --- .../reference/parserComputedPropertyName2.js | 5 ++ .../parserComputedPropertyName24.errors.txt | 9 ---- .../reference/parserComputedPropertyName24.js | 17 +++++++ .../parserComputedPropertyName3.errors.txt | 7 --- .../reference/parserComputedPropertyName3.js | 6 +++ .../parserComputedPropertyName35.errors.txt | 6 +-- .../reference/parserComputedPropertyName35.js | 9 ++++ .../parserComputedPropertyName37.errors.txt | 9 ---- .../reference/parserComputedPropertyName37.js | 9 ++++ .../parserComputedPropertyName38.errors.txt | 9 ---- .../reference/parserComputedPropertyName38.js | 13 +++++ .../parserComputedPropertyName4.errors.txt | 7 --- .../reference/parserComputedPropertyName4.js | 6 +++ .../parserComputedPropertyName40.errors.txt | 9 ---- .../reference/parserComputedPropertyName40.js | 13 +++++ .../parserComputedPropertyName41.errors.txt | 9 ---- .../reference/parserComputedPropertyName41.js | 9 ++++ .../parserComputedPropertyName5.errors.txt | 7 --- .../reference/parserComputedPropertyName5.js | 6 +++ .../parserComputedPropertyName6.errors.txt | 10 ---- .../reference/parserComputedPropertyName6.js | 5 ++ .../parserES5ComputedPropertyName2.errors.txt | 4 +- .../parserES5ComputedPropertyName3.errors.txt | 4 +- .../parserES5ComputedPropertyName4.errors.txt | 4 +- 42 files changed, 248 insertions(+), 183 deletions(-) delete mode 100644 tests/baselines/reference/computedPropertyNames1.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames1.js create mode 100644 tests/baselines/reference/computedPropertyNames2.js create mode 100644 tests/baselines/reference/computedPropertyNames3.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName12.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName12.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName17.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName17.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName2.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName2.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName24.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName24.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName3.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName3.js create mode 100644 tests/baselines/reference/parserComputedPropertyName35.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName37.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName37.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName38.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName38.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName4.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName4.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName40.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName40.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName41.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName41.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName5.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName5.js delete mode 100644 tests/baselines/reference/parserComputedPropertyName6.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName6.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ad62c1d639..9a3aa0d2fc3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10416,22 +10416,18 @@ module ts { return false; } - function checkGrammarComputedPropertyName(node: Node): void { + function checkGrammarComputedPropertyName(node: Node): boolean { // If node is not a computedPropertyName, just skip the grammar checking if (node.kind !== SyntaxKind.ComputedPropertyName) { - return; + return false; } - // Since computed properties are not supported in the type checker, disallow them in TypeScript 1.4 - // Once full support is added, remove this error. - grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_not_currently_supported); - return; var computedPropertyName = node; if (compilerOptions.target < ScriptTarget.ES6) { - grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); + return grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (computedPropertyName.expression).operator === SyntaxKind.CommaToken) { - grammarErrorOnNode(computedPropertyName.expression, Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); + return grammarErrorOnNode(computedPropertyName.expression, Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 9d62ee0e030..03df069a9ab 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -445,6 +445,5 @@ module ts { You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported.", isEarly: true }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported.", isEarly: true }, - Computed_property_names_are_not_currently_supported: { code: 9002, category: DiagnosticCategory.Error, key: "Computed property names are not currently supported.", isEarly: true }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ee962edc3a0..6be3bb65c77 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1880,10 +1880,5 @@ "category": "Error", "code": 9001, "isEarly": true - }, - "Computed property names are not currently supported.": { - "category": "Error", - "code": 9002, - "isEarly": true } } diff --git a/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt index 08d151203c9..5232c8f1608 100644 --- a/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (1 errors) ==== var v = { [yield]: foo } ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt index 8333eceb267..902a195e8fc 100644 --- a/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,13): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,13): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ==== @@ -8,5 +8,5 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,1 !!! error TS9001: Generators are not currently supported. var v = { [yield]: foo } ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt index eff0c79d827..430dd503667 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (1 errors) ==== var v = { *[foo()]() { } } ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames1.errors.txt b/tests/baselines/reference/computedPropertyNames1.errors.txt deleted file mode 100644 index 02abbcd6b2d..00000000000 --- a/tests/baselines/reference/computedPropertyNames1.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts(2,9): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts(3,9): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts (2 errors) ==== - var v = { - get [0 + 1]() { return 0 }, - ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - set [0 + 1](v: string) { } //No error - ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames1.js b/tests/baselines/reference/computedPropertyNames1.js new file mode 100644 index 00000000000..8f3e448d698 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames1.js @@ -0,0 +1,14 @@ +//// [computedPropertyNames1.ts] +var v = { + get [0 + 1]() { return 0 }, + set [0 + 1](v: string) { } //No error +} + +//// [computedPropertyNames1.js] +var v = { + get [0 + 1]() { + return 0; + }, + set [0 + 1](v) { + } //No error +}; diff --git a/tests/baselines/reference/computedPropertyNames2.errors.txt b/tests/baselines/reference/computedPropertyNames2.errors.txt index 3dd4ac01d5f..d0fd1de4576 100644 --- a/tests/baselines/reference/computedPropertyNames2.errors.txt +++ b/tests/baselines/reference/computedPropertyNames2.errors.txt @@ -1,37 +1,19 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(4,5): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(5,12): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(7,9): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(9,16): error TS9002: Computed property names are not currently supported. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts (8 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts (2 errors) ==== var methodName = "method"; var accessorName = "accessor"; class C { [methodName]() { } - ~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. static [methodName]() { } - ~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. get [accessorName]() { } ~~~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. - ~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. set [accessorName](v) { } - ~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. static get [accessorName]() { } ~~~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. - ~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. static set [accessorName](v) { } - ~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames2.js b/tests/baselines/reference/computedPropertyNames2.js new file mode 100644 index 00000000000..78d53ef94fc --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames2.js @@ -0,0 +1,48 @@ +//// [computedPropertyNames2.ts] +var methodName = "method"; +var accessorName = "accessor"; +class C { + [methodName]() { } + static [methodName]() { } + get [accessorName]() { } + set [accessorName](v) { } + static get [accessorName]() { } + static set [accessorName](v) { } +} + +//// [computedPropertyNames2.js] +var methodName = "method"; +var accessorName = "accessor"; +var C = (function () { + function C() { + } + C.prototype[methodName] = function () { + }; + C[methodName] = function () { + }; + Object.defineProperty(C.prototype, accessorName, { + get: function () { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, accessorName, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, accessorName, { + get: function () { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, accessorName, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames3.errors.txt b/tests/baselines/reference/computedPropertyNames3.errors.txt index 084a1f8889f..37a4ddaf1c0 100644 --- a/tests/baselines/reference/computedPropertyNames3.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3.errors.txt @@ -1,36 +1,18 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(3,5): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS9002: Computed property names are not currently supported. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(8,16): error TS9002: Computed property names are not currently supported. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (8 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (2 errors) ==== var id; class C { [0 + 1]() { } - ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. static [() => { }]() { } - ~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. get [delete id]() { } ~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. - ~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. set [[0, 1]](v) { } - ~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. static get [""]() { } ~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. - ~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. static set [id.toString()](v) { } - ~~~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames3.js b/tests/baselines/reference/computedPropertyNames3.js new file mode 100644 index 00000000000..fbd76bf48fc --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames3.js @@ -0,0 +1,47 @@ +//// [computedPropertyNames3.ts] +var id; +class C { + [0 + 1]() { } + static [() => { }]() { } + get [delete id]() { } + set [[0, 1]](v) { } + static get [""]() { } + static set [id.toString()](v) { } +} + +//// [computedPropertyNames3.js] +var id; +var C = (function () { + function C() { + } + C.prototype[0 + 1] = function () { + }; + C[function () { + }] = function () { + }; + Object.defineProperty(C.prototype, delete id, { + get: function () { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, [0, 1], { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "", { + get: function () { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, id.toString(), { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNamesOnOverloads.errors.txt b/tests/baselines/reference/computedPropertyNamesOnOverloads.errors.txt index 6329ab39f0f..b3c2957a13f 100644 --- a/tests/baselines/reference/computedPropertyNamesOnOverloads.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesOnOverloads.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesOnOverloads.ts(4,5): error TS1168: Computed property names are not allowed in method overloads. tests/cases/conformance/es6/computedProperties/computedPropertyNamesOnOverloads.ts(5,5): error TS1168: Computed property names are not allowed in method overloads. -tests/cases/conformance/es6/computedProperties/computedPropertyNamesOnOverloads.ts(6,5): error TS9002: Computed property names are not currently supported. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesOnOverloads.ts (3 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesOnOverloads.ts (2 errors) ==== var methodName = "method"; var accessorName = "accessor"; class C { @@ -14,6 +13,4 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesOnOverloads. ~~~~~~~~~~~~ !!! error TS1168: Computed property names are not allowed in method overloads. [methodName](v?: string) { } - ~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName12.errors.txt b/tests/baselines/reference/parserComputedPropertyName12.errors.txt deleted file mode 100644 index c028275369d..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName12.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName12.ts(2,4): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName12.ts (1 errors) ==== - class C { - [e]() { } - ~~~ -!!! error TS9002: Computed property names are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName12.js b/tests/baselines/reference/parserComputedPropertyName12.js new file mode 100644 index 00000000000..96e62b626e7 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName12.js @@ -0,0 +1,13 @@ +//// [parserComputedPropertyName12.ts] +class C { + [e]() { } +} + +//// [parserComputedPropertyName12.js] +var C = (function () { + function C() { + } + C.prototype[e] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/parserComputedPropertyName17.errors.txt b/tests/baselines/reference/parserComputedPropertyName17.errors.txt deleted file mode 100644 index f8b1a4866e8..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName17.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName17.ts(1,15): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName17.ts (1 errors) ==== - var v = { set [e](v) { } } - ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName17.js b/tests/baselines/reference/parserComputedPropertyName17.js new file mode 100644 index 00000000000..98d61ab8bca --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName17.js @@ -0,0 +1,6 @@ +//// [parserComputedPropertyName17.ts] +var v = { set [e](v) { } } + +//// [parserComputedPropertyName17.js] +var v = { set [e](v) { +} }; diff --git a/tests/baselines/reference/parserComputedPropertyName2.errors.txt b/tests/baselines/reference/parserComputedPropertyName2.errors.txt deleted file mode 100644 index 9eb6cdd6004..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName2.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName2.ts(1,11): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName2.ts (1 errors) ==== - var v = { [e]: 1 }; - ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName2.js b/tests/baselines/reference/parserComputedPropertyName2.js new file mode 100644 index 00000000000..f3c41f963f5 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName2.js @@ -0,0 +1,5 @@ +//// [parserComputedPropertyName2.ts] +var v = { [e]: 1 }; + +//// [parserComputedPropertyName2.js] +var v = { [e]: 1 }; diff --git a/tests/baselines/reference/parserComputedPropertyName24.errors.txt b/tests/baselines/reference/parserComputedPropertyName24.errors.txt deleted file mode 100644 index fa7280a93e7..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName24.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName24.ts(2,9): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName24.ts (1 errors) ==== - class C { - set [e](v) { } - ~~~ -!!! error TS9002: Computed property names are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName24.js b/tests/baselines/reference/parserComputedPropertyName24.js new file mode 100644 index 00000000000..0b9467fb26d --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName24.js @@ -0,0 +1,17 @@ +//// [parserComputedPropertyName24.ts] +class C { + set [e](v) { } +} + +//// [parserComputedPropertyName24.js] +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, e, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/parserComputedPropertyName3.errors.txt b/tests/baselines/reference/parserComputedPropertyName3.errors.txt deleted file mode 100644 index b13f453cb89..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName3.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName3.ts(1,11): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName3.ts (1 errors) ==== - var v = { [e]() { } }; - ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName3.js b/tests/baselines/reference/parserComputedPropertyName3.js new file mode 100644 index 00000000000..2e73fe87d3a --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName3.js @@ -0,0 +1,6 @@ +//// [parserComputedPropertyName3.ts] +var v = { [e]() { } }; + +//// [parserComputedPropertyName3.js] +var v = { [e]() { +} }; diff --git a/tests/baselines/reference/parserComputedPropertyName35.errors.txt b/tests/baselines/reference/parserComputedPropertyName35.errors.txt index d68f0eb1ec7..e603d1c73fd 100644 --- a/tests/baselines/reference/parserComputedPropertyName35.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName35.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName35.ts(2,5): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName35.ts(2,6): error TS1171: A comma expression is not allowed in a computed property name. ==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName35.ts (1 errors) ==== var x = { [0, 1]: { } - ~~~~~~ -!!! error TS9002: Computed property names are not currently supported. + ~~~~ +!!! error TS1171: A comma expression is not allowed in a computed property name. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName35.js b/tests/baselines/reference/parserComputedPropertyName35.js new file mode 100644 index 00000000000..15992d54ece --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName35.js @@ -0,0 +1,9 @@ +//// [parserComputedPropertyName35.ts] +var x = { + [0, 1]: { } +} + +//// [parserComputedPropertyName35.js] +var x = { + [0, 1]: {} +}; diff --git a/tests/baselines/reference/parserComputedPropertyName37.errors.txt b/tests/baselines/reference/parserComputedPropertyName37.errors.txt deleted file mode 100644 index fa1acd5dbe0..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName37.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts(2,5): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts (1 errors) ==== - var v = { - [public]: 0 - ~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - }; \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName37.js b/tests/baselines/reference/parserComputedPropertyName37.js new file mode 100644 index 00000000000..eb16d5ade37 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName37.js @@ -0,0 +1,9 @@ +//// [parserComputedPropertyName37.ts] +var v = { + [public]: 0 +}; + +//// [parserComputedPropertyName37.js] +var v = { + [public]: 0 +}; diff --git a/tests/baselines/reference/parserComputedPropertyName38.errors.txt b/tests/baselines/reference/parserComputedPropertyName38.errors.txt deleted file mode 100644 index 910a907ee0f..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName38.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,5): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (1 errors) ==== - class C { - [public]() { } - ~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.js b/tests/baselines/reference/parserComputedPropertyName38.js new file mode 100644 index 00000000000..487ff4078fd --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName38.js @@ -0,0 +1,13 @@ +//// [parserComputedPropertyName38.ts] +class C { + [public]() { } +} + +//// [parserComputedPropertyName38.js] +var C = (function () { + function C() { + } + C.prototype[public] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/parserComputedPropertyName4.errors.txt b/tests/baselines/reference/parserComputedPropertyName4.errors.txt deleted file mode 100644 index c1137b15872..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName4.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts(1,15): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts (1 errors) ==== - var v = { get [e]() { } }; - ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName4.js b/tests/baselines/reference/parserComputedPropertyName4.js new file mode 100644 index 00000000000..a88545566e6 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName4.js @@ -0,0 +1,6 @@ +//// [parserComputedPropertyName4.ts] +var v = { get [e]() { } }; + +//// [parserComputedPropertyName4.js] +var v = { get [e]() { +} }; diff --git a/tests/baselines/reference/parserComputedPropertyName40.errors.txt b/tests/baselines/reference/parserComputedPropertyName40.errors.txt deleted file mode 100644 index 93be0ad51b7..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName40.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts(2,5): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts (1 errors) ==== - class C { - [a ? "" : ""]() {} - ~~~~~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName40.js b/tests/baselines/reference/parserComputedPropertyName40.js new file mode 100644 index 00000000000..5f6381360fc --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName40.js @@ -0,0 +1,13 @@ +//// [parserComputedPropertyName40.ts] +class C { + [a ? "" : ""]() {} +} + +//// [parserComputedPropertyName40.js] +var C = (function () { + function C() { + } + C.prototype[a ? "" : ""] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/parserComputedPropertyName41.errors.txt b/tests/baselines/reference/parserComputedPropertyName41.errors.txt deleted file mode 100644 index eb5e9a9ebbf..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName41.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts(2,5): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts (1 errors) ==== - var v = { - [0 in []]: true - ~~~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName41.js b/tests/baselines/reference/parserComputedPropertyName41.js new file mode 100644 index 00000000000..b19cc3e7b3f --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName41.js @@ -0,0 +1,9 @@ +//// [parserComputedPropertyName41.ts] +var v = { + [0 in []]: true +} + +//// [parserComputedPropertyName41.js] +var v = { + [0 in []]: true +}; diff --git a/tests/baselines/reference/parserComputedPropertyName5.errors.txt b/tests/baselines/reference/parserComputedPropertyName5.errors.txt deleted file mode 100644 index f0dd056fdf9..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName5.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,22): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts (1 errors) ==== - var v = { public get [e]() { } }; - ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName5.js b/tests/baselines/reference/parserComputedPropertyName5.js new file mode 100644 index 00000000000..aa86d54d09c --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName5.js @@ -0,0 +1,6 @@ +//// [parserComputedPropertyName5.ts] +var v = { public get [e]() { } }; + +//// [parserComputedPropertyName5.js] +var v = { get [e]() { +} }; diff --git a/tests/baselines/reference/parserComputedPropertyName6.errors.txt b/tests/baselines/reference/parserComputedPropertyName6.errors.txt deleted file mode 100644 index 893bf3da719..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName6.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts(1,11): error TS9002: Computed property names are not currently supported. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts(1,19): error TS9002: Computed property names are not currently supported. - - -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts (2 errors) ==== - var v = { [e]: 1, [e + e]: 2 }; - ~~~ -!!! error TS9002: Computed property names are not currently supported. - ~~~~~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName6.js b/tests/baselines/reference/parserComputedPropertyName6.js new file mode 100644 index 00000000000..b60ad66a9d8 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName6.js @@ -0,0 +1,5 @@ +//// [parserComputedPropertyName6.ts] +var v = { [e]: 1, [e + e]: 2 }; + +//// [parserComputedPropertyName6.js] +var v = { [e]: 1, [e + e]: 2 }; diff --git a/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt index 7b6b74b8fd8..dc7d7e7ba30 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts(1,11): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts (1 errors) ==== var v = { [e]: 1 }; ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt index 669fd190265..376c1a29ae4 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts(1,11): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts (1 errors) ==== var v = { [e]() { } }; ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt index af0c6e858ad..e0b816f157c 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,15): error TS9002: Computed property names are not currently supported. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,15): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts (1 errors) ==== var v = { get [e]() { } }; ~~~ -!!! error TS9002: Computed property names are not currently supported. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file From d192fea774cda7b39bc56ee8e129f26a53d7b754 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 6 Jan 2015 15:17:07 -0800 Subject: [PATCH 09/71] Switch checkObjectLiteral to iterate over element declarations --- src/compiler/checker.ts | 78 +++++++++---------- .../lastPropertyInLiteralWins.errors.txt | 28 +++---- .../reference/memberOverride.errors.txt | 7 +- ...ypesInImplementationSignatures2.errors.txt | 5 +- 4 files changed, 55 insertions(+), 63 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9a3aa0d2fc3..a52a2765543 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5399,56 +5399,48 @@ module ts { // Grammar checking checkGrammarObjectLiteralExpression(node); - var members = node.symbol.members; var properties: SymbolTable = {}; var contextualType = getContextualType(node); var typeFlags: TypeFlags; - for (var id in members) { - if (hasProperty(members, id)) { - var member = members[id]; - if (member.flags & SymbolFlags.Property || isObjectLiteralMethod(member.declarations[0])) { - var memberDecl = member.declarations[0]; - if (memberDecl.kind === SyntaxKind.PropertyAssignment) { - var type = checkExpression((memberDecl).initializer, contextualMapper); - } - else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { - var type = checkObjectLiteralMethod(memberDecl, contextualMapper); - } - else { - Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); - var type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName - ? unknownType - : checkExpression(memberDecl.name, contextualMapper); - } - typeFlags |= type.flags; - var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); - prop.declarations = member.declarations; - prop.parent = member.parent; - if (member.valueDeclaration) { - prop.valueDeclaration = member.valueDeclaration; - } - - prop.type = type; - prop.target = member; - member = prop; + for (var i = 0; i < node.properties.length; i++) { + var memberDecl = node.properties[i]; + if (memberDecl.kind === SyntaxKind.PropertyAssignment || + memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment || + isObjectLiteralMethod(memberDecl)) { + if (memberDecl.kind === SyntaxKind.PropertyAssignment) { + var type = checkExpression((memberDecl).initializer, contextualMapper); + } + else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { + var type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - // TypeScript 1.0 spec (April 2014) - // A get accessor declaration is processed in the same manner as - // an ordinary function declaration(section 6.1) with no parameters. - // A set accessor declaration is processed in the same manner - // as an ordinary function declaration with a single parameter and a Void return type. - var getAccessor = getDeclarationOfKind(member, SyntaxKind.GetAccessor); - if (getAccessor) { - checkAccessorDeclaration(getAccessor); - } - - var setAccessor = getDeclarationOfKind(member, SyntaxKind.SetAccessor); - if (setAccessor) { - checkAccessorDeclaration(setAccessor); - } + Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); + var type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName + ? unknownType + : checkExpression(memberDecl.name, contextualMapper); } + typeFlags |= type.flags; + var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); + var member = memberDecl.symbol; + prop.declarations = member.declarations; + prop.parent = member.parent; + if (member.valueDeclaration) { + prop.valueDeclaration = member.valueDeclaration; + } + + prop.type = type; + prop.target = member; + properties[prop.name] = prop; + } + else { + // TypeScript 1.0 spec (April 2014) + // A get accessor declaration is processed in the same manner as + // an ordinary function declaration(section 6.1) with no parameters. + // A set accessor declaration is processed in the same manner + // as an ordinary function declaration with a single parameter and a Void return type. + Debug.assert(memberDecl.kind === SyntaxKind.GetAccessor || memberDecl.kind === SyntaxKind.SetAccessor); + checkAccessorDeclaration(memberDecl); properties[member.name] = member; } } diff --git a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt index 4bf5521d24d..d503f59c602 100644 --- a/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt +++ b/tests/baselines/reference/lastPropertyInLiteralWins.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2300: Duplicate identifier 'thunk'. -tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate identifier 'thunk'. -tests/cases/compiler/lastPropertyInLiteralWins.ts(12,6): error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'. +tests/cases/compiler/lastPropertyInLiteralWins.ts(7,6): error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'. Types of property 'thunk' are incompatible. Type '(num: number) => void' is not assignable to type '(str: string) => void'. +tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2300: Duplicate identifier 'thunk'. +tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate identifier 'thunk'. tests/cases/compiler/lastPropertyInLiteralWins.ts(13,5): error TS2300: Duplicate identifier 'thunk'. tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate identifier 'thunk'. @@ -15,21 +15,12 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate thing.thunk("str"); } test({ // Should error, as last one wins, and is wrong type + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ thunk: (str: string) => {}, - ~~~~~ -!!! error TS2300: Duplicate identifier 'thunk'. - thunk: (num: number) => {} - ~~~~~ -!!! error TS2300: Duplicate identifier 'thunk'. - }); - - test({ // Should be OK. Last 'thunk' is of correct type - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - thunk: (num: number) => {}, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2300: Duplicate identifier 'thunk'. - thunk: (str: string) => {} + thunk: (num: number) => {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ !!! error TS2300: Duplicate identifier 'thunk'. @@ -38,4 +29,13 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate !!! error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'. !!! error TS2345: Types of property 'thunk' are incompatible. !!! error TS2345: Type '(num: number) => void' is not assignable to type '(str: string) => void'. + + test({ // Should be OK. Last 'thunk' is of correct type + thunk: (num: number) => {}, + ~~~~~ +!!! error TS2300: Duplicate identifier 'thunk'. + thunk: (str: string) => {} + ~~~~~ +!!! error TS2300: Duplicate identifier 'thunk'. + }); \ No newline at end of file diff --git a/tests/baselines/reference/memberOverride.errors.txt b/tests/baselines/reference/memberOverride.errors.txt index 0fd0fb57e67..b4974e69e53 100644 --- a/tests/baselines/reference/memberOverride.errors.txt +++ b/tests/baselines/reference/memberOverride.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/memberOverride.ts(4,5): error TS2300: Duplicate identifier 'a'. tests/cases/compiler/memberOverride.ts(5,5): error TS2300: Duplicate identifier 'a'. -tests/cases/compiler/memberOverride.ts(8,5): error TS2322: Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/memberOverride.ts (3 errors) ==== +==== tests/cases/compiler/memberOverride.ts (2 errors) ==== // An object initialiser accepts the first definition for the same property with a different type signature // Should compile, since the second declaration of a overrides the first var x = { @@ -15,6 +14,4 @@ tests/cases/compiler/memberOverride.ts(8,5): error TS2322: Type 'string' is not !!! error TS2300: Duplicate identifier 'a'. } - var n: number = x.a; - ~ -!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file + var n: number = x.a; \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt index cbc517e0520..3cc172c96d5 100644 --- a/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesInImplementationSignatures2.errors.txt @@ -11,9 +11,10 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralType tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2300: Duplicate identifier 'foo'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2381: A signature with an implementation cannot use a string literal type. tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2381: A signature with an implementation cannot use a string literal type. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (13 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (14 errors) ==== // String literal types are only valid in overload signatures function foo(x: any); @@ -67,5 +68,7 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralType foo(x: 'a') { }, ~~~ !!! error TS2300: Duplicate identifier 'foo'. + ~~~~~~~~~~~~~~~ +!!! error TS2381: A signature with an implementation cannot use a string literal type. } \ No newline at end of file From ef06879a7519a49c537d86ea11b231225f71def1 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 9 Jan 2015 14:45:27 -0800 Subject: [PATCH 10/71] Create symbols for computed properties --- src/compiler/binder.ts | 27 +++++++++++-------- src/compiler/checker.ts | 11 ++++---- .../FunctionDeclaration8_es6.errors.txt | 7 +++-- ...unctionPropertyAssignments5_es6.errors.txt | 5 +++- .../reference/computedPropertyNames1.types | 12 +++++++++ .../parserComputedPropertyName12.types | 7 +++++ .../parserComputedPropertyName17.types | 7 +++++ .../parserComputedPropertyName2.types | 6 +++++ .../parserComputedPropertyName24.types | 8 ++++++ .../parserComputedPropertyName3.types | 6 +++++ .../parserComputedPropertyName37.types | 9 +++++++ .../parserComputedPropertyName38.types | 7 +++++ .../parserComputedPropertyName4.errors.txt | 7 +++++ .../parserComputedPropertyName40.types | 8 ++++++ .../parserComputedPropertyName41.types | 9 +++++++ .../parserComputedPropertyName5.errors.txt | 7 +++++ .../parserComputedPropertyName6.types | 9 +++++++ .../parserES5ComputedPropertyName4.errors.txt | 7 +++-- .../reference/privateIndexer2.errors.txt | 5 +++- 19 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNames1.types create mode 100644 tests/baselines/reference/parserComputedPropertyName12.types create mode 100644 tests/baselines/reference/parserComputedPropertyName17.types create mode 100644 tests/baselines/reference/parserComputedPropertyName2.types create mode 100644 tests/baselines/reference/parserComputedPropertyName24.types create mode 100644 tests/baselines/reference/parserComputedPropertyName3.types create mode 100644 tests/baselines/reference/parserComputedPropertyName37.types create mode 100644 tests/baselines/reference/parserComputedPropertyName38.types create mode 100644 tests/baselines/reference/parserComputedPropertyName4.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName40.types create mode 100644 tests/baselines/reference/parserComputedPropertyName41.types create mode 100644 tests/baselines/reference/parserComputedPropertyName5.errors.txt create mode 100644 tests/baselines/reference/parserComputedPropertyName6.types diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 201913a50b4..bbebe9e62ea 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -118,11 +118,7 @@ module ts { } function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol { - // Nodes with computed property names will not get symbols, because the type checker - // does not make properties for them. - if (hasComputedNameButNotSymbol(node)) { - return undefined; - } + Debug.assert(!hasComputedNameButNotSymbol(node)); var name = getDeclarationName(node); if (name !== undefined) { @@ -395,14 +391,14 @@ module ts { break; case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - bindDeclaration(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); + bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: - bindDeclaration(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); + bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.EnumMember: - bindDeclaration(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false); + bindPropertyOrMethodOrAccessor(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: @@ -415,7 +411,7 @@ module ts { // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - bindDeclaration(node, SymbolFlags.Method | ((node).questionToken ? SymbolFlags.Optional : 0), + bindPropertyOrMethodOrAccessor(node, SymbolFlags.Method | ((node).questionToken ? SymbolFlags.Optional : 0), isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.FunctionDeclaration: @@ -425,10 +421,10 @@ module ts { bindDeclaration(node, SymbolFlags.Constructor, /*symbolExcludes:*/ 0, /*isBlockScopeContainer:*/ true); break; case SyntaxKind.GetAccessor: - bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); + bindPropertyOrMethodOrAccessor(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.SetAccessor: - bindDeclaration(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true); + bindPropertyOrMethodOrAccessor(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.FunctionType: @@ -510,5 +506,14 @@ module ts { declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); } } + + function bindPropertyOrMethodOrAccessor(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { + if (hasComputedNameButNotSymbol(node)) { + bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); + } + else { + bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); + } + } } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a52a2765543..a93400b9703 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5405,6 +5405,7 @@ module ts { for (var i = 0; i < node.properties.length; i++) { var memberDecl = node.properties[i]; + var member = memberDecl.symbol; if (memberDecl.kind === SyntaxKind.PropertyAssignment || memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment || isObjectLiteralMethod(memberDecl)) { @@ -5422,7 +5423,6 @@ module ts { } typeFlags |= type.flags; var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); - var member = memberDecl.symbol; prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) { @@ -5431,7 +5431,7 @@ module ts { prop.type = type; prop.target = member; - properties[prop.name] = prop; + member = prop; } else { // TypeScript 1.0 spec (April 2014) @@ -5441,8 +5441,9 @@ module ts { // as an ordinary function declaration with a single parameter and a Void return type. Debug.assert(memberDecl.kind === SyntaxKind.GetAccessor || memberDecl.kind === SyntaxKind.SetAccessor); checkAccessorDeclaration(memberDecl); - properties[member.name] = member; } + + properties[member.name] = member; } var stringIndexType = getIndexType(IndexKind.String); @@ -7427,9 +7428,9 @@ module ts { } } } - - checkAndStoreTypeOfAccessors(getSymbolOfNode(node)); } + + checkAndStoreTypeOfAccessors(getSymbolOfNode(node)); } checkFunctionLikeDeclaration(node); diff --git a/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt index 5232c8f1608..386e1e8f63c 100644 --- a/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,20): error TS2304: Cannot find name 'foo'. -==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (1 errors) ==== +==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (2 errors) ==== var v = { [yield]: foo } ~~~~~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt index 430dd503667..0999186ec09 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt @@ -1,7 +1,10 @@ +tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported. tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (1 errors) ==== +==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ==== var v = { *[foo()]() { } } + ~ +!!! error TS9001: Generators are not currently supported. ~~~~~~~ !!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames1.types b/tests/baselines/reference/computedPropertyNames1.types new file mode 100644 index 00000000000..b44aa3c69d0 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames1.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts === +var v = { +>v : {} +>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : {} + + get [0 + 1]() { return 0 }, +>0 + 1 : number + + set [0 + 1](v: string) { } //No error +>0 + 1 : number +>v : string +} diff --git a/tests/baselines/reference/parserComputedPropertyName12.types b/tests/baselines/reference/parserComputedPropertyName12.types new file mode 100644 index 00000000000..fcc96bc4d51 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName12.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName12.ts === +class C { +>C : C + + [e]() { } +>e : unknown +} diff --git a/tests/baselines/reference/parserComputedPropertyName17.types b/tests/baselines/reference/parserComputedPropertyName17.types new file mode 100644 index 00000000000..8ae109dda37 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName17.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName17.ts === +var v = { set [e](v) { } } +>v : {} +>{ set [e](v) { } } : {} +>e : unknown +>v : any + diff --git a/tests/baselines/reference/parserComputedPropertyName2.types b/tests/baselines/reference/parserComputedPropertyName2.types new file mode 100644 index 00000000000..8e533282e28 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName2.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName2.ts === +var v = { [e]: 1 }; +>v : {} +>{ [e]: 1 } : {} +>e : unknown + diff --git a/tests/baselines/reference/parserComputedPropertyName24.types b/tests/baselines/reference/parserComputedPropertyName24.types new file mode 100644 index 00000000000..d2de5244057 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName24.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName24.ts === +class C { +>C : C + + set [e](v) { } +>e : unknown +>v : any +} diff --git a/tests/baselines/reference/parserComputedPropertyName3.types b/tests/baselines/reference/parserComputedPropertyName3.types new file mode 100644 index 00000000000..8a5cfafbd40 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName3.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName3.ts === +var v = { [e]() { } }; +>v : {} +>{ [e]() { } } : {} +>e : unknown + diff --git a/tests/baselines/reference/parserComputedPropertyName37.types b/tests/baselines/reference/parserComputedPropertyName37.types new file mode 100644 index 00000000000..ebcd0ca276c --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName37.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts === +var v = { +>v : {} +>{ [public]: 0} : {} + + [public]: 0 +>public : unknown + +}; diff --git a/tests/baselines/reference/parserComputedPropertyName38.types b/tests/baselines/reference/parserComputedPropertyName38.types new file mode 100644 index 00000000000..c77b9fcc67f --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName38.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts === +class C { +>C : C + + [public]() { } +>public : unknown +} diff --git a/tests/baselines/reference/parserComputedPropertyName4.errors.txt b/tests/baselines/reference/parserComputedPropertyName4.errors.txt new file mode 100644 index 00000000000..ec90ebf8df1 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName4.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts(1,15): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts (1 errors) ==== + var v = { get [e]() { } }; + ~~~ +!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName40.types b/tests/baselines/reference/parserComputedPropertyName40.types new file mode 100644 index 00000000000..1b0b3ae49f0 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName40.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts === +class C { +>C : C + + [a ? "" : ""]() {} +>a ? "" : "" : string +>a : unknown +} diff --git a/tests/baselines/reference/parserComputedPropertyName41.types b/tests/baselines/reference/parserComputedPropertyName41.types new file mode 100644 index 00000000000..468a44e6b9e --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName41.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts === +var v = { +>v : {} +>{ [0 in []]: true} : {} + + [0 in []]: true +>0 in [] : boolean +>[] : undefined[] +} diff --git a/tests/baselines/reference/parserComputedPropertyName5.errors.txt b/tests/baselines/reference/parserComputedPropertyName5.errors.txt new file mode 100644 index 00000000000..1d321dc156e --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName5.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,22): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts (1 errors) ==== + var v = { public get [e]() { } }; + ~~~ +!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName6.types b/tests/baselines/reference/parserComputedPropertyName6.types new file mode 100644 index 00000000000..5fa7e79c32c --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName6.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts === +var v = { [e]: 1, [e + e]: 2 }; +>v : {} +>{ [e]: 1, [e + e]: 2 } : {} +>e : unknown +>e + e : any +>e : unknown +>e : unknown + diff --git a/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt index e0b816f157c..df262603331 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,15): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,15): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts (2 errors) ==== var v = { get [e]() { } }; ~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~~~ +!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. \ No newline at end of file diff --git a/tests/baselines/reference/privateIndexer2.errors.txt b/tests/baselines/reference/privateIndexer2.errors.txt index 8d3c1ec1e6d..405167d68f8 100644 --- a/tests/baselines/reference/privateIndexer2.errors.txt +++ b/tests/baselines/reference/privateIndexer2.errors.txt @@ -1,17 +1,20 @@ tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,15): error TS1005: ']' expected. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,17): error TS2304: Cannot find name 'string'. tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,23): error TS1005: ',' expected. tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,24): error TS1136: Property assignment expected. tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,32): error TS1005: ':' expected. tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts (5 errors) ==== +==== tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts (6 errors) ==== // private indexers not allowed var x = { private [x: string]: string; ~ !!! error TS1005: ']' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'string'. ~ !!! error TS1005: ',' expected. ~ From 7192767a00e5d7651fbd419c49d04bc4d477e65c Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 9 Jan 2015 17:46:16 -0800 Subject: [PATCH 11/71] Add type checking for computed properties in object literals --- src/compiler/checker.ts | 18 +++++++++++++++++- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 8 ++++++-- src/compiler/utilities.ts | 2 ++ .../FunctionDeclaration8_es6.errors.txt | 5 ++++- .../FunctionDeclaration9_es6.errors.txt | 5 ++++- ...FunctionPropertyAssignments5_es6.errors.txt | 7 +++++-- .../parserComputedPropertyName1.errors.txt | 5 ++++- .../parserComputedPropertyName17.errors.txt | 7 +++++++ .../parserComputedPropertyName17.types | 7 ------- .../parserComputedPropertyName2.errors.txt | 7 +++++++ .../parserComputedPropertyName2.types | 6 ------ .../parserComputedPropertyName3.errors.txt | 7 +++++++ .../parserComputedPropertyName3.types | 6 ------ .../parserComputedPropertyName37.errors.txt | 9 +++++++++ .../parserComputedPropertyName37.types | 9 --------- .../parserComputedPropertyName4.errors.txt | 7 +++++-- .../parserComputedPropertyName41.errors.txt | 9 +++++++++ .../parserComputedPropertyName41.types | 9 --------- .../parserComputedPropertyName5.errors.txt | 7 +++++-- .../parserComputedPropertyName6.errors.txt | 13 +++++++++++++ .../parserComputedPropertyName6.types | 9 --------- .../parserES5ComputedPropertyName2.errors.txt | 7 +++++-- .../parserES5ComputedPropertyName3.errors.txt | 7 +++++-- .../parserES5ComputedPropertyName4.errors.txt | 7 +++++-- 25 files changed, 120 insertions(+), 64 deletions(-) create mode 100644 tests/baselines/reference/parserComputedPropertyName17.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName17.types create mode 100644 tests/baselines/reference/parserComputedPropertyName2.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName2.types create mode 100644 tests/baselines/reference/parserComputedPropertyName3.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName3.types create mode 100644 tests/baselines/reference/parserComputedPropertyName37.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName37.types create mode 100644 tests/baselines/reference/parserComputedPropertyName41.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName41.types create mode 100644 tests/baselines/reference/parserComputedPropertyName6.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName6.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a93400b9703..15df97de4c9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5395,6 +5395,17 @@ module ts { return (+name).toString() === name; } + function checkComputedPropertyName(node: ComputedPropertyName): void { + var computedNameType = checkExpression(node.expression); + + // This will only allow types number, string, or any. Any types more complex will + // be disallowed, even union types like string | number. In the future, we might consider + // allowing types like that. + if ((computedNameType.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.Any)) === 0) { + error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); + } + } + function checkObjectLiteral(node: ObjectLiteralExpression, contextualMapper?: TypeMapper): Type { // Grammar checking checkGrammarObjectLiteralExpression(node); @@ -5443,7 +5454,12 @@ module ts { checkAccessorDeclaration(memberDecl); } - properties[member.name] = member; + if (hasComputedNameButNotSymbol(memberDecl)) { + checkComputedPropertyName(memberDecl.name); + } + else { + properties[member.name] = member; + } } var stringIndexType = getIndexType(IndexKind.String); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 03df069a9ab..6354633fe60 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -299,6 +299,7 @@ module ts { Type_0_is_not_an_array_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type." }, A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" }, A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." }, + A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', or 'any'." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6be3bb65c77..8268af730ec 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -675,7 +675,7 @@ }, "A parameter property may not be a binding pattern.": { "category": "Error", - "code": 1187 + "code": 1187 }, "Duplicate identifier '{0}'.": { @@ -1288,7 +1288,11 @@ }, "A binding pattern parameter cannot be optional in an implementation signature.": { "category": "Error", - "code": 2463 + "code": 2463 + }, + "A computed property name must be of type 'string', 'number', or 'any'.": { + "category": "Error", + "code": 2464 }, "Import declaration '{0}' is using private name '{1}'.": { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7494ec9f6cb..f1fab4137e2 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -527,6 +527,8 @@ module ts { return node === (parent).expression; case SyntaxKind.TemplateSpan: return node === (parent).expression; + case SyntaxKind.ComputedPropertyName: + return node === (parent).expression; default: if (isExpression(parent)) { return true; diff --git a/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt index 386e1e8f63c..2c8d034649e 100644 --- a/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration8_es6.errors.txt @@ -1,10 +1,13 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,12): error TS2304: Cannot find name 'yield'. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,20): error TS2304: Cannot find name 'foo'. -==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (3 errors) ==== var v = { [yield]: foo } ~~~~~~~ !!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~~~~~ +!!! error TS2304: Cannot find name 'yield'. ~~~ !!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt index 902a195e8fc..ef744681fa1 100644 --- a/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt @@ -1,12 +1,15 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,13): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,14): error TS9000: 'yield' expressions are not currently supported. -==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (3 errors) ==== function * foo() { ~ !!! error TS9001: Generators are not currently supported. var v = { [yield]: foo } ~~~~~~~ !!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~~~~~ +!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt index 0999186ec09..c8c356a57ad 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt @@ -1,10 +1,13 @@ tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported. tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,13): error TS2304: Cannot find name 'foo'. -==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (3 errors) ==== var v = { *[foo()]() { } } ~ !!! error TS9001: Generators are not currently supported. ~~~~~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName1.errors.txt b/tests/baselines/reference/parserComputedPropertyName1.errors.txt index 508d06a915c..2258051a46e 100644 --- a/tests/baselines/reference/parserComputedPropertyName1.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName1.errors.txt @@ -1,7 +1,10 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName1.ts(1,12): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName1.ts(1,15): error TS1005: ':' expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName1.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName1.ts (2 errors) ==== var v = { [e] }; + ~ +!!! error TS2304: Cannot find name 'e'. ~ !!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName17.errors.txt b/tests/baselines/reference/parserComputedPropertyName17.errors.txt new file mode 100644 index 00000000000..d8b43ada527 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName17.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName17.ts(1,16): error TS2304: Cannot find name 'e'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName17.ts (1 errors) ==== + var v = { set [e](v) { } } + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName17.types b/tests/baselines/reference/parserComputedPropertyName17.types deleted file mode 100644 index 8ae109dda37..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName17.types +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName17.ts === -var v = { set [e](v) { } } ->v : {} ->{ set [e](v) { } } : {} ->e : unknown ->v : any - diff --git a/tests/baselines/reference/parserComputedPropertyName2.errors.txt b/tests/baselines/reference/parserComputedPropertyName2.errors.txt new file mode 100644 index 00000000000..864c7adf1b5 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName2.ts(1,12): error TS2304: Cannot find name 'e'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName2.ts (1 errors) ==== + var v = { [e]: 1 }; + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName2.types b/tests/baselines/reference/parserComputedPropertyName2.types deleted file mode 100644 index 8e533282e28..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName2.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName2.ts === -var v = { [e]: 1 }; ->v : {} ->{ [e]: 1 } : {} ->e : unknown - diff --git a/tests/baselines/reference/parserComputedPropertyName3.errors.txt b/tests/baselines/reference/parserComputedPropertyName3.errors.txt new file mode 100644 index 00000000000..4b20c55f499 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName3.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName3.ts(1,12): error TS2304: Cannot find name 'e'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName3.ts (1 errors) ==== + var v = { [e]() { } }; + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName3.types b/tests/baselines/reference/parserComputedPropertyName3.types deleted file mode 100644 index 8a5cfafbd40..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName3.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName3.ts === -var v = { [e]() { } }; ->v : {} ->{ [e]() { } } : {} ->e : unknown - diff --git a/tests/baselines/reference/parserComputedPropertyName37.errors.txt b/tests/baselines/reference/parserComputedPropertyName37.errors.txt new file mode 100644 index 00000000000..64a9e7e99dc --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName37.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts(2,6): error TS2304: Cannot find name 'public'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts (1 errors) ==== + var v = { + [public]: 0 + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + }; \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName37.types b/tests/baselines/reference/parserComputedPropertyName37.types deleted file mode 100644 index ebcd0ca276c..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName37.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts === -var v = { ->v : {} ->{ [public]: 0} : {} - - [public]: 0 ->public : unknown - -}; diff --git a/tests/baselines/reference/parserComputedPropertyName4.errors.txt b/tests/baselines/reference/parserComputedPropertyName4.errors.txt index ec90ebf8df1..bfc78b162fd 100644 --- a/tests/baselines/reference/parserComputedPropertyName4.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName4.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts(1,15): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts(1,16): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts (2 errors) ==== var v = { get [e]() { } }; ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. \ No newline at end of file +!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName41.errors.txt b/tests/baselines/reference/parserComputedPropertyName41.errors.txt new file mode 100644 index 00000000000..65d4ec8627f --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName41.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts(2,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts (1 errors) ==== + var v = { + [0 in []]: true + ~~~~~~~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName41.types b/tests/baselines/reference/parserComputedPropertyName41.types deleted file mode 100644 index 468a44e6b9e..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName41.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts === -var v = { ->v : {} ->{ [0 in []]: true} : {} - - [0 in []]: true ->0 in [] : boolean ->[] : undefined[] -} diff --git a/tests/baselines/reference/parserComputedPropertyName5.errors.txt b/tests/baselines/reference/parserComputedPropertyName5.errors.txt index 1d321dc156e..07cc6f3a9f0 100644 --- a/tests/baselines/reference/parserComputedPropertyName5.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName5.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,22): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,23): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts (2 errors) ==== var v = { public get [e]() { } }; ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. \ No newline at end of file +!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName6.errors.txt b/tests/baselines/reference/parserComputedPropertyName6.errors.txt new file mode 100644 index 00000000000..90f1b688408 --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts(1,12): error TS2304: Cannot find name 'e'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts(1,20): error TS2304: Cannot find name 'e'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts(1,24): error TS2304: Cannot find name 'e'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts (3 errors) ==== + var v = { [e]: 1, [e + e]: 2 }; + ~ +!!! error TS2304: Cannot find name 'e'. + ~ +!!! error TS2304: Cannot find name 'e'. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName6.types b/tests/baselines/reference/parserComputedPropertyName6.types deleted file mode 100644 index 5fa7e79c32c..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName6.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName6.ts === -var v = { [e]: 1, [e + e]: 2 }; ->v : {} ->{ [e]: 1, [e + e]: 2 } : {} ->e : unknown ->e + e : any ->e : unknown ->e : unknown - diff --git a/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt index dc7d7e7ba30..5918387942d 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName2.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts(1,12): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName2.ts (2 errors) ==== var v = { [e]: 1 }; ~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt index 376c1a29ae4..097ab1ea9cb 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName3.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts(1,12): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName3.ts (2 errors) ==== var v = { [e]() { } }; ~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt index df262603331..ca69791c93c 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName4.errors.txt @@ -1,10 +1,13 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,15): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,15): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts(1,16): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName4.ts (3 errors) ==== var v = { get [e]() { } }; ~~~ !!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. ~~~ -!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. \ No newline at end of file +!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file From 4ac2b4b9c87d4025e47bde52d2cadd31b2c18870 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 12 Jan 2015 14:04:34 -0800 Subject: [PATCH 12/71] Add tests for object literals with computed properties --- .../reference/computedPropertyNames4.js | 35 ++++++++++++++ .../reference/computedPropertyNames4.types | 48 +++++++++++++++++++ .../computedPropertyNames5.errors.txt | 30 ++++++++++++ .../reference/computedPropertyNames5.js | 21 ++++++++ .../computedPropertyNames6.errors.txt | 20 ++++++++ .../reference/computedPropertyNames6.js | 19 ++++++++ .../computedPropertyNames7.errors.txt | 12 +++++ .../reference/computedPropertyNames7.js | 16 +++++++ .../computedPropertyNames8.errors.txt | 17 +++++++ .../reference/computedPropertyNames8.js | 19 ++++++++ .../computedPropertyNames9.errors.txt | 16 +++++++ .../reference/computedPropertyNames9.js | 20 ++++++++ .../computedPropertyNames4.ts | 17 +++++++ .../computedPropertyNames5.ts | 10 ++++ .../computedPropertyNames6.ts | 9 ++++ .../computedPropertyNames7.ts | 7 +++ .../computedPropertyNames8.ts | 9 ++++ .../computedPropertyNames9.ts | 11 +++++ 18 files changed, 336 insertions(+) create mode 100644 tests/baselines/reference/computedPropertyNames4.js create mode 100644 tests/baselines/reference/computedPropertyNames4.types create mode 100644 tests/baselines/reference/computedPropertyNames5.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames5.js create mode 100644 tests/baselines/reference/computedPropertyNames6.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames6.js create mode 100644 tests/baselines/reference/computedPropertyNames7.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames7.js create mode 100644 tests/baselines/reference/computedPropertyNames8.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames8.js create mode 100644 tests/baselines/reference/computedPropertyNames9.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames9.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts diff --git a/tests/baselines/reference/computedPropertyNames4.js b/tests/baselines/reference/computedPropertyNames4.js new file mode 100644 index 00000000000..5acb6d957da --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames4.js @@ -0,0 +1,35 @@ +//// [computedPropertyNames4.ts] +var s: string; +var n: number; +var a: any; +var v = { + [s]: 0, + [n]: n, + [s + s]: 1, + [s + n]: 2, + [+s]: s, + [""]: 0, + [0]: 0, + [a]: 1, + [true]: 0, + [`hello bye`]: 0, + [`hello ${a} bye`]: 0 +} + +//// [computedPropertyNames4.js] +var s; +var n; +var a; +var v = { + [s]: 0, + [n]: n, + [s + s]: 1, + [s + n]: 2, + [+s]: s, + [""]: 0, + [0]: 0, + [a]: 1, + [true]: 0, + [`hello bye`]: 0, + [`hello ${a} bye`]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNames4.types b/tests/baselines/reference/computedPropertyNames4.types new file mode 100644 index 00000000000..968cc86b598 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames4.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts === +var s: string; +>s : string + +var n: number; +>n : number + +var a: any; +>a : any + +var v = { +>v : {} +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : {} + + [s]: 0, +>s : string + + [n]: n, +>n : number +>n : number + + [s + s]: 1, +>s + s : string +>s : string +>s : string + + [s + n]: 2, +>s + n : string +>s : string +>n : number + + [+s]: s, +>+s : number +>s : string +>s : string + + [""]: 0, + [0]: 0, + [a]: 1, +>a : any + + [true]: 0, +>true : any + + [`hello bye`]: 0, + [`hello ${a} bye`]: 0 +>a : any +} diff --git a/tests/baselines/reference/computedPropertyNames5.errors.txt b/tests/baselines/reference/computedPropertyNames5.errors.txt new file mode 100644 index 00000000000..f7ca4b97e9f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames5.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(4,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(8,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts (6 errors) ==== + var b: boolean; + var v = { + [b]: 0, + ~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [true]: 1, + ~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [[]]: 0, + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [{}]: 0, + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [undefined]: undefined, + ~~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [null]: null + ~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames5.js b/tests/baselines/reference/computedPropertyNames5.js new file mode 100644 index 00000000000..d0158da6400 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames5.js @@ -0,0 +1,21 @@ +//// [computedPropertyNames5.ts] +var b: boolean; +var v = { + [b]: 0, + [true]: 1, + [[]]: 0, + [{}]: 0, + [undefined]: undefined, + [null]: null +} + +//// [computedPropertyNames5.js] +var b; +var v = { + [b]: 0, + [true]: 1, + [[]]: 0, + [{}]: 0, + [undefined]: undefined, + [null]: null +}; diff --git a/tests/baselines/reference/computedPropertyNames6.errors.txt b/tests/baselines/reference/computedPropertyNames6.errors.txt new file mode 100644 index 00000000000..e9e150e2739 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts (3 errors) ==== + var p1: number | string; + var p2: number | number[]; + var p3: string | boolean; + var v = { + [p1]: 0, + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [p2]: 1, + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [p3]: 2 + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames6.js b/tests/baselines/reference/computedPropertyNames6.js new file mode 100644 index 00000000000..e131ef4417f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames6.js @@ -0,0 +1,19 @@ +//// [computedPropertyNames6.ts] +var p1: number | string; +var p2: number | number[]; +var p3: string | boolean; +var v = { + [p1]: 0, + [p2]: 1, + [p3]: 2 +} + +//// [computedPropertyNames6.js] +var p1; +var p2; +var p3; +var v = { + [p1]: 0, + [p2]: 1, + [p3]: 2 +}; diff --git a/tests/baselines/reference/computedPropertyNames7.errors.txt b/tests/baselines/reference/computedPropertyNames7.errors.txt new file mode 100644 index 00000000000..b519369956c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames7.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts (1 errors) ==== + enum E { + member + } + var v = { + [E.member]: 0 + ~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames7.js b/tests/baselines/reference/computedPropertyNames7.js new file mode 100644 index 00000000000..075b149522b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames7.js @@ -0,0 +1,16 @@ +//// [computedPropertyNames7.ts] +enum E { + member +} +var v = { + [E.member]: 0 +} + +//// [computedPropertyNames7.js] +var E; +(function (E) { + E[E["member"] = 0] = "member"; +})(E || (E = {})); +var v = { + [0 /* member */]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNames8.errors.txt b/tests/baselines/reference/computedPropertyNames8.errors.txt new file mode 100644 index 00000000000..99aa43b9276 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames8.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts (2 errors) ==== + function f() { + var t: T; + var u: U; + var v = { + [t]: 0, + ~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [u]: 1 + ~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames8.js b/tests/baselines/reference/computedPropertyNames8.js new file mode 100644 index 00000000000..44a21d79a1c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames8.js @@ -0,0 +1,19 @@ +//// [computedPropertyNames8.ts] +function f() { + var t: T; + var u: U; + var v = { + [t]: 0, + [u]: 1 + }; +} + +//// [computedPropertyNames8.js] +function f() { + var t; + var u; + var v = { + [t]: 0, + [u]: 1 + }; +} diff --git a/tests/baselines/reference/computedPropertyNames9.errors.txt b/tests/baselines/reference/computedPropertyNames9.errors.txt new file mode 100644 index 00000000000..8450e1fd092 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames9.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts(9,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts (1 errors) ==== + function f(s: string): string; + function f(n: number): number; + function f(x: T): T; + function f(x): any { } + + var v = { + [f("")]: 0, + [f(0)]: 0, + [f(true)]: 0 + ~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames9.js b/tests/baselines/reference/computedPropertyNames9.js new file mode 100644 index 00000000000..ede8bb3012b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames9.js @@ -0,0 +1,20 @@ +//// [computedPropertyNames9.ts] +function f(s: string): string; +function f(n: number): number; +function f(x: T): T; +function f(x): any { } + +var v = { + [f("")]: 0, + [f(0)]: 0, + [f(true)]: 0 +} + +//// [computedPropertyNames9.js] +function f(x) { +} +var v = { + [f("")]: 0, + [f(0)]: 0, + [f(true)]: 0 +}; diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts new file mode 100644 index 00000000000..a6d4e17c44a --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts @@ -0,0 +1,17 @@ +// @target: es6 +var s: string; +var n: number; +var a: any; +var v = { + [s]: 0, + [n]: n, + [s + s]: 1, + [s + n]: 2, + [+s]: s, + [""]: 0, + [0]: 0, + [a]: 1, + [true]: 0, + [`hello bye`]: 0, + [`hello ${a} bye`]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts new file mode 100644 index 00000000000..590f819c4e4 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts @@ -0,0 +1,10 @@ +// @target: es6 +var b: boolean; +var v = { + [b]: 0, + [true]: 1, + [[]]: 0, + [{}]: 0, + [undefined]: undefined, + [null]: null +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts new file mode 100644 index 00000000000..b21b76b03f2 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts @@ -0,0 +1,9 @@ +// @target: es6 +var p1: number | string; +var p2: number | number[]; +var p3: string | boolean; +var v = { + [p1]: 0, + [p2]: 1, + [p3]: 2 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts new file mode 100644 index 00000000000..5063d1e2d0c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts @@ -0,0 +1,7 @@ +// @target: es6 +enum E { + member +} +var v = { + [E.member]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts new file mode 100644 index 00000000000..95b6398a62d --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts @@ -0,0 +1,9 @@ +// @target: es6 +function f() { + var t: T; + var u: U; + var v = { + [t]: 0, + [u]: 1 + }; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts new file mode 100644 index 00000000000..21dc4eaa1e9 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts @@ -0,0 +1,11 @@ +// @target: es6 +function f(s: string): string; +function f(n: number): number; +function f(x: T): T; +function f(x): any { } + +var v = { + [f("")]: 0, + [f(0)]: 0, + [f(true)]: 0 +} \ No newline at end of file From 4c0122d879eeb9c2b6517c84b3c0c71e21ad2eb0 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 12 Jan 2015 17:21:55 -0800 Subject: [PATCH 13/71] Move computed property checks so that they will be checked in classes and interfaces --- src/compiler/checker.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 15df97de4c9..e15dcb37d70 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5421,7 +5421,7 @@ module ts { memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment || isObjectLiteralMethod(memberDecl)) { if (memberDecl.kind === SyntaxKind.PropertyAssignment) { - var type = checkExpression((memberDecl).initializer, contextualMapper); + var type = checkPropertyAssignment(memberDecl, contextualMapper); } else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { var type = checkObjectLiteralMethod(memberDecl, contextualMapper); @@ -5454,10 +5454,7 @@ module ts { checkAccessorDeclaration(memberDecl); } - if (hasComputedNameButNotSymbol(memberDecl)) { - checkComputedPropertyName(memberDecl.name); - } - else { + if (!hasComputedNameButNotSymbol(memberDecl)) { properties[member.name] = member; } } @@ -7050,10 +7047,22 @@ module ts { return links.resolvedType; } + function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type { + if (hasComputedNameButNotSymbol(node)) { + checkComputedPropertyName(node.name); + } + + return checkExpression((node).initializer, contextualMapper); + } + function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { // Grammar checking checkGrammarMethod(node); + if (hasComputedNameButNotSymbol(node)) { + checkComputedPropertyName(node.name); + } + var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } @@ -7862,7 +7871,12 @@ module ts { function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { checkSignatureDeclaration(node); - if (!hasComputedNameButNotSymbol(node)) { + if (hasComputedNameButNotSymbol(node)) { + // This check will account for methods in class/interface declarations, + // as well as accessors in classes/object literals + checkComputedPropertyName(node.name); + } + else { // first we want to check the local symbol that contain this declaration // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode @@ -8092,6 +8106,7 @@ module ts { checkSourceElement(node.type); // For a computed property, just check the initializer and exit if (hasComputedNameButNotSymbol(node)) { + checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); } From de3eb36b2cfa0153d5e39bd400d99c55feaa4349 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 13 Jan 2015 10:30:32 -0800 Subject: [PATCH 14/71] Update baselines --- .../MemberFunctionDeclaration3_es6.errors.txt | 5 +- .../reference/complicatedPrivacy.errors.txt | 7 +- .../computedPropertyNames3.errors.txt | 14 +- tests/baselines/reference/giant.errors.txt | 26 ++- ...SignatureMustHaveTypeAnnotation.errors.txt | 18 ++- .../indexSignatureWithInitializer.errors.txt | 13 +- .../indexWithoutParamType2.errors.txt | 8 +- .../reference/intTypeCheck.errors.txt | 150 +++++++++--------- .../parserComputedPropertyName10.errors.txt | 5 +- .../parserComputedPropertyName11.errors.txt | 5 +- .../parserComputedPropertyName12.errors.txt | 9 ++ .../parserComputedPropertyName12.types | 7 - .../parserComputedPropertyName13.errors.txt | 7 +- .../parserComputedPropertyName14.errors.txt | 7 +- .../parserComputedPropertyName15.errors.txt | 7 +- .../parserComputedPropertyName18.errors.txt | 7 +- .../parserComputedPropertyName19.errors.txt | 7 +- .../parserComputedPropertyName20.errors.txt | 5 +- .../parserComputedPropertyName21.errors.txt | 5 +- .../parserComputedPropertyName22.errors.txt | 5 +- .../parserComputedPropertyName23.errors.txt | 5 +- .../parserComputedPropertyName24.errors.txt | 9 ++ .../parserComputedPropertyName24.types | 8 - .../parserComputedPropertyName25.errors.txt | 5 +- .../parserComputedPropertyName27.errors.txt | 5 +- .../parserComputedPropertyName28.errors.txt | 8 +- .../parserComputedPropertyName29.errors.txt | 8 +- .../parserComputedPropertyName31.errors.txt | 8 +- .../parserComputedPropertyName32.errors.txt | 5 +- .../parserComputedPropertyName33.errors.txt | 5 +- .../parserComputedPropertyName36.errors.txt | 5 +- .../parserComputedPropertyName38.errors.txt | 9 ++ .../parserComputedPropertyName38.types | 7 - .../parserComputedPropertyName40.errors.txt | 9 ++ .../parserComputedPropertyName40.types | 8 - .../parserComputedPropertyName7.errors.txt | 5 +- .../parserComputedPropertyName8.errors.txt | 5 +- .../parserComputedPropertyName9.errors.txt | 5 +- .../parserES5ComputedPropertyName1.errors.txt | 5 +- ...parserES5ComputedPropertyName10.errors.txt | 5 +- ...parserES5ComputedPropertyName11.errors.txt | 5 +- .../parserES5ComputedPropertyName5.errors.txt | 5 +- .../parserES5ComputedPropertyName7.errors.txt | 5 +- .../parserES5ComputedPropertyName8.errors.txt | 7 +- .../parserES5ComputedPropertyName9.errors.txt | 5 +- .../parserIndexSignature11.errors.txt | 7 +- .../parserIndexSignature4.errors.txt | 7 +- .../parserIndexSignature5.errors.txt | 7 +- .../reference/propertyAssignment.errors.txt | 7 +- tests/cases/compiler/complicatedPrivacy.ts | 2 +- .../indexSignatureMustHaveTypeAnnotation.ts | 2 + .../compiler/indexSignatureWithInitializer.ts | 1 + .../cases/compiler/indexWithoutParamType2.ts | 1 + tests/cases/compiler/intTypeCheck.ts | 8 +- tests/cases/compiler/propertyAssignment.ts | 2 +- .../IndexSignatures/parserIndexSignature11.ts | 2 +- .../IndexSignatures/parserIndexSignature4.ts | 2 +- .../IndexSignatures/parserIndexSignature5.ts | 2 +- 58 files changed, 356 insertions(+), 167 deletions(-) create mode 100644 tests/baselines/reference/parserComputedPropertyName12.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName12.types create mode 100644 tests/baselines/reference/parserComputedPropertyName24.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName24.types create mode 100644 tests/baselines/reference/parserComputedPropertyName38.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName38.types create mode 100644 tests/baselines/reference/parserComputedPropertyName40.errors.txt delete mode 100644 tests/baselines/reference/parserComputedPropertyName40.types diff --git a/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt index b43e266e2a5..826c1d7fd75 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,6): error TS2304: Cannot find name 'foo'. -==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts (1 errors) ==== +==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts (2 errors) ==== class C { *[foo]() { } ~ !!! error TS9001: Generators are not currently supported. + ~~~ +!!! error TS2304: Cannot find name 'foo'. } \ No newline at end of file diff --git a/tests/baselines/reference/complicatedPrivacy.errors.txt b/tests/baselines/reference/complicatedPrivacy.errors.txt index fd47927f883..5aa399d1d84 100644 --- a/tests/baselines/reference/complicatedPrivacy.errors.txt +++ b/tests/baselines/reference/complicatedPrivacy.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/complicatedPrivacy.ts(24,38): error TS1005: ';' expected. +tests/cases/compiler/complicatedPrivacy.ts(35,6): error TS2304: Cannot find name 'number'. tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' has no exported member 'i6'. -==== tests/cases/compiler/complicatedPrivacy.ts (2 errors) ==== +==== tests/cases/compiler/complicatedPrivacy.ts (3 errors) ==== module m1 { export module m2 { @@ -39,7 +40,9 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' export function f4(arg1: { - [number]: C1; + [number]: C1; // Used to be indexer, now it is a computed property + ~~~~~~ +!!! error TS2304: Cannot find name 'number'. }) { } diff --git a/tests/baselines/reference/computedPropertyNames3.errors.txt b/tests/baselines/reference/computedPropertyNames3.errors.txt index 37a4ddaf1c0..ad98baf6a14 100644 --- a/tests/baselines/reference/computedPropertyNames3.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3.errors.txt @@ -1,18 +1,30 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (2 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (6 errors) ==== var id; class C { [0 + 1]() { } static [() => { }]() { } + ~~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. get [delete id]() { } ~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. set [[0, 1]](v) { } + ~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. static get [""]() { } ~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. + ~~~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. static set [id.toString()](v) { } } \ No newline at end of file diff --git a/tests/baselines/reference/giant.errors.txt b/tests/baselines/reference/giant.errors.txt index fbe05bbfc79..e8c574d2115 100644 --- a/tests/baselines/reference/giant.errors.txt +++ b/tests/baselines/reference/giant.errors.txt @@ -17,6 +17,7 @@ tests/cases/compiler/giant.ts(35,12): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(36,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(61,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(61,6): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(62,5): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(63,6): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(76,5): error TS2386: Overload signatures must all be optional or required. @@ -39,6 +40,7 @@ tests/cases/compiler/giant.ts(99,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(100,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(100,20): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(125,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(125,10): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(126,9): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(127,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(140,9): error TS2386: Overload signatures must all be optional or required. @@ -62,6 +64,7 @@ tests/cases/compiler/giant.ts(178,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(179,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(179,20): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(204,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(204,10): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(205,9): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(206,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(219,9): error TS2386: Overload signatures must all be optional or required. @@ -117,6 +120,7 @@ tests/cases/compiler/giant.ts(293,12): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(294,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(294,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(319,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(319,6): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(320,5): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(321,6): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(334,5): error TS2386: Overload signatures must all be optional or required. @@ -139,6 +143,7 @@ tests/cases/compiler/giant.ts(357,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(358,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(358,20): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(383,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(383,10): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(384,9): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(385,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(398,9): error TS2386: Overload signatures must all be optional or required. @@ -162,6 +167,7 @@ tests/cases/compiler/giant.ts(436,16): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(437,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/giant.ts(437,20): error TS2300: Duplicate identifier 'tgF'. tests/cases/compiler/giant.ts(462,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(462,10): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(463,9): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(464,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(477,9): error TS2386: Overload signatures must all be optional or required. @@ -233,6 +239,7 @@ tests/cases/compiler/giant.ts(558,24): error TS1184: An implementation cannot be tests/cases/compiler/giant.ts(561,21): error TS1184: An implementation cannot be declared in ambient contexts. tests/cases/compiler/giant.ts(563,21): error TS1184: An implementation cannot be declared in ambient contexts. tests/cases/compiler/giant.ts(587,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(587,10): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(588,9): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(589,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(602,9): error TS2386: Overload signatures must all be optional or required. @@ -249,6 +256,7 @@ tests/cases/compiler/giant.ts(623,24): error TS1184: An implementation cannot be tests/cases/compiler/giant.ts(626,21): error TS1184: An implementation cannot be declared in ambient contexts. tests/cases/compiler/giant.ts(628,21): error TS1184: An implementation cannot be declared in ambient contexts. tests/cases/compiler/giant.ts(653,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/giant.ts(653,10): error TS2304: Cannot find name 'p'. tests/cases/compiler/giant.ts(654,9): error TS1021: An index signature must have a type annotation. tests/cases/compiler/giant.ts(655,10): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all be optional or required. @@ -257,7 +265,7 @@ tests/cases/compiler/giant.ts(672,25): error TS1036: Statements are not allowed tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be declared in ambient contexts. -==== tests/cases/compiler/giant.ts (257 errors) ==== +==== tests/cases/compiler/giant.ts (265 errors) ==== /* Prefixes @@ -357,6 +365,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -465,6 +475,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -590,6 +602,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -815,6 +829,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -923,6 +939,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -1048,6 +1066,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -1315,6 +1335,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. @@ -1413,6 +1435,8 @@ tests/cases/compiler/giant.ts(676,30): error TS1184: An implementation cannot be [p]; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. diff --git a/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt b/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt index 294282d1e9e..82e96bf3846 100644 --- a/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt +++ b/tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt @@ -1,23 +1,31 @@ -tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(2,5): error TS1169: Computed property names are not allowed in interfaces. -tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(3,5): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(7,5): error TS1166: Computed property names are not allowed in class property declarations. -tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(12,5): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(3,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(3,6): error TS2304: Cannot find name 'x'. +tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(4,5): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(9,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(9,6): error TS2304: Cannot find name 'x'. +tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(14,5): error TS1021: An index signature must have a type annotation. -==== tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts (4 errors) ==== +==== tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts (6 errors) ==== interface I { + // Used to be indexer, now it is a computed property [x]: string; ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'x'. [x: string]; ~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. } class C { + // Used to be indexer, now it is a computed property [x]: string ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'x'. } diff --git a/tests/baselines/reference/indexSignatureWithInitializer.errors.txt b/tests/baselines/reference/indexSignatureWithInitializer.errors.txt index 6fb708a3b80..d6f547a25cb 100644 --- a/tests/baselines/reference/indexSignatureWithInitializer.errors.txt +++ b/tests/baselines/reference/indexSignatureWithInitializer.errors.txt @@ -1,16 +1,23 @@ -tests/cases/compiler/indexSignatureWithInitializer.ts(2,5): error TS1169: Computed property names are not allowed in interfaces. -tests/cases/compiler/indexSignatureWithInitializer.ts(6,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/compiler/indexSignatureWithInitializer.ts(3,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/compiler/indexSignatureWithInitializer.ts(3,6): error TS2304: Cannot find name 'x'. +tests/cases/compiler/indexSignatureWithInitializer.ts(7,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/compiler/indexSignatureWithInitializer.ts(7,6): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/indexSignatureWithInitializer.ts (2 errors) ==== +==== tests/cases/compiler/indexSignatureWithInitializer.ts (4 errors) ==== + // These used to be indexers, now they are computed properties interface I { [x = '']: string; ~~~~~~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'x'. } class C { [x = 0]: string ~~~~~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'x'. } \ No newline at end of file diff --git a/tests/baselines/reference/indexWithoutParamType2.errors.txt b/tests/baselines/reference/indexWithoutParamType2.errors.txt index 41527d0859f..468368b5f23 100644 --- a/tests/baselines/reference/indexWithoutParamType2.errors.txt +++ b/tests/baselines/reference/indexWithoutParamType2.errors.txt @@ -1,9 +1,13 @@ -tests/cases/compiler/indexWithoutParamType2.ts(2,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/compiler/indexWithoutParamType2.ts(3,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/compiler/indexWithoutParamType2.ts(3,6): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/indexWithoutParamType2.ts (1 errors) ==== +==== tests/cases/compiler/indexWithoutParamType2.ts (2 errors) ==== class C { + // Used to be indexer, now it is a computed property [x]: string ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'x'. } \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 5f7c213a916..bd8b2048045 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -1,91 +1,93 @@ -tests/cases/compiler/intTypeCheck.ts(83,5): error TS2386: Overload signatures must all be optional or required. -tests/cases/compiler/intTypeCheck.ts(97,5): error TS2322: Type 'Object' is not assignable to type 'i1'. +tests/cases/compiler/intTypeCheck.ts(35,6): error TS2304: Cannot find name 'p'. +tests/cases/compiler/intTypeCheck.ts(71,6): error TS2304: Cannot find name 'p'. +tests/cases/compiler/intTypeCheck.ts(85,5): error TS2386: Overload signatures must all be optional or required. +tests/cases/compiler/intTypeCheck.ts(99,5): error TS2322: Type 'Object' is not assignable to type 'i1'. Property 'p' is missing in type 'Object'. -tests/cases/compiler/intTypeCheck.ts(98,16): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(99,5): error TS2322: Type 'Base' is not assignable to type 'i1'. +tests/cases/compiler/intTypeCheck.ts(100,16): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(101,5): error TS2322: Type 'Base' is not assignable to type 'i1'. Property 'p' is missing in type 'Base'. -tests/cases/compiler/intTypeCheck.ts(101,5): error TS2322: Type '() => void' is not assignable to type 'i1'. +tests/cases/compiler/intTypeCheck.ts(103,5): error TS2322: Type '() => void' is not assignable to type 'i1'. Property 'p' is missing in type '() => void'. -tests/cases/compiler/intTypeCheck.ts(104,5): error TS2322: Type 'boolean' is not assignable to type 'i1'. +tests/cases/compiler/intTypeCheck.ts(106,5): error TS2322: Type 'boolean' is not assignable to type 'i1'. Property 'p' is missing in type 'Boolean'. -tests/cases/compiler/intTypeCheck.ts(104,20): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(104,21): error TS2304: Cannot find name 'i1'. -tests/cases/compiler/intTypeCheck.ts(105,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(110,5): error TS2322: Type '{}' is not assignable to type 'i2'. -tests/cases/compiler/intTypeCheck.ts(111,5): error TS2322: Type 'Object' is not assignable to type 'i2'. -tests/cases/compiler/intTypeCheck.ts(112,17): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/compiler/intTypeCheck.ts(113,5): error TS2322: Type 'Base' is not assignable to type 'i2'. -tests/cases/compiler/intTypeCheck.ts(118,5): error TS2322: Type 'boolean' is not assignable to type 'i2'. -tests/cases/compiler/intTypeCheck.ts(118,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(118,22): error TS2304: Cannot find name 'i2'. -tests/cases/compiler/intTypeCheck.ts(119,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(124,5): error TS2322: Type '{}' is not assignable to type 'i3'. -tests/cases/compiler/intTypeCheck.ts(125,5): error TS2322: Type 'Object' is not assignable to type 'i3'. -tests/cases/compiler/intTypeCheck.ts(127,5): error TS2322: Type 'Base' is not assignable to type 'i3'. -tests/cases/compiler/intTypeCheck.ts(129,5): error TS2322: Type '() => void' is not assignable to type 'i3'. -tests/cases/compiler/intTypeCheck.ts(132,5): error TS2322: Type 'boolean' is not assignable to type 'i3'. -tests/cases/compiler/intTypeCheck.ts(132,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(132,22): error TS2304: Cannot find name 'i3'. -tests/cases/compiler/intTypeCheck.ts(133,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(139,5): error TS2322: Type 'Object' is not assignable to type 'i4'. +tests/cases/compiler/intTypeCheck.ts(106,20): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(106,21): error TS2304: Cannot find name 'i1'. +tests/cases/compiler/intTypeCheck.ts(107,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(112,5): error TS2322: Type '{}' is not assignable to type 'i2'. +tests/cases/compiler/intTypeCheck.ts(113,5): error TS2322: Type 'Object' is not assignable to type 'i2'. +tests/cases/compiler/intTypeCheck.ts(114,17): error TS2350: Only a void function can be called with the 'new' keyword. +tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not assignable to type 'i2'. +tests/cases/compiler/intTypeCheck.ts(120,5): error TS2322: Type 'boolean' is not assignable to type 'i2'. +tests/cases/compiler/intTypeCheck.ts(120,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(120,22): error TS2304: Cannot find name 'i2'. +tests/cases/compiler/intTypeCheck.ts(121,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(126,5): error TS2322: Type '{}' is not assignable to type 'i3'. +tests/cases/compiler/intTypeCheck.ts(127,5): error TS2322: Type 'Object' is not assignable to type 'i3'. +tests/cases/compiler/intTypeCheck.ts(129,5): error TS2322: Type 'Base' is not assignable to type 'i3'. +tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is not assignable to type 'i3'. +tests/cases/compiler/intTypeCheck.ts(134,5): error TS2322: Type 'boolean' is not assignable to type 'i3'. +tests/cases/compiler/intTypeCheck.ts(134,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(134,22): error TS2304: Cannot find name 'i3'. +tests/cases/compiler/intTypeCheck.ts(135,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(141,5): error TS2322: Type 'Object' is not assignable to type 'i4'. Index signature is missing in type 'Object'. -tests/cases/compiler/intTypeCheck.ts(140,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(141,5): error TS2322: Type 'Base' is not assignable to type 'i4'. +tests/cases/compiler/intTypeCheck.ts(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(143,5): error TS2322: Type 'Base' is not assignable to type 'i4'. Index signature is missing in type 'Base'. -tests/cases/compiler/intTypeCheck.ts(143,5): error TS2322: Type '() => void' is not assignable to type 'i4'. +tests/cases/compiler/intTypeCheck.ts(145,5): error TS2322: Type '() => void' is not assignable to type 'i4'. Index signature is missing in type '() => void'. -tests/cases/compiler/intTypeCheck.ts(146,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. +tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. Index signature is missing in type 'Boolean'. -tests/cases/compiler/intTypeCheck.ts(146,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(146,22): error TS2304: Cannot find name 'i4'. -tests/cases/compiler/intTypeCheck.ts(147,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(152,5): error TS2322: Type '{}' is not assignable to type 'i5'. +tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(148,22): error TS2304: Cannot find name 'i4'. +tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(154,5): error TS2322: Type '{}' is not assignable to type 'i5'. Property 'p' is missing in type '{}'. -tests/cases/compiler/intTypeCheck.ts(153,5): error TS2322: Type 'Object' is not assignable to type 'i5'. +tests/cases/compiler/intTypeCheck.ts(155,5): error TS2322: Type 'Object' is not assignable to type 'i5'. Property 'p' is missing in type 'Object'. -tests/cases/compiler/intTypeCheck.ts(154,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(155,5): error TS2322: Type 'Base' is not assignable to type 'i5'. +tests/cases/compiler/intTypeCheck.ts(156,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(157,5): error TS2322: Type 'Base' is not assignable to type 'i5'. Property 'p' is missing in type 'Base'. -tests/cases/compiler/intTypeCheck.ts(157,5): error TS2322: Type '() => void' is not assignable to type 'i5'. +tests/cases/compiler/intTypeCheck.ts(159,5): error TS2322: Type '() => void' is not assignable to type 'i5'. Property 'p' is missing in type '() => void'. -tests/cases/compiler/intTypeCheck.ts(160,5): error TS2322: Type 'boolean' is not assignable to type 'i5'. +tests/cases/compiler/intTypeCheck.ts(162,5): error TS2322: Type 'boolean' is not assignable to type 'i5'. Property 'p' is missing in type 'Boolean'. -tests/cases/compiler/intTypeCheck.ts(160,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(160,22): error TS2304: Cannot find name 'i5'. -tests/cases/compiler/intTypeCheck.ts(161,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(166,5): error TS2322: Type '{}' is not assignable to type 'i6'. -tests/cases/compiler/intTypeCheck.ts(167,5): error TS2322: Type 'Object' is not assignable to type 'i6'. -tests/cases/compiler/intTypeCheck.ts(168,17): error TS2350: Only a void function can be called with the 'new' keyword. -tests/cases/compiler/intTypeCheck.ts(169,5): error TS2322: Type 'Base' is not assignable to type 'i6'. -tests/cases/compiler/intTypeCheck.ts(171,5): error TS2322: Type '() => void' is not assignable to type 'i6'. +tests/cases/compiler/intTypeCheck.ts(162,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(162,22): error TS2304: Cannot find name 'i5'. +tests/cases/compiler/intTypeCheck.ts(163,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(168,5): error TS2322: Type '{}' is not assignable to type 'i6'. +tests/cases/compiler/intTypeCheck.ts(169,5): error TS2322: Type 'Object' is not assignable to type 'i6'. +tests/cases/compiler/intTypeCheck.ts(170,17): error TS2350: Only a void function can be called with the 'new' keyword. +tests/cases/compiler/intTypeCheck.ts(171,5): error TS2322: Type 'Base' is not assignable to type 'i6'. +tests/cases/compiler/intTypeCheck.ts(173,5): error TS2322: Type '() => void' is not assignable to type 'i6'. Type 'void' is not assignable to type 'number'. -tests/cases/compiler/intTypeCheck.ts(174,5): error TS2322: Type 'boolean' is not assignable to type 'i6'. -tests/cases/compiler/intTypeCheck.ts(174,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(174,22): error TS2304: Cannot find name 'i6'. -tests/cases/compiler/intTypeCheck.ts(175,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(180,5): error TS2322: Type '{}' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(181,5): error TS2322: Type 'Object' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(183,17): error TS2352: Neither type 'Base' nor type 'i7' is assignable to the other. -tests/cases/compiler/intTypeCheck.ts(185,5): error TS2322: Type '() => void' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(188,5): error TS2322: Type 'boolean' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(188,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(188,22): error TS2304: Cannot find name 'i7'. -tests/cases/compiler/intTypeCheck.ts(189,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(195,5): error TS2322: Type 'Object' is not assignable to type 'i8'. +tests/cases/compiler/intTypeCheck.ts(176,5): error TS2322: Type 'boolean' is not assignable to type 'i6'. +tests/cases/compiler/intTypeCheck.ts(176,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(176,22): error TS2304: Cannot find name 'i6'. +tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'. +tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'. +tests/cases/compiler/intTypeCheck.ts(185,17): error TS2352: Neither type 'Base' nor type 'i7' is assignable to the other. +tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'. +tests/cases/compiler/intTypeCheck.ts(190,5): error TS2322: Type 'boolean' is not assignable to type 'i7'. +tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(190,22): error TS2304: Cannot find name 'i7'. +tests/cases/compiler/intTypeCheck.ts(191,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(197,5): error TS2322: Type 'Object' is not assignable to type 'i8'. Index signature is missing in type 'Object'. -tests/cases/compiler/intTypeCheck.ts(196,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(197,5): error TS2322: Type 'Base' is not assignable to type 'i8'. +tests/cases/compiler/intTypeCheck.ts(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(199,5): error TS2322: Type 'Base' is not assignable to type 'i8'. Index signature is missing in type 'Base'. -tests/cases/compiler/intTypeCheck.ts(199,5): error TS2322: Type '() => void' is not assignable to type 'i8'. +tests/cases/compiler/intTypeCheck.ts(201,5): error TS2322: Type '() => void' is not assignable to type 'i8'. Index signature is missing in type '() => void'. -tests/cases/compiler/intTypeCheck.ts(202,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. +tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. Index signature is missing in type 'Boolean'. -tests/cases/compiler/intTypeCheck.ts(202,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(202,22): error TS2304: Cannot find name 'i8'. -tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected. +tests/cases/compiler/intTypeCheck.ts(204,22): error TS2304: Cannot find name 'i8'. +tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -==== tests/cases/compiler/intTypeCheck.ts (67 errors) ==== +==== tests/cases/compiler/intTypeCheck.ts (69 errors) ==== interface i1 { //Property Signatures p; @@ -119,8 +121,11 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit new (p6: string, ...p7: any[]); } interface i4 { - //Index Signatures + // Used to be indexer, now it is a computed property [p]; + ~ +!!! error TS2304: Cannot find name 'p'. + //Index Signatures [p1: string]; [p2: string, p3: number]; } @@ -153,9 +158,12 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit new (...p3: any[]); new (p4: string, p5?: string); new (p6: string, ...p7: any[]); - - //Index Signatures + + // Used to be indexer, now it is a computed property [p]; + ~ +!!! error TS2304: Cannot find name 'p'. + //Index Signatures [p1: string]; [p2: string, p3: number]; diff --git a/tests/baselines/reference/parserComputedPropertyName10.errors.txt b/tests/baselines/reference/parserComputedPropertyName10.errors.txt index 704c37ebf45..061e2c40c2d 100644 --- a/tests/baselines/reference/parserComputedPropertyName10.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName10.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName10.ts(2,4): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName10.ts(2,5): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName10.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName10.ts (2 errors) ==== class C { [e] = 1 ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName11.errors.txt b/tests/baselines/reference/parserComputedPropertyName11.errors.txt index f47aa75031d..65748f72b24 100644 --- a/tests/baselines/reference/parserComputedPropertyName11.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName11.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName11.ts(2,4): error TS1168: Computed property names are not allowed in method overloads. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName11.ts(2,5): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName11.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName11.ts (2 errors) ==== class C { [e](); ~~~ !!! error TS1168: Computed property names are not allowed in method overloads. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName12.errors.txt b/tests/baselines/reference/parserComputedPropertyName12.errors.txt new file mode 100644 index 00000000000..46baacf402d --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName12.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName12.ts(2,5): error TS2304: Cannot find name 'e'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName12.ts (1 errors) ==== + class C { + [e]() { } + ~ +!!! error TS2304: Cannot find name 'e'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName12.types b/tests/baselines/reference/parserComputedPropertyName12.types deleted file mode 100644 index fcc96bc4d51..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName12.types +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName12.ts === -class C { ->C : C - - [e]() { } ->e : unknown -} diff --git a/tests/baselines/reference/parserComputedPropertyName13.errors.txt b/tests/baselines/reference/parserComputedPropertyName13.errors.txt index 33ef5f9141a..b209f3c7d01 100644 --- a/tests/baselines/reference/parserComputedPropertyName13.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName13.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName13.ts(1,10): error TS1170: Computed property names are not allowed in type literals. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName13.ts(1,11): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName13.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName13.ts (2 errors) ==== var v: { [e]: number }; ~~~ -!!! error TS1170: Computed property names are not allowed in type literals. \ No newline at end of file +!!! error TS1170: Computed property names are not allowed in type literals. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName14.errors.txt b/tests/baselines/reference/parserComputedPropertyName14.errors.txt index d2f7ad34ed9..6ac2d276a80 100644 --- a/tests/baselines/reference/parserComputedPropertyName14.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName14.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName14.ts(1,10): error TS1170: Computed property names are not allowed in type literals. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName14.ts(1,11): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName14.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName14.ts (2 errors) ==== var v: { [e](): number }; ~~~ -!!! error TS1170: Computed property names are not allowed in type literals. \ No newline at end of file +!!! error TS1170: Computed property names are not allowed in type literals. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName15.errors.txt b/tests/baselines/reference/parserComputedPropertyName15.errors.txt index b09ddb73112..f66e5930c26 100644 --- a/tests/baselines/reference/parserComputedPropertyName15.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName15.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName15.ts(1,31): error TS1170: Computed property names are not allowed in type literals. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName15.ts(1,32): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName15.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName15.ts (2 errors) ==== var v: { [e: number]: string; [e]: number }; ~~~ -!!! error TS1170: Computed property names are not allowed in type literals. \ No newline at end of file +!!! error TS1170: Computed property names are not allowed in type literals. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName18.errors.txt b/tests/baselines/reference/parserComputedPropertyName18.errors.txt index 72833dda837..f7485a127cb 100644 --- a/tests/baselines/reference/parserComputedPropertyName18.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName18.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName18.ts(1,10): error TS1170: Computed property names are not allowed in type literals. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName18.ts(1,11): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName18.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName18.ts (2 errors) ==== var v: { [e]?(): number }; ~~~ -!!! error TS1170: Computed property names are not allowed in type literals. \ No newline at end of file +!!! error TS1170: Computed property names are not allowed in type literals. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName19.errors.txt b/tests/baselines/reference/parserComputedPropertyName19.errors.txt index 22dbfff3c61..65c22ff36c3 100644 --- a/tests/baselines/reference/parserComputedPropertyName19.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName19.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName19.ts(1,10): error TS1170: Computed property names are not allowed in type literals. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName19.ts(1,11): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName19.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName19.ts (2 errors) ==== var v: { [e]? }; ~~~ -!!! error TS1170: Computed property names are not allowed in type literals. \ No newline at end of file +!!! error TS1170: Computed property names are not allowed in type literals. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName20.errors.txt b/tests/baselines/reference/parserComputedPropertyName20.errors.txt index 36a7e2d4866..d65dfede1d2 100644 --- a/tests/baselines/reference/parserComputedPropertyName20.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName20.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName20.ts(2,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName20.ts(2,6): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName20.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName20.ts (2 errors) ==== interface I { [e](): number ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName21.errors.txt b/tests/baselines/reference/parserComputedPropertyName21.errors.txt index 5850de24b76..5a9738a23a6 100644 --- a/tests/baselines/reference/parserComputedPropertyName21.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName21.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName21.ts(2,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName21.ts(2,6): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName21.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName21.ts (2 errors) ==== interface I { [e]: number ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName22.errors.txt b/tests/baselines/reference/parserComputedPropertyName22.errors.txt index 5149c937108..ce20dd0c587 100644 --- a/tests/baselines/reference/parserComputedPropertyName22.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName22.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName22.ts(2,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName22.ts(2,6): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName22.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName22.ts (2 errors) ==== declare class C { [e]: number ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName23.errors.txt b/tests/baselines/reference/parserComputedPropertyName23.errors.txt index 2018032ef94..8c95992253c 100644 --- a/tests/baselines/reference/parserComputedPropertyName23.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName23.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts(2,9): error TS1086: An accessor cannot be declared in an ambient context. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts(2,10): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts (2 errors) ==== declare class C { get [e](): number ~~~ !!! error TS1086: An accessor cannot be declared in an ambient context. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName24.errors.txt b/tests/baselines/reference/parserComputedPropertyName24.errors.txt new file mode 100644 index 00000000000..29bcb05ea0f --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName24.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName24.ts(2,10): error TS2304: Cannot find name 'e'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName24.ts (1 errors) ==== + class C { + set [e](v) { } + ~ +!!! error TS2304: Cannot find name 'e'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName24.types b/tests/baselines/reference/parserComputedPropertyName24.types deleted file mode 100644 index d2de5244057..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName24.types +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName24.ts === -class C { ->C : C - - set [e](v) { } ->e : unknown ->v : any -} diff --git a/tests/baselines/reference/parserComputedPropertyName25.errors.txt b/tests/baselines/reference/parserComputedPropertyName25.errors.txt index c8dd6b3bc7c..8d26c8afdb7 100644 --- a/tests/baselines/reference/parserComputedPropertyName25.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName25.errors.txt @@ -1,13 +1,16 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName25.ts(3,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName25.ts(3,6): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName25.ts(4,6): error TS2304: Cannot find name 'e2'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName25.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName25.ts (3 errors) ==== class C { // No ASI [e] = 0 ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. [e2] = 1 ~~ !!! error TS2304: Cannot find name 'e2'. diff --git a/tests/baselines/reference/parserComputedPropertyName27.errors.txt b/tests/baselines/reference/parserComputedPropertyName27.errors.txt index 7c8e30bf25d..3792cf0eccd 100644 --- a/tests/baselines/reference/parserComputedPropertyName27.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName27.errors.txt @@ -1,11 +1,14 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName27.ts(3,6): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName27.ts(4,6): error TS2304: Cannot find name 'e2'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName27.ts(4,9): error TS1005: ';' expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName27.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName27.ts (3 errors) ==== class C { // No ASI [e]: number = 0 + ~ +!!! error TS2304: Cannot find name 'e'. [e2]: number ~~ !!! error TS2304: Cannot find name 'e2'. diff --git a/tests/baselines/reference/parserComputedPropertyName28.errors.txt b/tests/baselines/reference/parserComputedPropertyName28.errors.txt index bc32f34c151..c522ec031eb 100644 --- a/tests/baselines/reference/parserComputedPropertyName28.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName28.errors.txt @@ -1,13 +1,19 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName28.ts(2,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName28.ts(2,6): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName28.ts(3,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName28.ts(3,6): error TS2304: Cannot find name 'e2'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName28.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName28.ts (4 errors) ==== class C { [e]: number = 0; ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. [e2]: number ~~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~~ +!!! error TS2304: Cannot find name 'e2'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName29.errors.txt b/tests/baselines/reference/parserComputedPropertyName29.errors.txt index 691a240375a..5e6baed0f06 100644 --- a/tests/baselines/reference/parserComputedPropertyName29.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName29.errors.txt @@ -1,17 +1,23 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts(3,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts(3,6): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts(3,11): error TS2304: Cannot find name 'id'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts(4,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts(4,6): error TS2304: Cannot find name 'e2'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName29.ts (5 errors) ==== class C { // yes ASI [e] = id++ ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. ~~ !!! error TS2304: Cannot find name 'id'. [e2]: number ~~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~~ +!!! error TS2304: Cannot find name 'e2'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName31.errors.txt b/tests/baselines/reference/parserComputedPropertyName31.errors.txt index 6dddbd859c9..97a3b1ee187 100644 --- a/tests/baselines/reference/parserComputedPropertyName31.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName31.errors.txt @@ -1,14 +1,20 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts(3,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts(3,6): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts(4,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts(4,6): error TS2304: Cannot find name 'e2'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts (4 errors) ==== class C { // yes ASI [e]: number ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. [e2]: number ~~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~~ +!!! error TS2304: Cannot find name 'e2'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName32.errors.txt b/tests/baselines/reference/parserComputedPropertyName32.errors.txt index 4407014cf99..da423baaa05 100644 --- a/tests/baselines/reference/parserComputedPropertyName32.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName32.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName32.ts(2,5): error TS1165: Computed property names are not allowed in an ambient context. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName32.ts(2,6): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName32.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName32.ts (2 errors) ==== declare class C { [e](): number ~~~ !!! error TS1165: Computed property names are not allowed in an ambient context. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName33.errors.txt b/tests/baselines/reference/parserComputedPropertyName33.errors.txt index d56ee49863f..5ce420ceb60 100644 --- a/tests/baselines/reference/parserComputedPropertyName33.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName33.errors.txt @@ -1,12 +1,15 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(3,6): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(4,6): error TS2304: Cannot find name 'e2'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(4,12): error TS1005: ';' expected. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts(5,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName33.ts (4 errors) ==== class C { // No ASI [e] = 0 + ~ +!!! error TS2304: Cannot find name 'e'. [e2]() { } ~~ !!! error TS2304: Cannot find name 'e2'. diff --git a/tests/baselines/reference/parserComputedPropertyName36.errors.txt b/tests/baselines/reference/parserComputedPropertyName36.errors.txt index d10d826d1a9..1b4130b0e27 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName36.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS2304: Cannot find name 'public'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (2 errors) ==== class C { [public ]: string; ~~~~~~~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.errors.txt b/tests/baselines/reference/parserComputedPropertyName38.errors.txt new file mode 100644 index 00000000000..4322abf44ed --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName38.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS2304: Cannot find name 'public'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (1 errors) ==== + class C { + [public]() { } + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.types b/tests/baselines/reference/parserComputedPropertyName38.types deleted file mode 100644 index c77b9fcc67f..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName38.types +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts === -class C { ->C : C - - [public]() { } ->public : unknown -} diff --git a/tests/baselines/reference/parserComputedPropertyName40.errors.txt b/tests/baselines/reference/parserComputedPropertyName40.errors.txt new file mode 100644 index 00000000000..862836ae47d --- /dev/null +++ b/tests/baselines/reference/parserComputedPropertyName40.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts(2,6): error TS2304: Cannot find name 'a'. + + +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts (1 errors) ==== + class C { + [a ? "" : ""]() {} + ~ +!!! error TS2304: Cannot find name 'a'. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName40.types b/tests/baselines/reference/parserComputedPropertyName40.types deleted file mode 100644 index 1b0b3ae49f0..00000000000 --- a/tests/baselines/reference/parserComputedPropertyName40.types +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts === -class C { ->C : C - - [a ? "" : ""]() {} ->a ? "" : "" : string ->a : unknown -} diff --git a/tests/baselines/reference/parserComputedPropertyName7.errors.txt b/tests/baselines/reference/parserComputedPropertyName7.errors.txt index 21147be3074..bcf39b0ca0a 100644 --- a/tests/baselines/reference/parserComputedPropertyName7.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName7.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName7.ts(2,4): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName7.ts(2,5): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName7.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName7.ts (2 errors) ==== class C { [e] ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName8.errors.txt b/tests/baselines/reference/parserComputedPropertyName8.errors.txt index 75352ec9e51..250c7a52c6e 100644 --- a/tests/baselines/reference/parserComputedPropertyName8.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName8.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName8.ts(2,11): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName8.ts(2,12): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName8.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName8.ts (2 errors) ==== class C { public [e] ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName9.errors.txt b/tests/baselines/reference/parserComputedPropertyName9.errors.txt index eb5cfd28d73..fd434046564 100644 --- a/tests/baselines/reference/parserComputedPropertyName9.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName9.errors.txt @@ -1,12 +1,15 @@ tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName9.ts(2,4): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName9.ts(2,5): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName9.ts(2,9): error TS2304: Cannot find name 'Type'. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName9.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName9.ts (3 errors) ==== class C { [e]: Type ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. ~~~~ !!! error TS2304: Cannot find name 'Type'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName1.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName1.errors.txt index 5bae79b95aa..55af923e54b 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName1.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName1.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName1.ts(2,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName1.ts(2,6): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName1.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName1.ts (2 errors) ==== declare class C { [e]: number ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName10.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName10.errors.txt index 40bec1b4f38..7db85cdef35 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName10.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName10.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName10.ts(2,4): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName10.ts(2,5): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName10.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName10.ts (2 errors) ==== class C { [e] = 1 ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName11.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName11.errors.txt index 124db7da75a..ead27a994d1 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName11.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName11.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName11.ts(2,4): error TS1168: Computed property names are not allowed in method overloads. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName11.ts(2,5): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName11.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName11.ts (2 errors) ==== class C { [e](); ~~~ !!! error TS1168: Computed property names are not allowed in method overloads. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName5.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName5.errors.txt index 8eeeef1516f..122ca20a0e4 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName5.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName5.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName5.ts(2,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName5.ts(2,6): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName5.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName5.ts (2 errors) ==== interface I { [e]: number ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName7.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName7.errors.txt index 6aefd27ef58..d38d57d87be 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName7.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName7.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName7.ts(2,4): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName7.ts(2,5): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName7.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName7.ts (2 errors) ==== class C { [e] ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName8.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName8.errors.txt index 4595081c145..e52727c6929 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName8.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName8.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName8.ts(1,10): error TS1170: Computed property names are not allowed in type literals. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName8.ts(1,11): error TS2304: Cannot find name 'e'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName8.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName8.ts (2 errors) ==== var v: { [e]: number }; ~~~ -!!! error TS1170: Computed property names are not allowed in type literals. \ No newline at end of file +!!! error TS1170: Computed property names are not allowed in type literals. + ~ +!!! error TS2304: Cannot find name 'e'. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName9.errors.txt b/tests/baselines/reference/parserES5ComputedPropertyName9.errors.txt index 6d035a7c610..8cbe0ffcf8d 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName9.errors.txt +++ b/tests/baselines/reference/parserES5ComputedPropertyName9.errors.txt @@ -1,12 +1,15 @@ tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName9.ts(2,4): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName9.ts(2,5): error TS2304: Cannot find name 'e'. tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName9.ts(2,9): error TS2304: Cannot find name 'Type'. -==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName9.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName9.ts (3 errors) ==== class C { [e]: Type ~~~ !!! error TS1166: Computed property names are not allowed in class property declarations. + ~ +!!! error TS2304: Cannot find name 'e'. ~~~~ !!! error TS2304: Cannot find name 'Type'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexSignature11.errors.txt b/tests/baselines/reference/parserIndexSignature11.errors.txt index c9976e2bc4a..8cf474b19bb 100644 --- a/tests/baselines/reference/parserIndexSignature11.errors.txt +++ b/tests/baselines/reference/parserIndexSignature11.errors.txt @@ -1,13 +1,16 @@ tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts(2,9): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts(2,10): error TS2304: Cannot find name 'p'. tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts(3,9): error TS1021: An index signature must have a type annotation. tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts(4,10): error TS1096: An index signature must have exactly one parameter. -==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts (4 errors) ==== interface I { - [p]; + [p]; // Used to be indexer, now it is a computed property ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'p'. [p1: string]; ~~~~~~~~~~~~~ !!! error TS1021: An index signature must have a type annotation. diff --git a/tests/baselines/reference/parserIndexSignature4.errors.txt b/tests/baselines/reference/parserIndexSignature4.errors.txt index 0f11eb17f3c..d625f27eb6f 100644 --- a/tests/baselines/reference/parserIndexSignature4.errors.txt +++ b/tests/baselines/reference/parserIndexSignature4.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts(2,3): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts(2,4): error TS2304: Cannot find name 'a'. -==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts (2 errors) ==== interface I { - [a = 0] + [a = 0] // Used to be indexer, now it is a computed property ~~~~~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'a'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexSignature5.errors.txt b/tests/baselines/reference/parserIndexSignature5.errors.txt index 6400383f9d2..3f3415973d9 100644 --- a/tests/baselines/reference/parserIndexSignature5.errors.txt +++ b/tests/baselines/reference/parserIndexSignature5.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts(2,3): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts(2,4): error TS2304: Cannot find name 'a'. -==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts (2 errors) ==== interface I { - [a] + [a] // Used to be indexer, now it is a computed property ~~~ !!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2304: Cannot find name 'a'. } \ No newline at end of file diff --git a/tests/baselines/reference/propertyAssignment.errors.txt b/tests/baselines/reference/propertyAssignment.errors.txt index 2ea55a1a2d3..51850754a9a 100644 --- a/tests/baselines/reference/propertyAssignment.errors.txt +++ b/tests/baselines/reference/propertyAssignment.errors.txt @@ -1,17 +1,20 @@ tests/cases/compiler/propertyAssignment.ts(6,13): error TS1170: Computed property names are not allowed in type literals. +tests/cases/compiler/propertyAssignment.ts(6,14): error TS2304: Cannot find name 'index'. tests/cases/compiler/propertyAssignment.ts(14,1): error TS2322: Type '{ x: number; }' is not assignable to type 'new () => any'. tests/cases/compiler/propertyAssignment.ts(16,1): error TS2322: Type '{ x: number; }' is not assignable to type '() => void'. -==== tests/cases/compiler/propertyAssignment.ts (3 errors) ==== +==== tests/cases/compiler/propertyAssignment.ts (4 errors) ==== var foo1: { new ():any; } var bar1: { x : number; } - var foo2: { [index]; } // should be an error + var foo2: { [index]; } // should be an error, used to be indexer, now it is a computed property ~~~~~~~ !!! error TS1170: Computed property names are not allowed in type literals. + ~~~~~ +!!! error TS2304: Cannot find name 'index'. var bar2: { x : number; } var foo3: { ():void; } diff --git a/tests/cases/compiler/complicatedPrivacy.ts b/tests/cases/compiler/complicatedPrivacy.ts index 6c1e3fa8527..6fe144d237c 100644 --- a/tests/cases/compiler/complicatedPrivacy.ts +++ b/tests/cases/compiler/complicatedPrivacy.ts @@ -33,7 +33,7 @@ module m1 { export function f4(arg1: { - [number]: C1; + [number]: C1; // Used to be indexer, now it is a computed property }) { } diff --git a/tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts b/tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts index fbe24e975e9..47d818065a1 100644 --- a/tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts +++ b/tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts @@ -1,9 +1,11 @@ interface I { + // Used to be indexer, now it is a computed property [x]: string; [x: string]; } class C { + // Used to be indexer, now it is a computed property [x]: string } diff --git a/tests/cases/compiler/indexSignatureWithInitializer.ts b/tests/cases/compiler/indexSignatureWithInitializer.ts index a7b185eee0e..f9a4aafc699 100644 --- a/tests/cases/compiler/indexSignatureWithInitializer.ts +++ b/tests/cases/compiler/indexSignatureWithInitializer.ts @@ -1,3 +1,4 @@ +// These used to be indexers, now they are computed properties interface I { [x = '']: string; } diff --git a/tests/cases/compiler/indexWithoutParamType2.ts b/tests/cases/compiler/indexWithoutParamType2.ts index 9a1976fe9ef..0def5dc06a9 100644 --- a/tests/cases/compiler/indexWithoutParamType2.ts +++ b/tests/cases/compiler/indexWithoutParamType2.ts @@ -1,3 +1,4 @@ class C { + // Used to be indexer, now it is a computed property [x]: string } \ No newline at end of file diff --git a/tests/cases/compiler/intTypeCheck.ts b/tests/cases/compiler/intTypeCheck.ts index 787dc944c43..a1563097863 100644 --- a/tests/cases/compiler/intTypeCheck.ts +++ b/tests/cases/compiler/intTypeCheck.ts @@ -31,8 +31,9 @@ interface i3 { new (p6: string, ...p7: any[]); } interface i4 { - //Index Signatures + // Used to be indexer, now it is a computed property [p]; + //Index Signatures [p1: string]; [p2: string, p3: number]; } @@ -65,9 +66,10 @@ interface i11 { new (...p3: any[]); new (p4: string, p5?: string); new (p6: string, ...p7: any[]); - - //Index Signatures + + // Used to be indexer, now it is a computed property [p]; + //Index Signatures [p1: string]; [p2: string, p3: number]; diff --git a/tests/cases/compiler/propertyAssignment.ts b/tests/cases/compiler/propertyAssignment.ts index 0afb8fb60a7..0c8351fb05d 100644 --- a/tests/cases/compiler/propertyAssignment.ts +++ b/tests/cases/compiler/propertyAssignment.ts @@ -3,7 +3,7 @@ var foo1: { new ():any; } var bar1: { x : number; } -var foo2: { [index]; } // should be an error +var foo2: { [index]; } // should be an error, used to be indexer, now it is a computed property var bar2: { x : number; } var foo3: { ():void; } diff --git a/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts b/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts index 4ef57a277ac..1c78f24a213 100644 --- a/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts +++ b/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature11.ts @@ -1,5 +1,5 @@ interface I { - [p]; + [p]; // Used to be indexer, now it is a computed property [p1: string]; [p2: string, p3: number]; } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts b/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts index a12f8aecf21..a6cf3a720a9 100644 --- a/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts +++ b/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts @@ -1,3 +1,3 @@ interface I { - [a = 0] + [a = 0] // Used to be indexer, now it is a computed property } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts b/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts index 5970ab6d8fb..e77c8fe9bb0 100644 --- a/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts +++ b/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature5.ts @@ -1,3 +1,3 @@ interface I { - [a] + [a] // Used to be indexer, now it is a computed property } \ No newline at end of file From 96b5f1fe431673619d0559d96b17afe22dc0d0aa Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 13 Jan 2015 16:10:24 -0800 Subject: [PATCH 15/71] Add tests for classes, methods, accessors with computed properties --- .../reference/computedPropertyNames10.js | 46 +++++++++ .../reference/computedPropertyNames10.types | 46 +++++++++ .../reference/computedPropertyNames11.js | 52 ++++++++++ .../reference/computedPropertyNames11.types | 53 ++++++++++ .../computedPropertyNames12.errors.txt | 52 ++++++++++ .../reference/computedPropertyNames13.js | 49 +++++++++ .../reference/computedPropertyNames13.types | 45 +++++++++ .../computedPropertyNames14.errors.txt | 30 ++++++ .../reference/computedPropertyNames14.js | 30 ++++++ .../computedPropertyNames15.errors.txt | 20 ++++ .../reference/computedPropertyNames15.js | 25 +++++ .../reference/computedPropertyNames16.js | 99 +++++++++++++++++++ .../reference/computedPropertyNames16.types | 52 ++++++++++ .../computedPropertyNames17.errors.txt | 30 ++++++ .../reference/computedPropertyNames17.js | 57 +++++++++++ .../computedPropertyNames10.ts | 17 ++++ .../computedPropertyNames11.ts | 17 ++++ .../computedPropertyNames12.ts | 17 ++++ .../computedPropertyNames13.ts | 17 ++++ .../computedPropertyNames14.ts | 10 ++ .../computedPropertyNames15.ts | 9 ++ .../computedPropertyNames16.ts | 17 ++++ .../computedPropertyNames17.ts | 10 ++ 23 files changed, 800 insertions(+) create mode 100644 tests/baselines/reference/computedPropertyNames10.js create mode 100644 tests/baselines/reference/computedPropertyNames10.types create mode 100644 tests/baselines/reference/computedPropertyNames11.js create mode 100644 tests/baselines/reference/computedPropertyNames11.types create mode 100644 tests/baselines/reference/computedPropertyNames12.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames13.js create mode 100644 tests/baselines/reference/computedPropertyNames13.types create mode 100644 tests/baselines/reference/computedPropertyNames14.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames14.js create mode 100644 tests/baselines/reference/computedPropertyNames15.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames15.js create mode 100644 tests/baselines/reference/computedPropertyNames16.js create mode 100644 tests/baselines/reference/computedPropertyNames16.types create mode 100644 tests/baselines/reference/computedPropertyNames17.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames17.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts diff --git a/tests/baselines/reference/computedPropertyNames10.js b/tests/baselines/reference/computedPropertyNames10.js new file mode 100644 index 00000000000..138cbd7a4b2 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames10.js @@ -0,0 +1,46 @@ +//// [computedPropertyNames10.ts] +var s: string; +var n: number; +var a: any; +var v = { + [s]() { }, + [n]() { }, + [s + s]() { }, + [s + n]() { }, + [+s]() { }, + [""]() { }, + [0]() { }, + [a]() { }, + [true]() { }, + [`hello bye`]() { }, + [`hello ${a} bye`]() { } +} + +//// [computedPropertyNames10.js] +var s; +var n; +var a; +var v = { + [s]() { + }, + [n]() { + }, + [s + s]() { + }, + [s + n]() { + }, + [+s]() { + }, + [""]() { + }, + [0]() { + }, + [a]() { + }, + [true]() { + }, + [`hello bye`]() { + }, + [`hello ${a} bye`]() { + } +}; diff --git a/tests/baselines/reference/computedPropertyNames10.types b/tests/baselines/reference/computedPropertyNames10.types new file mode 100644 index 00000000000..29bf6c43bef --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames10.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts === +var s: string; +>s : string + +var n: number; +>n : number + +var a: any; +>a : any + +var v = { +>v : {} +>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : {} + + [s]() { }, +>s : string + + [n]() { }, +>n : number + + [s + s]() { }, +>s + s : string +>s : string +>s : string + + [s + n]() { }, +>s + n : string +>s : string +>n : number + + [+s]() { }, +>+s : number +>s : string + + [""]() { }, + [0]() { }, + [a]() { }, +>a : any + + [true]() { }, +>true : any + + [`hello bye`]() { }, + [`hello ${a} bye`]() { } +>a : any +} diff --git a/tests/baselines/reference/computedPropertyNames11.js b/tests/baselines/reference/computedPropertyNames11.js new file mode 100644 index 00000000000..d82a7c4e512 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames11.js @@ -0,0 +1,52 @@ +//// [computedPropertyNames11.ts] +var s: string; +var n: number; +var a: any; +var v = { + get [s]() { return 0; }, + set [n](v) { }, + get [s + s]() { return 0; }, + set [s + n](v) { }, + get [+s]() { return 0; }, + set [""](v) { }, + get [0]() { return 0; }, + set [a](v) { }, + get [true]() { return 0; }, + set [`hello bye`](v) { }, + get [`hello ${a} bye`]() { return 0; } +} + +//// [computedPropertyNames11.js] +var s; +var n; +var a; +var v = { + get [s]() { + return 0; + }, + set [n](v) { + }, + get [s + s]() { + return 0; + }, + set [s + n](v) { + }, + get [+s]() { + return 0; + }, + set [""](v) { + }, + get [0]() { + return 0; + }, + set [a](v) { + }, + get [true]() { + return 0; + }, + set [`hello bye`](v) { + }, + get [`hello ${a} bye`]() { + return 0; + } +}; diff --git a/tests/baselines/reference/computedPropertyNames11.types b/tests/baselines/reference/computedPropertyNames11.types new file mode 100644 index 00000000000..ee0796320d6 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames11.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts === +var s: string; +>s : string + +var n: number; +>n : number + +var a: any; +>a : any + +var v = { +>v : {} +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : {} + + get [s]() { return 0; }, +>s : string + + set [n](v) { }, +>n : number +>v : any + + get [s + s]() { return 0; }, +>s + s : string +>s : string +>s : string + + set [s + n](v) { }, +>s + n : string +>s : string +>n : number +>v : any + + get [+s]() { return 0; }, +>+s : number +>s : string + + set [""](v) { }, +>v : any + + get [0]() { return 0; }, + set [a](v) { }, +>a : any +>v : any + + get [true]() { return 0; }, +>true : any + + set [`hello bye`](v) { }, +>v : any + + get [`hello ${a} bye`]() { return 0; } +>a : any +} diff --git a/tests/baselines/reference/computedPropertyNames12.errors.txt b/tests/baselines/reference/computedPropertyNames12.errors.txt new file mode 100644 index 00000000000..56774fe8dae --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames12.errors.txt @@ -0,0 +1,52 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(5,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(6,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(7,12): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(8,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(9,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(10,12): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(11,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(12,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(13,12): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(14,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(15,12): error TS1166: Computed property names are not allowed in class property declarations. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts (11 errors) ==== + var s: string; + var n: number; + var a: any; + class C { + [s]: number; + ~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + [n] = n; + ~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + static [s + s]: string; + ~~~~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + [s + n] = 2; + ~~~~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + [+s]: typeof s; + ~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + static [""]: number; + ~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + [0]: number; + ~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + [a]: number; + ~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + static [true]: number; + ~~~~~~~~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + [`hello bye`] = 0; + ~~~~~~~~~~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + static [`hello ${a} bye`] = 0 + ~~~~~~~~~~~~~~~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames13.js b/tests/baselines/reference/computedPropertyNames13.js new file mode 100644 index 00000000000..ea531a9c644 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames13.js @@ -0,0 +1,49 @@ +//// [computedPropertyNames13.ts] +var s: string; +var n: number; +var a: any; +class C { + [s]() {} + [n]() { } + static [s + s]() { } + [s + n]() { } + [+s]() { } + static [""]() { } + [0]() { } + [a]() { } + static [true]() { } + [`hello bye`]() { } + static [`hello ${a} bye`]() { } +} + +//// [computedPropertyNames13.js] +var s; +var n; +var a; +var C = (function () { + function C() { + } + C.prototype[s] = function () { + }; + C.prototype[n] = function () { + }; + C[s + s] = function () { + }; + C.prototype[s + n] = function () { + }; + C.prototype[+s] = function () { + }; + C[""] = function () { + }; + C.prototype[0] = function () { + }; + C.prototype[a] = function () { + }; + C[true] = function () { + }; + C.prototype[`hello bye`] = function () { + }; + C[`hello ${a} bye`] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames13.types b/tests/baselines/reference/computedPropertyNames13.types new file mode 100644 index 00000000000..4f267f2e893 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames13.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts === +var s: string; +>s : string + +var n: number; +>n : number + +var a: any; +>a : any + +class C { +>C : C + + [s]() {} +>s : string + + [n]() { } +>n : number + + static [s + s]() { } +>s + s : string +>s : string +>s : string + + [s + n]() { } +>s + n : string +>s : string +>n : number + + [+s]() { } +>+s : number +>s : string + + static [""]() { } + [0]() { } + [a]() { } +>a : any + + static [true]() { } +>true : any + + [`hello bye`]() { } + static [`hello ${a} bye`]() { } +>a : any +} diff --git a/tests/baselines/reference/computedPropertyNames14.errors.txt b/tests/baselines/reference/computedPropertyNames14.errors.txt new file mode 100644 index 00000000000..fe38166f9ab --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames14.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(4,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(6,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(8,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts (6 errors) ==== + var b: boolean; + class C { + [b]() {} + ~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + static [true]() { } + ~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [[]]() { } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + static [{}]() { } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [undefined]() { } + ~~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + static [null]() { } + ~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames14.js b/tests/baselines/reference/computedPropertyNames14.js new file mode 100644 index 00000000000..aa551795da6 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames14.js @@ -0,0 +1,30 @@ +//// [computedPropertyNames14.ts] +var b: boolean; +class C { + [b]() {} + static [true]() { } + [[]]() { } + static [{}]() { } + [undefined]() { } + static [null]() { } +} + +//// [computedPropertyNames14.js] +var b; +var C = (function () { + function C() { + } + C.prototype[b] = function () { + }; + C[true] = function () { + }; + C.prototype[[]] = function () { + }; + C[{}] = function () { + }; + C.prototype[undefined] = function () { + }; + C[null] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames15.errors.txt b/tests/baselines/reference/computedPropertyNames15.errors.txt new file mode 100644 index 00000000000..ee8d5b96bca --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames15.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts (3 errors) ==== + var p1: number | string; + var p2: number | number[]; + var p3: string | boolean; + class C { + [p1]() { } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [p2]() { } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + [p3]() { } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames15.js b/tests/baselines/reference/computedPropertyNames15.js new file mode 100644 index 00000000000..1b506bbeb90 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames15.js @@ -0,0 +1,25 @@ +//// [computedPropertyNames15.ts] +var p1: number | string; +var p2: number | number[]; +var p3: string | boolean; +class C { + [p1]() { } + [p2]() { } + [p3]() { } +} + +//// [computedPropertyNames15.js] +var p1; +var p2; +var p3; +var C = (function () { + function C() { + } + C.prototype[p1] = function () { + }; + C.prototype[p2] = function () { + }; + C.prototype[p3] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames16.js b/tests/baselines/reference/computedPropertyNames16.js new file mode 100644 index 00000000000..295deb9ee82 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames16.js @@ -0,0 +1,99 @@ +//// [computedPropertyNames16.ts] +var s: string; +var n: number; +var a: any; +class C { + get [s]() { return 0;} + set [n](v) { } + static get [s + s]() { return 0; } + set [s + n](v) { } + get [+s]() { return 0; } + static set [""](v) { } + get [0]() { return 0; } + set [a](v) { } + static get [true]() { return 0; } + set [`hello bye`](v) { } + get [`hello ${a} bye`]() { return 0; } +} + +//// [computedPropertyNames16.js] +var s; +var n; +var a; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, s, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, n, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, s + s, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, s + n, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, +s, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "", { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, 0, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, a, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, true, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, `hello bye`, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, `hello ${a} bye`, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames16.types b/tests/baselines/reference/computedPropertyNames16.types new file mode 100644 index 00000000000..ccfa7996066 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames16.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts === +var s: string; +>s : string + +var n: number; +>n : number + +var a: any; +>a : any + +class C { +>C : C + + get [s]() { return 0;} +>s : string + + set [n](v) { } +>n : number +>v : any + + static get [s + s]() { return 0; } +>s + s : string +>s : string +>s : string + + set [s + n](v) { } +>s + n : string +>s : string +>n : number +>v : any + + get [+s]() { return 0; } +>+s : number +>s : string + + static set [""](v) { } +>v : any + + get [0]() { return 0; } + set [a](v) { } +>a : any +>v : any + + static get [true]() { return 0; } +>true : any + + set [`hello bye`](v) { } +>v : any + + get [`hello ${a} bye`]() { return 0; } +>a : any +} diff --git a/tests/baselines/reference/computedPropertyNames17.errors.txt b/tests/baselines/reference/computedPropertyNames17.errors.txt new file mode 100644 index 00000000000..3b0ceb2c653 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames17.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(3,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(4,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(7,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(8,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts (6 errors) ==== + var b: boolean; + class C { + get [b]() { return 0;} + ~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + static set [true](v) { } + ~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + get [[]]() { return 0; } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + set [{}](v) { } + ~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + static get [undefined]() { return 0; } + ~~~~~~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + set [null](v) { } + ~~~~~~ +!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames17.js b/tests/baselines/reference/computedPropertyNames17.js new file mode 100644 index 00000000000..5a55dbf7e1b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames17.js @@ -0,0 +1,57 @@ +//// [computedPropertyNames17.ts] +var b: boolean; +class C { + get [b]() { return 0;} + static set [true](v) { } + get [[]]() { return 0; } + set [{}](v) { } + static get [undefined]() { return 0; } + set [null](v) { } +} + +//// [computedPropertyNames17.js] +var b; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, b, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, true, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, [], { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, {}, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, undefined, { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, null, { + set: function (v) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts new file mode 100644 index 00000000000..0ab74d788c8 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts @@ -0,0 +1,17 @@ +// @target: es6 +var s: string; +var n: number; +var a: any; +var v = { + [s]() { }, + [n]() { }, + [s + s]() { }, + [s + n]() { }, + [+s]() { }, + [""]() { }, + [0]() { }, + [a]() { }, + [true]() { }, + [`hello bye`]() { }, + [`hello ${a} bye`]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts new file mode 100644 index 00000000000..d41c56fe953 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts @@ -0,0 +1,17 @@ +// @target: es6 +var s: string; +var n: number; +var a: any; +var v = { + get [s]() { return 0; }, + set [n](v) { }, + get [s + s]() { return 0; }, + set [s + n](v) { }, + get [+s]() { return 0; }, + set [""](v) { }, + get [0]() { return 0; }, + set [a](v) { }, + get [true]() { return 0; }, + set [`hello bye`](v) { }, + get [`hello ${a} bye`]() { return 0; } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts new file mode 100644 index 00000000000..e046899d331 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts @@ -0,0 +1,17 @@ +// @target: es6 +var s: string; +var n: number; +var a: any; +class C { + [s]: number; + [n] = n; + static [s + s]: string; + [s + n] = 2; + [+s]: typeof s; + static [""]: number; + [0]: number; + [a]: number; + static [true]: number; + [`hello bye`] = 0; + static [`hello ${a} bye`] = 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts new file mode 100644 index 00000000000..de40dc4e774 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts @@ -0,0 +1,17 @@ +// @target: es6 +var s: string; +var n: number; +var a: any; +class C { + [s]() {} + [n]() { } + static [s + s]() { } + [s + n]() { } + [+s]() { } + static [""]() { } + [0]() { } + [a]() { } + static [true]() { } + [`hello bye`]() { } + static [`hello ${a} bye`]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts new file mode 100644 index 00000000000..d90f2d7f976 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts @@ -0,0 +1,10 @@ +// @target: es6 +var b: boolean; +class C { + [b]() {} + static [true]() { } + [[]]() { } + static [{}]() { } + [undefined]() { } + static [null]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts new file mode 100644 index 00000000000..60b62d29034 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts @@ -0,0 +1,9 @@ +// @target: es6 +var p1: number | string; +var p2: number | number[]; +var p3: string | boolean; +class C { + [p1]() { } + [p2]() { } + [p3]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts new file mode 100644 index 00000000000..c42e6e97177 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts @@ -0,0 +1,17 @@ +// @target: es6 +var s: string; +var n: number; +var a: any; +class C { + get [s]() { return 0;} + set [n](v) { } + static get [s + s]() { return 0; } + set [s + n](v) { } + get [+s]() { return 0; } + static set [""](v) { } + get [0]() { return 0; } + set [a](v) { } + static get [true]() { return 0; } + set [`hello bye`](v) { } + get [`hello ${a} bye`]() { return 0; } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts new file mode 100644 index 00000000000..d795b527d06 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts @@ -0,0 +1,10 @@ +// @target: es6 +var b: boolean; +class C { + get [b]() { return 0;} + static set [true](v) { } + get [[]]() { return 0; } + set [{}](v) { } + static get [undefined]() { return 0; } + set [null](v) { } +} \ No newline at end of file From 4c5db716f951e2a01241437aa7d36535ed5e22bc Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 13 Jan 2015 17:18:12 -0800 Subject: [PATCH 16/71] Remove some unnecessary TODOs --- src/compiler/checker.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e15dcb37d70..79b7efc395d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8518,7 +8518,6 @@ module ts { } } - // TODO(jfreeman): Decide what to do for computed properties function checkTypeNameIsReserved(name: DeclarationName, message: DiagnosticMessage): void { // TS 1.0 spec (April 2014): 3.6.1 // The predefined type keywords are reserved and cannot be used as names of user defined types. @@ -8812,8 +8811,7 @@ module ts { var enumIsConst = isConst(node); forEach(node.members, member => { - // TODO(jfreeman): Check that it is not a computed name - if(isNumericName((member.name).text)) { + if (member.name.kind !== SyntaxKind.ComputedPropertyName && isNumericName((member.name).text)) { error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name); } var initializer = member.initializer; From 1b35a1be2522736ebe708f2acf64863447f06783 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 14 Jan 2015 12:09:46 -0800 Subject: [PATCH 17/71] Contextual typing for computed properties --- src/compiler/checker.ts | 46 ++++++++++++++----- .../computedPropertyNamesContextualType1.js | 18 ++++++++ ...computedPropertyNamesContextualType1.types | 33 +++++++++++++ .../computedPropertyNamesContextualType2.js | 18 ++++++++ ...computedPropertyNamesContextualType2.types | 33 +++++++++++++ .../computedPropertyNamesContextualType3.js | 17 +++++++ ...computedPropertyNamesContextualType3.types | 29 ++++++++++++ .../computedPropertyNamesContextualType1.ts | 10 ++++ .../computedPropertyNamesContextualType2.ts | 10 ++++ .../computedPropertyNamesContextualType3.ts | 9 ++++ 10 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType1.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType1.types create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType2.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType2.types create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType3.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType3.types create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType1.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType2.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 79b7efc395d..e37e9484ef7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5165,13 +5165,26 @@ module ts { function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) { var objectLiteral = element.parent; var type = getContextualType(objectLiteral); - // TODO(jfreeman): Handle this case for computed names and symbols - var name = (element.name).text; - if (type && name) { - return getTypeOfPropertyOfContextualType(type, name) || - isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || + if (type) { + if (!hasComputedNameButNotSymbol(element)) { + // For a (non-symbol) computed property, there is no reason to look up the name + // in the type. It will just be "__computed", which does not appear in any + // SymbolTable. + var symbolName = getSymbolOfNode(element).name; + var propertyType = getTypeOfPropertyOfContextualType(type, symbolName); + if (propertyType) { + return propertyType; + } + } + + var nameNode = element.name; + var propertyHasNumericName = nameNode.kind === SyntaxKind.ComputedPropertyName + ? isNumericComputedName(nameNode) + : isNumericName((nameNode).text); + return propertyHasNumericName && getIndexTypeOfContextualType(type, IndexKind.Number) || getIndexTypeOfContextualType(type, IndexKind.String); } + return undefined; } @@ -5370,6 +5383,10 @@ module ts { return createArrayType(getUnionType(elementTypes)); } + function isNumericComputedName(name: ComputedPropertyName): boolean { + return !!(checkExpression(name.expression).flags & TypeFlags.Number); + } + function isNumericName(name: string) { // The intent of numeric names is that // - they are names with text in a numeric form, and that @@ -5395,15 +5412,20 @@ module ts { return (+name).toString() === name; } - function checkComputedPropertyName(node: ComputedPropertyName): void { - var computedNameType = checkExpression(node.expression); + function checkComputedPropertyName(node: ComputedPropertyName): Type { + var links = getNodeLinks(node.expression); + if (!links.resolvedType) { + links.resolvedType = checkExpression(node.expression); - // This will only allow types number, string, or any. Any types more complex will - // be disallowed, even union types like string | number. In the future, we might consider - // allowing types like that. - if ((computedNameType.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.Any)) === 0) { - error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); + // This will only allow types number, string, or any. Any types more complex will + // be disallowed, even union types like string | number. In the future, we might consider + // allowing types like that. + if ((links.resolvedType.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.Any)) === 0) { + error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); + } } + + return links.resolvedType; } function checkObjectLiteral(node: ObjectLiteralExpression, contextualMapper?: TypeMapper): Type { diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1.js b/tests/baselines/reference/computedPropertyNamesContextualType1.js new file mode 100644 index 00000000000..d7704c8c377 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType1.js @@ -0,0 +1,18 @@ +//// [computedPropertyNamesContextualType1.ts] +interface I { + [s: string]: (x: string) => number; + [s: number]: (x: any) => number; // Doesn't get hit +} + +var o: I = { + ["" + 0](y) { return y.length; }, + ["" + 1]: y => y.length +} + +//// [computedPropertyNamesContextualType1.js] +var o = { + ["" + 0](y) { + return y.length; + }, + ["" + 1]: function (y) { return y.length; } +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1.types b/tests/baselines/reference/computedPropertyNamesContextualType1.types new file mode 100644 index 00000000000..2394eb96323 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType1.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType1.ts === +interface I { +>I : I + + [s: string]: (x: string) => number; +>s : string +>x : string + + [s: number]: (x: any) => number; // Doesn't get hit +>s : number +>x : any +} + +var o: I = { +>o : I +>I : I +>{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: undefined; [x: number]: undefined; } + + ["" + 0](y) { return y.length; }, +>"" + 0 : string +>y : string +>y.length : number +>y : string +>length : number + + ["" + 1]: y => y.length +>"" + 1 : string +>y => y.length : (y: string) => number +>y : string +>y.length : number +>y : string +>length : number +} diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2.js b/tests/baselines/reference/computedPropertyNamesContextualType2.js new file mode 100644 index 00000000000..7b9f98402f5 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType2.js @@ -0,0 +1,18 @@ +//// [computedPropertyNamesContextualType2.ts] +interface I { + [s: string]: (x: any) => number; // Doesn't get hit + [s: number]: (x: string) => number; +} + +var o: I = { + [+"foo"](y) { return y.length; }, + [+"bar"]: y => y.length +} + +//// [computedPropertyNamesContextualType2.js] +var o = { + [+"foo"](y) { + return y.length; + }, + [+"bar"]: function (y) { return y.length; } +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2.types b/tests/baselines/reference/computedPropertyNamesContextualType2.types new file mode 100644 index 00000000000..cb6842d4820 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType2.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType2.ts === +interface I { +>I : I + + [s: string]: (x: any) => number; // Doesn't get hit +>s : string +>x : any + + [s: number]: (x: string) => number; +>s : number +>x : string +} + +var o: I = { +>o : I +>I : I +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: undefined; [x: number]: undefined; } + + [+"foo"](y) { return y.length; }, +>+"foo" : number +>y : string +>y.length : number +>y : string +>length : number + + [+"bar"]: y => y.length +>+"bar" : number +>y => y.length : (y: string) => number +>y : string +>y.length : number +>y : string +>length : number +} diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3.js b/tests/baselines/reference/computedPropertyNamesContextualType3.js new file mode 100644 index 00000000000..f5b2c71bc18 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType3.js @@ -0,0 +1,17 @@ +//// [computedPropertyNamesContextualType3.ts] +interface I { + [s: string]: (x: string) => number; +} + +var o: I = { + [+"foo"](y) { return y.length; }, + [+"bar"]: y => y.length +} + +//// [computedPropertyNamesContextualType3.js] +var o = { + [+"foo"](y) { + return y.length; + }, + [+"bar"]: function (y) { return y.length; } +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3.types b/tests/baselines/reference/computedPropertyNamesContextualType3.types new file mode 100644 index 00000000000..d13670eb4b1 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType3.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType3.ts === +interface I { +>I : I + + [s: string]: (x: string) => number; +>s : string +>x : string +} + +var o: I = { +>o : I +>I : I +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: undefined; } + + [+"foo"](y) { return y.length; }, +>+"foo" : number +>y : string +>y.length : number +>y : string +>length : number + + [+"bar"]: y => y.length +>+"bar" : number +>y => y.length : (y: string) => number +>y : string +>y.length : number +>y : string +>length : number +} diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType1.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType1.ts new file mode 100644 index 00000000000..69c7c3ce958 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType1.ts @@ -0,0 +1,10 @@ +// @target: es6 +interface I { + [s: string]: (x: string) => number; + [s: number]: (x: any) => number; // Doesn't get hit +} + +var o: I = { + ["" + 0](y) { return y.length; }, + ["" + 1]: y => y.length +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType2.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType2.ts new file mode 100644 index 00000000000..e9d289c5cd3 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType2.ts @@ -0,0 +1,10 @@ +// @target: es6 +interface I { + [s: string]: (x: any) => number; // Doesn't get hit + [s: number]: (x: string) => number; +} + +var o: I = { + [+"foo"](y) { return y.length; }, + [+"bar"]: y => y.length +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType3.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType3.ts new file mode 100644 index 00000000000..dd2aff2931b --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType3.ts @@ -0,0 +1,9 @@ +// @target: es6 +interface I { + [s: string]: (x: string) => number; +} + +var o: I = { + [+"foo"](y) { return y.length; }, + [+"bar"]: y => y.length +} \ No newline at end of file From 1973b42946999e59d22c5b5db6c59ca8d1745345 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 14 Jan 2015 17:09:33 -0800 Subject: [PATCH 18/71] Indexers in object literals include computed property types --- src/compiler/checker.ts | 35 ++++++++-------- ...computedPropertyNamesContextualType1.types | 2 +- ...edPropertyNamesContextualType10.errors.txt | 20 ++++++++++ .../computedPropertyNamesContextualType10.js | 15 +++++++ ...computedPropertyNamesContextualType2.types | 2 +- ...computedPropertyNamesContextualType3.types | 2 +- .../computedPropertyNamesContextualType4.js | 16 ++++++++ ...computedPropertyNamesContextualType4.types | 22 ++++++++++ .../computedPropertyNamesContextualType5.js | 16 ++++++++ ...computedPropertyNamesContextualType5.types | 22 ++++++++++ .../computedPropertyNamesContextualType6.js | 24 +++++++++++ ...computedPropertyNamesContextualType6.types | 40 +++++++++++++++++++ .../computedPropertyNamesContextualType7.js | 24 +++++++++++ ...computedPropertyNamesContextualType7.types | 40 +++++++++++++++++++ ...tedPropertyNamesContextualType8.errors.txt | 21 ++++++++++ .../computedPropertyNamesContextualType8.js | 16 ++++++++ ...tedPropertyNamesContextualType9.errors.txt | 21 ++++++++++ .../computedPropertyNamesContextualType9.js | 16 ++++++++ .../computedPropertyNamesContextualType10.ts | 9 +++++ .../computedPropertyNamesContextualType4.ts | 10 +++++ .../computedPropertyNamesContextualType5.ts | 10 +++++ .../computedPropertyNamesContextualType6.ts | 14 +++++++ .../computedPropertyNamesContextualType7.ts | 14 +++++++ .../computedPropertyNamesContextualType8.ts | 10 +++++ .../computedPropertyNamesContextualType9.ts | 10 +++++ 25 files changed, 410 insertions(+), 21 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType10.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType10.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType4.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType4.types create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType5.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType5.types create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType6.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType6.types create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType7.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType7.types create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType8.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType8.js create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType9.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesContextualType9.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType4.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType5.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType6.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e37e9484ef7..3232fe1749a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1658,7 +1658,7 @@ module ts { // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. var type = getTypeOfPropertyOfType(parentType, name.text) || - isNumericName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) || + isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) || getIndexTypeOfType(parentType, IndexKind.String); if (!type) { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); @@ -5176,12 +5176,8 @@ module ts { return propertyType; } } - - var nameNode = element.name; - var propertyHasNumericName = nameNode.kind === SyntaxKind.ComputedPropertyName - ? isNumericComputedName(nameNode) - : isNumericName((nameNode).text); - return propertyHasNumericName && getIndexTypeOfContextualType(type, IndexKind.Number) || + + return isNumericName(element.name) && getIndexTypeOfContextualType(type, IndexKind.Number) || getIndexTypeOfContextualType(type, IndexKind.String); } @@ -5383,11 +5379,15 @@ module ts { return createArrayType(getUnionType(elementTypes)); } + function isNumericName(name: DeclarationName): boolean { + return name.kind === SyntaxKind.ComputedPropertyName ? isNumericComputedName(name) : isNumericLiteralName((name).text); + } + function isNumericComputedName(name: ComputedPropertyName): boolean { return !!(checkExpression(name.expression).flags & TypeFlags.Number); } - function isNumericName(name: string) { + function isNumericLiteralName(name: string) { // The intent of numeric names is that // - they are names with text in a numeric form, and that // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit', @@ -5490,13 +5490,12 @@ module ts { function getIndexType(kind: IndexKind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { var propTypes: Type[] = []; - for (var id in properties) { - if (hasProperty(properties, id)) { - if (kind === IndexKind.String || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!contains(propTypes, type)) { - propTypes.push(type); - } + for (var i = 0; i < node.properties.length; i++) { + var propertyDecl = node.properties[i]; + if (kind === IndexKind.String || isNumericName(propertyDecl.name)) { + var type = getTypeOfSymbol(getSymbolOfNode(propertyDecl)); + if (!contains(propTypes, type)) { + propTypes.push(type); } } } @@ -6788,7 +6787,7 @@ module ts { var name = (p).name; var type = sourceType.flags & TypeFlags.Any ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || - isNumericName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) || + isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) || getIndexTypeOfType(sourceType, IndexKind.String); if (type) { checkDestructuringAssignment((p).initializer || name, type); @@ -8479,7 +8478,7 @@ module ts { } // index is numeric and property name is not valid numeric literal - if (indexKind === IndexKind.Number && !isNumericName(prop.name)) { + if (indexKind === IndexKind.Number && !isNumericLiteralName(prop.name)) { return; } @@ -8833,7 +8832,7 @@ module ts { var enumIsConst = isConst(node); forEach(node.members, member => { - if (member.name.kind !== SyntaxKind.ComputedPropertyName && isNumericName((member.name).text)) { + if (member.name.kind !== SyntaxKind.ComputedPropertyName && isNumericLiteralName((member.name).text)) { error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name); } var initializer = member.initializer; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1.types b/tests/baselines/reference/computedPropertyNamesContextualType1.types index 2394eb96323..1697542fba6 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType1.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType1.types @@ -14,7 +14,7 @@ interface I { var o: I = { >o : I >I : I ->{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: undefined; [x: number]: undefined; } +>{ ["" + 0](y) { return y.length; }, ["" + 1]: y => y.length} : { [x: string]: (y: string) => number; [x: number]: undefined; } ["" + 0](y) { return y.length; }, >"" + 0 : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType10.errors.txt new file mode 100644 index 00000000000..5e9fbe7b45b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType10.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10.ts(5,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. + Index signatures are incompatible. + Type 'string | number' is not assignable to type 'boolean'. + Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10.ts (1 errors) ==== + interface I { + [s: number]: boolean; + } + + var o: I = { + ~ +!!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. +!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. + [+"foo"]: "", + [+"bar"]: 0 + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10.js b/tests/baselines/reference/computedPropertyNamesContextualType10.js new file mode 100644 index 00000000000..125a014852e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType10.js @@ -0,0 +1,15 @@ +//// [computedPropertyNamesContextualType10.ts] +interface I { + [s: number]: boolean; +} + +var o: I = { + [+"foo"]: "", + [+"bar"]: 0 +} + +//// [computedPropertyNamesContextualType10.js] +var o = { + [+"foo"]: "", + [+"bar"]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2.types b/tests/baselines/reference/computedPropertyNamesContextualType2.types index cb6842d4820..408fd6a5062 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType2.types @@ -14,7 +14,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: undefined; [x: number]: undefined; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: (y: string) => number; [x: number]: (y: string) => number; } [+"foo"](y) { return y.length; }, >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3.types b/tests/baselines/reference/computedPropertyNamesContextualType3.types index d13670eb4b1..a1a36c1b7e9 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType3.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType3.types @@ -10,7 +10,7 @@ interface I { var o: I = { >o : I >I : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: undefined; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: string]: (y: string) => number; } [+"foo"](y) { return y.length; }, >+"foo" : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4.js b/tests/baselines/reference/computedPropertyNamesContextualType4.js new file mode 100644 index 00000000000..6ddd22baf6e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType4.js @@ -0,0 +1,16 @@ +//// [computedPropertyNamesContextualType4.ts] +interface I { + [s: string]: any; + [s: number]: any; +} + +var o: I = { + [""+"foo"]: "", + [""+"bar"]: 0 +} + +//// [computedPropertyNamesContextualType4.js] +var o = { + ["" + "foo"]: "", + ["" + "bar"]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4.types b/tests/baselines/reference/computedPropertyNamesContextualType4.types new file mode 100644 index 00000000000..d22f56f24fe --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType4.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType4.ts === +interface I { +>I : I + + [s: string]: any; +>s : string + + [s: number]: any; +>s : number +} + +var o: I = { +>o : I +>I : I +>{ [""+"foo"]: "", [""+"bar"]: 0} : { [x: string]: string | number; [x: number]: undefined; } + + [""+"foo"]: "", +>""+"foo" : string + + [""+"bar"]: 0 +>""+"bar" : string +} diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5.js b/tests/baselines/reference/computedPropertyNamesContextualType5.js new file mode 100644 index 00000000000..f2bd79644a0 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType5.js @@ -0,0 +1,16 @@ +//// [computedPropertyNamesContextualType5.ts] +interface I { + [s: string]: any; + [s: number]: any; +} + +var o: I = { + [+"foo"]: "", + [+"bar"]: 0 +} + +//// [computedPropertyNamesContextualType5.js] +var o = { + [+"foo"]: "", + [+"bar"]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5.types b/tests/baselines/reference/computedPropertyNamesContextualType5.types new file mode 100644 index 00000000000..12c3332acfa --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType5.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType5.ts === +interface I { +>I : I + + [s: string]: any; +>s : string + + [s: number]: any; +>s : number +} + +var o: I = { +>o : I +>I : I +>{ [+"foo"]: "", [+"bar"]: 0} : { [x: string]: string | number; [x: number]: string | number; } + + [+"foo"]: "", +>+"foo" : number + + [+"bar"]: 0 +>+"bar" : number +} diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6.js b/tests/baselines/reference/computedPropertyNamesContextualType6.js new file mode 100644 index 00000000000..5d0cc149b2c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType6.js @@ -0,0 +1,24 @@ +//// [computedPropertyNamesContextualType6.ts] +interface I { + [s: string]: T; +} + +declare function foo(obj: I): T + +foo({ + p: "", + 0: () => { }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); + +//// [computedPropertyNamesContextualType6.js] +foo({ + p: "", + 0: function () { + }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6.types b/tests/baselines/reference/computedPropertyNamesContextualType6.types new file mode 100644 index 00000000000..acbae75ad4c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType6.types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType6.ts === +interface I { +>I : I +>T : T + + [s: string]: T; +>s : string +>T : T +} + +declare function foo(obj: I): T +>foo : (obj: I) => T +>T : T +>obj : I +>I : I +>T : T +>T : T + +foo({ +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | number[] | (() => void) +>foo : (obj: I) => T +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | number[] | (() => void); 0: () => void; p: string; } + + p: "", +>p : string + + 0: () => { }, +>() => { } : () => void + + ["hi" + "bye"]: true, +>"hi" + "bye" : string + + [0 + 1]: 0, +>0 + 1 : number + + [+"hi"]: [0] +>+"hi" : number +>[0] : number[] + +}); diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7.js b/tests/baselines/reference/computedPropertyNamesContextualType7.js new file mode 100644 index 00000000000..74030be6f2a --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType7.js @@ -0,0 +1,24 @@ +//// [computedPropertyNamesContextualType7.ts] +interface I { + [s: number]: T; +} + +declare function foo(obj: I): T + +foo({ + p: "", + 0: () => { }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); + +//// [computedPropertyNamesContextualType7.js] +foo({ + p: "", + 0: function () { + }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7.types b/tests/baselines/reference/computedPropertyNamesContextualType7.types new file mode 100644 index 00000000000..da059d490b0 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType7.types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7.ts === +interface I { +>I : I +>T : T + + [s: number]: T; +>s : number +>T : T +} + +declare function foo(obj: I): T +>foo : (obj: I) => T +>T : T +>obj : I +>I : I +>T : T +>T : T + +foo({ +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | number[] | (() => void) +>foo : (obj: I) => T +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | number[] | (() => void); 0: () => void; p: string; } + + p: "", +>p : string + + 0: () => { }, +>() => { } : () => void + + ["hi" + "bye"]: true, +>"hi" + "bye" : string + + [0 + 1]: 0, +>0 + 1 : number + + [+"hi"]: [0] +>+"hi" : number +>[0] : number[] + +}); diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType8.errors.txt new file mode 100644 index 00000000000..07b55b799e4 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType8.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8.ts(6,5): error TS2322: Type '{ [x: string]: string | number; [x: number]: undefined; }' is not assignable to type 'I'. + Index signatures are incompatible. + Type 'string | number' is not assignable to type 'boolean'. + Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8.ts (1 errors) ==== + interface I { + [s: string]: boolean; + [s: number]: boolean; + } + + var o: I = { + ~ +!!! error TS2322: Type '{ [x: string]: string | number; [x: number]: undefined; }' is not assignable to type 'I'. +!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. + [""+"foo"]: "", + [""+"bar"]: 0 + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8.js b/tests/baselines/reference/computedPropertyNamesContextualType8.js new file mode 100644 index 00000000000..d98538c40c1 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType8.js @@ -0,0 +1,16 @@ +//// [computedPropertyNamesContextualType8.ts] +interface I { + [s: string]: boolean; + [s: number]: boolean; +} + +var o: I = { + [""+"foo"]: "", + [""+"bar"]: 0 +} + +//// [computedPropertyNamesContextualType8.js] +var o = { + ["" + "foo"]: "", + ["" + "bar"]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9.errors.txt new file mode 100644 index 00000000000..6a1d9316fd7 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType9.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9.ts(6,5): error TS2322: Type '{ [x: string]: string | number; [x: number]: string | number; }' is not assignable to type 'I'. + Index signatures are incompatible. + Type 'string | number' is not assignable to type 'boolean'. + Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9.ts (1 errors) ==== + interface I { + [s: string]: boolean; + [s: number]: boolean; + } + + var o: I = { + ~ +!!! error TS2322: Type '{ [x: string]: string | number; [x: number]: string | number; }' is not assignable to type 'I'. +!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. + [+"foo"]: "", + [+"bar"]: 0 + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9.js b/tests/baselines/reference/computedPropertyNamesContextualType9.js new file mode 100644 index 00000000000..ed8791a51e0 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesContextualType9.js @@ -0,0 +1,16 @@ +//// [computedPropertyNamesContextualType9.ts] +interface I { + [s: string]: boolean; + [s: number]: boolean; +} + +var o: I = { + [+"foo"]: "", + [+"bar"]: 0 +} + +//// [computedPropertyNamesContextualType9.js] +var o = { + [+"foo"]: "", + [+"bar"]: 0 +}; diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10.ts new file mode 100644 index 00000000000..f19c7fcab9d --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10.ts @@ -0,0 +1,9 @@ +// @target: es6 +interface I { + [s: number]: boolean; +} + +var o: I = { + [+"foo"]: "", + [+"bar"]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType4.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType4.ts new file mode 100644 index 00000000000..ff191a3e80d --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType4.ts @@ -0,0 +1,10 @@ +// @target: es6 +interface I { + [s: string]: any; + [s: number]: any; +} + +var o: I = { + [""+"foo"]: "", + [""+"bar"]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType5.ts new file mode 100644 index 00000000000..a78ddef37fc --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType5.ts @@ -0,0 +1,10 @@ +// @target: es6 +interface I { + [s: string]: any; + [s: number]: any; +} + +var o: I = { + [+"foo"]: "", + [+"bar"]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType6.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType6.ts new file mode 100644 index 00000000000..70f31378b56 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType6.ts @@ -0,0 +1,14 @@ +// @target: es6 +interface I { + [s: string]: T; +} + +declare function foo(obj: I): T + +foo({ + p: "", + 0: () => { }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7.ts new file mode 100644 index 00000000000..1ddb966488d --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType7.ts @@ -0,0 +1,14 @@ +// @target: es6 +interface I { + [s: number]: T; +} + +declare function foo(obj: I): T + +foo({ + p: "", + 0: () => { }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8.ts new file mode 100644 index 00000000000..b5caf1e717c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8.ts @@ -0,0 +1,10 @@ +// @target: es6 +interface I { + [s: string]: boolean; + [s: number]: boolean; +} + +var o: I = { + [""+"foo"]: "", + [""+"bar"]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9.ts new file mode 100644 index 00000000000..8282fab0035 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9.ts @@ -0,0 +1,10 @@ +// @target: es6 +interface I { + [s: string]: boolean; + [s: number]: boolean; +} + +var o: I = { + [+"foo"]: "", + [+"bar"]: 0 +} \ No newline at end of file From f943f6c486988a1bb65b88a2916c420bbf00144f Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 15 Jan 2015 17:54:34 -0800 Subject: [PATCH 19/71] Adjust error numbers --- .../computedPropertyNames14.errors.txt | 24 +++++++++---------- .../computedPropertyNames15.errors.txt | 12 +++++----- .../computedPropertyNames17.errors.txt | 24 +++++++++---------- .../computedPropertyNames3.errors.txt | 16 ++++++------- .../computedPropertyNames5.errors.txt | 24 +++++++++---------- .../computedPropertyNames6.errors.txt | 12 +++++----- .../computedPropertyNames7.errors.txt | 4 ++-- .../computedPropertyNames8.errors.txt | 8 +++---- .../computedPropertyNames9.errors.txt | 4 ++-- 9 files changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/baselines/reference/computedPropertyNames14.errors.txt b/tests/baselines/reference/computedPropertyNames14.errors.txt index fe38166f9ab..1cf5b1445f2 100644 --- a/tests/baselines/reference/computedPropertyNames14.errors.txt +++ b/tests/baselines/reference/computedPropertyNames14.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(4,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(6,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(8,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(3,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(6,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(8,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts (6 errors) ==== @@ -11,20 +11,20 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(8,12): class C { [b]() {} ~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static [true]() { } ~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [[]]() { } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static [{}]() { } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [undefined]() { } ~~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static [null]() { } ~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames15.errors.txt b/tests/baselines/reference/computedPropertyNames15.errors.txt index ee8d5b96bca..69d997d7737 100644 --- a/tests/baselines/reference/computedPropertyNames15.errors.txt +++ b/tests/baselines/reference/computedPropertyNames15.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(6,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts (3 errors) ==== @@ -10,11 +10,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): class C { [p1]() { } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [p2]() { } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [p3]() { } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames17.errors.txt b/tests/baselines/reference/computedPropertyNames17.errors.txt index 3b0ceb2c653..b236ae3245e 100644 --- a/tests/baselines/reference/computedPropertyNames17.errors.txt +++ b/tests/baselines/reference/computedPropertyNames17.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(3,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(4,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(7,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(8,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(3,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(4,16): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(8,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts (6 errors) ==== @@ -11,20 +11,20 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(8,9): class C { get [b]() { return 0;} ~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static set [true](v) { } ~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. get [[]]() { return 0; } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. set [{}](v) { } ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static get [undefined]() { return 0; } ~~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. set [null](v) { } ~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames3.errors.txt b/tests/baselines/reference/computedPropertyNames3.errors.txt index ad98baf6a14..080bff1ab9a 100644 --- a/tests/baselines/reference/computedPropertyNames3.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (6 errors) ==== @@ -12,19 +12,19 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): [0 + 1]() { } static [() => { }]() { } ~~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. get [delete id]() { } ~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. set [[0, 1]](v) { } ~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static get [""]() { } ~~~~~~~~~~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. static set [id.toString()](v) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames5.errors.txt b/tests/baselines/reference/computedPropertyNames5.errors.txt index f7ca4b97e9f..2b8cf5503b8 100644 --- a/tests/baselines/reference/computedPropertyNames5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames5.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(4,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(8,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(3,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(4,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(6,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(8,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts (6 errors) ==== @@ -11,20 +11,20 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(8,5): e var v = { [b]: 0, ~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [true]: 1, ~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [[]]: 0, ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [{}]: 0, ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [undefined]: undefined, ~~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [null]: null ~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames6.errors.txt b/tests/baselines/reference/computedPropertyNames6.errors.txt index e9e150e2739..100afc85992 100644 --- a/tests/baselines/reference/computedPropertyNames6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames6.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(6,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts (3 errors) ==== @@ -10,11 +10,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): e var v = { [p1]: 0, ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [p2]: 1, ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [p3]: 2 ~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames7.errors.txt b/tests/baselines/reference/computedPropertyNames7.errors.txt index b519369956c..e98be616a3a 100644 --- a/tests/baselines/reference/computedPropertyNames7.errors.txt +++ b/tests/baselines/reference/computedPropertyNames7.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts (1 errors) ==== @@ -8,5 +8,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): e var v = { [E.member]: 0 ~~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames8.errors.txt b/tests/baselines/reference/computedPropertyNames8.errors.txt index 99aa43b9276..515af1f4fc4 100644 --- a/tests/baselines/reference/computedPropertyNames8.errors.txt +++ b/tests/baselines/reference/computedPropertyNames8.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts (2 errors) ==== @@ -9,9 +9,9 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(6,9): e var v = { [t]: 0, ~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [u]: 1 ~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. }; } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames9.errors.txt b/tests/baselines/reference/computedPropertyNames9.errors.txt index 8450e1fd092..d87576f1f77 100644 --- a/tests/baselines/reference/computedPropertyNames9.errors.txt +++ b/tests/baselines/reference/computedPropertyNames9.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts(9,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts(9,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts (1 errors) ==== @@ -12,5 +12,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts(9,5): e [f(0)]: 0, [f(true)]: 0 ~~~~~~~~~ -!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'. +!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. } \ No newline at end of file From 4cc27227001d7d9895bf930f750eb57955ac4214 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 16 Jan 2015 19:15:24 -0800 Subject: [PATCH 20/71] Disallow this in computed properties in classes --- src/compiler/checker.ts | 3 +++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/utilities.ts | 8 +++++++ src/services/services.ts | 2 ++ .../reference/computedPropertyNames18.js | 13 +++++++++++ .../reference/computedPropertyNames18.types | 14 +++++++++++ .../computedPropertyNames19.errors.txt | 11 +++++++++ .../reference/computedPropertyNames19.js | 14 +++++++++++ .../reference/computedPropertyNames20.js | 9 ++++++++ .../reference/computedPropertyNames20.types | 10 ++++++++ .../computedPropertyNames21.errors.txt | 12 ++++++++++ .../reference/computedPropertyNames21.js | 19 +++++++++++++++ .../reference/computedPropertyNames22.js | 23 +++++++++++++++++++ .../reference/computedPropertyNames22.types | 21 +++++++++++++++++ .../computedPropertyNames23.errors.txt | 14 +++++++++++ .../reference/computedPropertyNames23.js | 21 +++++++++++++++++ .../computedPropertyNames18.ts | 6 +++++ .../computedPropertyNames19.ts | 6 +++++ .../computedPropertyNames20.ts | 4 ++++ .../computedPropertyNames21.ts | 7 ++++++ .../computedPropertyNames22.ts | 9 ++++++++ .../computedPropertyNames23.ts | 9 ++++++++ 23 files changed, 240 insertions(+) create mode 100644 tests/baselines/reference/computedPropertyNames18.js create mode 100644 tests/baselines/reference/computedPropertyNames18.types create mode 100644 tests/baselines/reference/computedPropertyNames19.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames19.js create mode 100644 tests/baselines/reference/computedPropertyNames20.js create mode 100644 tests/baselines/reference/computedPropertyNames20.types create mode 100644 tests/baselines/reference/computedPropertyNames21.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames21.js create mode 100644 tests/baselines/reference/computedPropertyNames22.js create mode 100644 tests/baselines/reference/computedPropertyNames22.types create mode 100644 tests/baselines/reference/computedPropertyNames23.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames23.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames18.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames20.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames22.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3232fe1749a..8c5b49014ad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4853,6 +4853,9 @@ module ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks } break; + case SyntaxKind.ComputedPropertyName: + error(node, Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); + break; } if (needToCaptureLexicalThis) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 6354633fe60..fb9811b396b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -300,6 +300,7 @@ module ts { A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" }, A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." }, A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', or 'any'." }, + this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8268af730ec..940b66c4efc 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1294,6 +1294,10 @@ "category": "Error", "code": 2464 }, + "'this' cannot be referenced in a computed property name.": { + "category": "Error", + "code": 2465 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f1fab4137e2..6f3460244b3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -399,6 +399,14 @@ module ts { return undefined; } switch (node.kind) { + case SyntaxKind.ComputedPropertyName: + // If the grandparent node is an object literal (as opposed to a class), + // then the computed property is not a 'this' container. + // A computed property name in a class needs to be a this container + // so that we can error on it. + if (node.parent.parent.kind !== SyntaxKind.ClassDeclaration) { + continue; + } case SyntaxKind.ArrowFunction: if (!includeArrowFunctions) { continue; diff --git a/src/services/services.ts b/src/services/services.ts index 84e5e7fefa5..8c6ebecf469 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4191,6 +4191,8 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: break; + // Computed properties in classes are not handled here because references to this are illegal, + // so there is no point finding references to them. default: return undefined; } diff --git a/tests/baselines/reference/computedPropertyNames18.js b/tests/baselines/reference/computedPropertyNames18.js new file mode 100644 index 00000000000..af2d68b3095 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames18.js @@ -0,0 +1,13 @@ +//// [computedPropertyNames18.ts] +function foo() { + var obj = { + [this.bar]: 0 + } +} + +//// [computedPropertyNames18.js] +function foo() { + var obj = { + [this.bar]: 0 + }; +} diff --git a/tests/baselines/reference/computedPropertyNames18.types b/tests/baselines/reference/computedPropertyNames18.types new file mode 100644 index 00000000000..0976e5fc3ca --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames18.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames18.ts === +function foo() { +>foo : () => void + + var obj = { +>obj : {} +>{ [this.bar]: 0 } : {} + + [this.bar]: 0 +>this.bar : any +>this : any +>bar : any + } +} diff --git a/tests/baselines/reference/computedPropertyNames19.errors.txt b/tests/baselines/reference/computedPropertyNames19.errors.txt new file mode 100644 index 00000000000..2037008992f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames19.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts(3,10): error TS2331: 'this' cannot be referenced in a module body. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts (1 errors) ==== + module M { + var obj = { + [this.bar]: 0 + ~~~~ +!!! error TS2331: 'this' cannot be referenced in a module body. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames19.js b/tests/baselines/reference/computedPropertyNames19.js new file mode 100644 index 00000000000..3fd2f99eea6 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames19.js @@ -0,0 +1,14 @@ +//// [computedPropertyNames19.ts] +module M { + var obj = { + [this.bar]: 0 + } +} + +//// [computedPropertyNames19.js] +var M; +(function (M) { + var obj = { + [this.bar]: 0 + }; +})(M || (M = {})); diff --git a/tests/baselines/reference/computedPropertyNames20.js b/tests/baselines/reference/computedPropertyNames20.js new file mode 100644 index 00000000000..2a1edf06142 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames20.js @@ -0,0 +1,9 @@ +//// [computedPropertyNames20.ts] +var obj = { + [this.bar]: 0 +} + +//// [computedPropertyNames20.js] +var obj = { + [this.bar]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNames20.types b/tests/baselines/reference/computedPropertyNames20.types new file mode 100644 index 00000000000..abd1b203e87 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames20.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames20.ts === +var obj = { +>obj : {} +>{ [this.bar]: 0} : {} + + [this.bar]: 0 +>this.bar : any +>this : any +>bar : any +} diff --git a/tests/baselines/reference/computedPropertyNames21.errors.txt b/tests/baselines/reference/computedPropertyNames21.errors.txt new file mode 100644 index 00000000000..a44c8d60ee8 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames21.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts(5,6): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts (1 errors) ==== + class C { + bar() { + return 0; + } + [this.bar()]() { } + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames21.js b/tests/baselines/reference/computedPropertyNames21.js new file mode 100644 index 00000000000..250d9142aa5 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames21.js @@ -0,0 +1,19 @@ +//// [computedPropertyNames21.ts] +class C { + bar() { + return 0; + } + [this.bar()]() { } +} + +//// [computedPropertyNames21.js] +var C = (function () { + function C() { + } + C.prototype.bar = function () { + return 0; + }; + C.prototype[this.bar()] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames22.js b/tests/baselines/reference/computedPropertyNames22.js new file mode 100644 index 00000000000..b42946536d0 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames22.js @@ -0,0 +1,23 @@ +//// [computedPropertyNames22.ts] +class C { + bar() { + var obj = { + [this.bar()]() { } + }; + return 0; + } +} + +//// [computedPropertyNames22.js] +var C = (function () { + function C() { + } + C.prototype.bar = function () { + var obj = { + [this.bar()]() { + } + }; + return 0; + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames22.types b/tests/baselines/reference/computedPropertyNames22.types new file mode 100644 index 00000000000..52dff9a4f41 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames22.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames22.ts === +class C { +>C : C + + bar() { +>bar : () => number + + var obj = { +>obj : {} +>{ [this.bar()]() { } } : {} + + [this.bar()]() { } +>this.bar() : any +>this.bar : any +>this : any +>bar : any + + }; + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames23.errors.txt b/tests/baselines/reference/computedPropertyNames23.errors.txt new file mode 100644 index 00000000000..0846ba4d6c6 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames23.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts(6,12): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts (1 errors) ==== + class C { + bar() { + return 0; + } + [ + { [this.bar()]: 1 }[0] + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + ]() { } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames23.js b/tests/baselines/reference/computedPropertyNames23.js new file mode 100644 index 00000000000..9d71ef34c1e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames23.js @@ -0,0 +1,21 @@ +//// [computedPropertyNames23.ts] +class C { + bar() { + return 0; + } + [ + { [this.bar()]: 1 }[0] + ]() { } +} + +//// [computedPropertyNames23.js] +var C = (function () { + function C() { + } + C.prototype.bar = function () { + return 0; + }; + C.prototype[{ [this.bar()]: 1 }[0]] = function () { + }; + return C; +})(); diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames18.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames18.ts new file mode 100644 index 00000000000..cd7a43f233f --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames18.ts @@ -0,0 +1,6 @@ +// @target: es6 +function foo() { + var obj = { + [this.bar]: 0 + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts new file mode 100644 index 00000000000..3dbf97d7f7a --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts @@ -0,0 +1,6 @@ +// @target: es6 +module M { + var obj = { + [this.bar]: 0 + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames20.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames20.ts new file mode 100644 index 00000000000..d31f63d2e87 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames20.ts @@ -0,0 +1,4 @@ +// @target: es6 +var obj = { + [this.bar]: 0 +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts new file mode 100644 index 00000000000..654f1b29985 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts @@ -0,0 +1,7 @@ +// @target: es6 +class C { + bar() { + return 0; + } + [this.bar()]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames22.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames22.ts new file mode 100644 index 00000000000..c999e0d642c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames22.ts @@ -0,0 +1,9 @@ +// @target: es6 +class C { + bar() { + var obj = { + [this.bar()]() { } + }; + return 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts new file mode 100644 index 00000000000..9c7c5bb6539 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts @@ -0,0 +1,9 @@ +// @target: es6 +class C { + bar() { + return 0; + } + [ + { [this.bar()]: 1 }[0] + ]() { } +} \ No newline at end of file From e317767966aa175d2e1f167ba1e5d3686eee1479 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 16 Jan 2015 19:46:32 -0800 Subject: [PATCH 21/71] Consolidate getSuperContainer --- src/compiler/checker.ts | 24 ++---------------------- src/compiler/utilities.ts | 12 ++++++++---- src/services/services.ts | 4 ++-- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8c5b49014ad..98fcd90b623 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4870,26 +4870,6 @@ module ts { return anyType; } - function getSuperContainer(node: Node): Node { - while (true) { - node = node.parent; - if (!node) return node; - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return node; - } - } - } - function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean { for (var n = node; n && n !== constructorDecl; n = n.parent) { if (n.kind === SyntaxKind.Parameter) { @@ -4913,7 +4893,7 @@ module ts { return unknownType; } - var container = getSuperContainer(node); + var container = getSuperContainer(node, /*includeFunctions*/ true); if (container) { var canUseSuperExpression = false; @@ -4931,7 +4911,7 @@ module ts { // super property access might appear in arrow functions with arbitrary deep nesting var needToCaptureLexicalThis = false; while (container && container.kind === SyntaxKind.ArrowFunction) { - container = getSuperContainer(container); + container = getSuperContainer(container, /*includeFunctions*/ true); needToCaptureLexicalThis = true; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6f3460244b3..d41b7ea6b24 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -429,13 +429,17 @@ module ts { } } - export function getSuperContainer(node: Node): Node { + export function getSuperContainer(node: Node, includeFunctions: boolean): Node { while (true) { node = node.parent; - if (!node) { - return undefined; - } + if (!node) return node; switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + if (!includeFunctions) { + continue; + } case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index 8c6ebecf469..848c22b52a3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4114,7 +4114,7 @@ module ts { } function getReferencesForSuperKeyword(superKeyword: Node): ReferenceEntry[] { - var searchSpaceNode = getSuperContainer(superKeyword); + var searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false); if (!searchSpaceNode) { return undefined; } @@ -4149,7 +4149,7 @@ module ts { return; } - var container = getSuperContainer(node); + var container = getSuperContainer(node, /*includeFunctions*/ false); // If we have a 'super' container, we must have an enclosing class. // Now make sure the owning class is the same as the search-space From b5349a5038b66c7d2461a765ccc33dbfa0f16423 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 19 Jan 2015 16:27:58 -0800 Subject: [PATCH 22/71] Disallow super and fix this capturing for computed properties --- src/compiler/checker.ts | 5 +- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/compiler/utilities.ts | 26 +++++++++- .../reference/computedPropertyNames22.types | 8 +-- .../computedPropertyNames24.errors.txt | 16 ++++++ .../reference/computedPropertyNames24.js | 38 ++++++++++++++ .../reference/computedPropertyNames25.js | 44 +++++++++++++++++ .../reference/computedPropertyNames25.types | 31 ++++++++++++ .../computedPropertyNames26.errors.txt | 18 +++++++ .../reference/computedPropertyNames26.js | 40 +++++++++++++++ .../computedPropertyNames27.errors.txt | 11 +++++ .../reference/computedPropertyNames27.js | 28 +++++++++++ .../reference/computedPropertyNames28.js | 35 +++++++++++++ .../reference/computedPropertyNames28.types | 26 ++++++++++ .../reference/computedPropertyNames29.js | 28 +++++++++++ .../reference/computedPropertyNames29.types | 25 ++++++++++ .../computedPropertyNames30.errors.txt | 21 ++++++++ .../reference/computedPropertyNames30.js | 45 +++++++++++++++++ .../reference/computedPropertyNames31.js | 49 +++++++++++++++++++ .../reference/computedPropertyNames31.types | 35 +++++++++++++ .../computedPropertyNames24.ts | 11 +++++ .../computedPropertyNames25.ts | 14 ++++++ .../computedPropertyNames26.ts | 13 +++++ .../computedPropertyNames27.ts | 6 +++ .../computedPropertyNames28.ts | 11 +++++ .../computedPropertyNames29.ts | 11 +++++ .../computedPropertyNames30.ts | 16 ++++++ .../computedPropertyNames31.ts | 16 ++++++ 29 files changed, 625 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNames24.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames24.js create mode 100644 tests/baselines/reference/computedPropertyNames25.js create mode 100644 tests/baselines/reference/computedPropertyNames25.types create mode 100644 tests/baselines/reference/computedPropertyNames26.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames26.js create mode 100644 tests/baselines/reference/computedPropertyNames27.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames27.js create mode 100644 tests/baselines/reference/computedPropertyNames28.js create mode 100644 tests/baselines/reference/computedPropertyNames28.types create mode 100644 tests/baselines/reference/computedPropertyNames29.js create mode 100644 tests/baselines/reference/computedPropertyNames29.types create mode 100644 tests/baselines/reference/computedPropertyNames30.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames30.js create mode 100644 tests/baselines/reference/computedPropertyNames31.js create mode 100644 tests/baselines/reference/computedPropertyNames31.types create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames25.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames28.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames29.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames31.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 98fcd90b623..1fc3227e5ec 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4966,7 +4966,10 @@ module ts { } } - if (isCallExpression) { + if (container.kind === SyntaxKind.ComputedPropertyName) { + error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); + } + else if (isCallExpression) { error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); } else { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index fb9811b396b..0a8c3a7edfe 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -301,6 +301,7 @@ module ts { A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." }, A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', or 'any'." }, this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." }, + super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 940b66c4efc..2d1b4e4daf0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1298,6 +1298,10 @@ "category": "Error", "code": 2465 }, + "'super' cannot be referenced in a computed property name.": { + "category": "Error", + "code": 2466 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index d41b7ea6b24..6c894ad7d9c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -404,9 +404,16 @@ module ts { // then the computed property is not a 'this' container. // A computed property name in a class needs to be a this container // so that we can error on it. - if (node.parent.parent.kind !== SyntaxKind.ClassDeclaration) { - continue; + if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + return node; } + // If this is a computed property, then the parent should not + // make it a this container. The parent might be a property + // in an object literal, like a method or accessor. But in order for + // such a parent to be a this container, the reference must be in + // the *body* of the container. + node = node.parent; + break; case SyntaxKind.ArrowFunction: if (!includeArrowFunctions) { continue; @@ -434,6 +441,21 @@ module ts { node = node.parent; if (!node) return node; switch (node.kind) { + case SyntaxKind.ComputedPropertyName: + // If the grandparent node is an object literal (as opposed to a class), + // then the computed property is not a 'super' container. + // A computed property name in a class needs to be a super container + // so that we can error on it. + if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + return node; + } + // If this is a computed property, then the parent should not + // make it a super container. The parent might be a property + // in an object literal, like a method or accessor. But in order for + // such a parent to be a super container, the reference must be in + // the *body* of the container. + node = node.parent; + break; case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: diff --git a/tests/baselines/reference/computedPropertyNames22.types b/tests/baselines/reference/computedPropertyNames22.types index 52dff9a4f41..d23546192c0 100644 --- a/tests/baselines/reference/computedPropertyNames22.types +++ b/tests/baselines/reference/computedPropertyNames22.types @@ -10,10 +10,10 @@ class C { >{ [this.bar()]() { } } : {} [this.bar()]() { } ->this.bar() : any ->this.bar : any ->this : any ->bar : any +>this.bar() : number +>this.bar : () => number +>this : C +>bar : () => number }; return 0; diff --git a/tests/baselines/reference/computedPropertyNames24.errors.txt b/tests/baselines/reference/computedPropertyNames24.errors.txt new file mode 100644 index 00000000000..938fb64b82e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames24.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts (1 errors) ==== + class Base { + bar() { + return 0; + } + } + class C extends Base { + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + [super.bar()]() { } + ~~~~~ +!!! error TS2466: 'super' cannot be referenced in a computed property name. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames24.js b/tests/baselines/reference/computedPropertyNames24.js new file mode 100644 index 00000000000..2ef2826ee22 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames24.js @@ -0,0 +1,38 @@ +//// [computedPropertyNames24.ts] +class Base { + bar() { + return 0; + } +} +class C extends Base { + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + [super.bar()]() { } +} + +//// [computedPropertyNames24.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + Base.prototype.bar = function () { + return 0; + }; + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + C.prototype[super.bar.call(this)] = function () { + }; + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames25.js b/tests/baselines/reference/computedPropertyNames25.js new file mode 100644 index 00000000000..a15fcb217e7 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames25.js @@ -0,0 +1,44 @@ +//// [computedPropertyNames25.ts] +class Base { + bar() { + return 0; + } +} +class C extends Base { + foo() { + var obj = { + [super.bar()]() { } + }; + return 0; + } +} + +//// [computedPropertyNames25.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + Base.prototype.bar = function () { + return 0; + }; + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + C.prototype.foo = function () { + var obj = { + [_super.prototype.bar.call(this)]() { + } + }; + return 0; + }; + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames25.types b/tests/baselines/reference/computedPropertyNames25.types new file mode 100644 index 00000000000..d8567dc86ad --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames25.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames25.ts === +class Base { +>Base : Base + + bar() { +>bar : () => number + + return 0; + } +} +class C extends Base { +>C : C +>Base : Base + + foo() { +>foo : () => number + + var obj = { +>obj : {} +>{ [super.bar()]() { } } : {} + + [super.bar()]() { } +>super.bar() : number +>super.bar : () => number +>super : Base +>bar : () => number + + }; + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames26.errors.txt b/tests/baselines/reference/computedPropertyNames26.errors.txt new file mode 100644 index 00000000000..bbe51c6a0c8 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames26.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts (1 errors) ==== + class Base { + bar() { + return 0; + } + } + class C extends Base { + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + [ + { [super.bar()]: 1 }[0] + ~~~~~ +!!! error TS2466: 'super' cannot be referenced in a computed property name. + ]() { } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames26.js b/tests/baselines/reference/computedPropertyNames26.js new file mode 100644 index 00000000000..96760fc279c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames26.js @@ -0,0 +1,40 @@ +//// [computedPropertyNames26.ts] +class Base { + bar() { + return 0; + } +} +class C extends Base { + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + [ + { [super.bar()]: 1 }[0] + ]() { } +} + +//// [computedPropertyNames26.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + Base.prototype.bar = function () { + return 0; + }; + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + C.prototype[{ [super.bar.call(this)]: 1 }[0]] = function () { + }; + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames27.errors.txt b/tests/baselines/reference/computedPropertyNames27.errors.txt new file mode 100644 index 00000000000..c2872197363 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames27.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts(4,7): error TS2466: 'super' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts (1 errors) ==== + class Base { + } + class C extends Base { + [(super(), "prop")]() { } + ~~~~~ +!!! error TS2466: 'super' cannot be referenced in a computed property name. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames27.js b/tests/baselines/reference/computedPropertyNames27.js new file mode 100644 index 00000000000..71db977e9b6 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames27.js @@ -0,0 +1,28 @@ +//// [computedPropertyNames27.ts] +class Base { +} +class C extends Base { + [(super(), "prop")]() { } +} + +//// [computedPropertyNames27.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + C.prototype[(_super.call(this), "prop")] = function () { + }; + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames28.js b/tests/baselines/reference/computedPropertyNames28.js new file mode 100644 index 00000000000..96c7cd082f1 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames28.js @@ -0,0 +1,35 @@ +//// [computedPropertyNames28.ts] +class Base { +} +class C extends Base { + constructor() { + super(); + var obj = { + [(super(), "prop")]() { } + }; + } +} + +//// [computedPropertyNames28.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.call(this); + var obj = { + [(_super.call(this), "prop")]() { + } + }; + } + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames28.types b/tests/baselines/reference/computedPropertyNames28.types new file mode 100644 index 00000000000..2adf52f8c5f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames28.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames28.ts === +class Base { +>Base : Base +} +class C extends Base { +>C : C +>Base : Base + + constructor() { + super(); +>super() : void +>super : typeof Base + + var obj = { +>obj : {} +>{ [(super(), "prop")]() { } } : {} + + [(super(), "prop")]() { } +>(super(), "prop") : string +>super(), "prop" : string +>super() : void +>super : typeof Base + + }; + } +} diff --git a/tests/baselines/reference/computedPropertyNames29.js b/tests/baselines/reference/computedPropertyNames29.js new file mode 100644 index 00000000000..dc45746c63c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames29.js @@ -0,0 +1,28 @@ +//// [computedPropertyNames29.ts] +class C { + bar() { + () => { + var obj = { + [this.bar()]() { } // needs capture + }; + } + return 0; + } +} + +//// [computedPropertyNames29.js] +var C = (function () { + function C() { + } + C.prototype.bar = function () { + var _this = this; + (function () { + var obj = { + [_this.bar()]() { + } // needs capture + }; + }); + return 0; + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames29.types b/tests/baselines/reference/computedPropertyNames29.types new file mode 100644 index 00000000000..ed4db5862e9 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames29.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames29.ts === +class C { +>C : C + + bar() { +>bar : () => number + + () => { +>() => { var obj = { [this.bar()]() { } // needs capture }; } : () => void + + var obj = { +>obj : {} +>{ [this.bar()]() { } // needs capture } : {} + + [this.bar()]() { } // needs capture +>this.bar() : number +>this.bar : () => number +>this : C +>bar : () => number + + }; + } + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames30.errors.txt b/tests/baselines/reference/computedPropertyNames30.errors.txt new file mode 100644 index 00000000000..f7b6411f867 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames30.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts (1 errors) ==== + class Base { + } + class C extends Base { + constructor() { + super(); + () => { + var obj = { + // Ideally, we would capture this. But the reference is + // illegal, and not capturing this is consistent with + //treatment of other similar violations. + [(super(), "prop")]() { } + ~~~~~ +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors + }; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames30.js b/tests/baselines/reference/computedPropertyNames30.js new file mode 100644 index 00000000000..c10ba51316d --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames30.js @@ -0,0 +1,45 @@ +//// [computedPropertyNames30.ts] +class Base { +} +class C extends Base { + constructor() { + super(); + () => { + var obj = { + // Ideally, we would capture this. But the reference is + // illegal, and not capturing this is consistent with + //treatment of other similar violations. + [(super(), "prop")]() { } + }; + } + } +} + +//// [computedPropertyNames30.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.call(this); + (function () { + var obj = { + // Ideally, we would capture this. But the reference is + // illegal, and not capturing this is consistent with + //treatment of other similar violations. + [(_super.call(this), "prop")]() { + } + }; + }); + } + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames31.js b/tests/baselines/reference/computedPropertyNames31.js new file mode 100644 index 00000000000..bf75ac2be74 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames31.js @@ -0,0 +1,49 @@ +//// [computedPropertyNames31.ts] +class Base { + bar() { + return 0; + } +} +class C extends Base { + foo() { + () => { + var obj = { + [super.bar()]() { } // needs capture + }; + } + return 0; + } +} + +//// [computedPropertyNames31.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Base = (function () { + function Base() { + } + Base.prototype.bar = function () { + return 0; + }; + return Base; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + C.prototype.foo = function () { + var _this = this; + (function () { + var obj = { + [_super.prototype.bar.call(_this)]() { + } // needs capture + }; + }); + return 0; + }; + return C; +})(Base); diff --git a/tests/baselines/reference/computedPropertyNames31.types b/tests/baselines/reference/computedPropertyNames31.types new file mode 100644 index 00000000000..90e73bc3dcb --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames31.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames31.ts === +class Base { +>Base : Base + + bar() { +>bar : () => number + + return 0; + } +} +class C extends Base { +>C : C +>Base : Base + + foo() { +>foo : () => number + + () => { +>() => { var obj = { [super.bar()]() { } // needs capture }; } : () => void + + var obj = { +>obj : {} +>{ [super.bar()]() { } // needs capture } : {} + + [super.bar()]() { } // needs capture +>super.bar() : number +>super.bar : () => number +>super : Base +>bar : () => number + + }; + } + return 0; + } +} diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts new file mode 100644 index 00000000000..dc3a9541e11 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Base { + bar() { + return 0; + } +} +class C extends Base { + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + [super.bar()]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames25.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames25.ts new file mode 100644 index 00000000000..bc07847b251 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames25.ts @@ -0,0 +1,14 @@ +// @target: es6 +class Base { + bar() { + return 0; + } +} +class C extends Base { + foo() { + var obj = { + [super.bar()]() { } + }; + return 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts new file mode 100644 index 00000000000..6ef32397f54 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts @@ -0,0 +1,13 @@ +// @target: es6 +class Base { + bar() { + return 0; + } +} +class C extends Base { + // Gets emitted as super, not _super, which is consistent with + // use of super in static properties initializers. + [ + { [super.bar()]: 1 }[0] + ]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts new file mode 100644 index 00000000000..be19acd4729 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts @@ -0,0 +1,6 @@ +// @target: es6 +class Base { +} +class C extends Base { + [(super(), "prop")]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames28.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames28.ts new file mode 100644 index 00000000000..f9b14c3a75c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames28.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Base { +} +class C extends Base { + constructor() { + super(); + var obj = { + [(super(), "prop")]() { } + }; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames29.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames29.ts new file mode 100644 index 00000000000..abf213b4c75 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames29.ts @@ -0,0 +1,11 @@ +// @target: es6 +class C { + bar() { + () => { + var obj = { + [this.bar()]() { } // needs capture + }; + } + return 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts new file mode 100644 index 00000000000..5fba13388f8 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts @@ -0,0 +1,16 @@ +// @target: es6 +class Base { +} +class C extends Base { + constructor() { + super(); + () => { + var obj = { + // Ideally, we would capture this. But the reference is + // illegal, and not capturing this is consistent with + //treatment of other similar violations. + [(super(), "prop")]() { } + }; + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames31.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames31.ts new file mode 100644 index 00000000000..0ee8a0284a3 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames31.ts @@ -0,0 +1,16 @@ +// @target: es6 +class Base { + bar() { + return 0; + } +} +class C extends Base { + foo() { + () => { + var obj = { + [super.bar()]() { } // needs capture + }; + } + return 0; + } +} \ No newline at end of file From 89f36bb9c53b7c9511736c179aeda072179ff943 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 19 Jan 2015 18:44:15 -0800 Subject: [PATCH 23/71] Disallow computed properties referencing type parameters from containing type --- src/compiler/checker.ts | 10 +++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ .../computedPropertyNames32.errors.txt | 13 +++++++++ .../reference/computedPropertyNames32.js | 23 ++++++++++++++++ .../reference/computedPropertyNames33.js | 27 +++++++++++++++++++ .../reference/computedPropertyNames33.types | 25 +++++++++++++++++ .../computedPropertyNames34.errors.txt | 15 +++++++++++ .../reference/computedPropertyNames34.js | 27 +++++++++++++++++++ .../computedPropertyNames35.errors.txt | 14 ++++++++++ .../computedPropertyNames32.ts | 8 ++++++ .../computedPropertyNames33.ts | 10 +++++++ .../computedPropertyNames34.ts | 10 +++++++ .../computedPropertyNames35.ts | 6 +++++ 14 files changed, 193 insertions(+) create mode 100644 tests/baselines/reference/computedPropertyNames32.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames32.js create mode 100644 tests/baselines/reference/computedPropertyNames33.js create mode 100644 tests/baselines/reference/computedPropertyNames33.types create mode 100644 tests/baselines/reference/computedPropertyNames34.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames34.js create mode 100644 tests/baselines/reference/computedPropertyNames35.errors.txt create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames33.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1fc3227e5ec..42612ed4cdc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -335,6 +335,16 @@ module ts { break loop; } break; + case SyntaxKind.ComputedPropertyName: + var grandparent = location.parent.parent; + if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) { + // A reference to this grandparent's type parameters would be an error + if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) { + error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_contained_type); + return undefined; + } + } + break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0a8c3a7edfe..fc47f0257a7 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -302,6 +302,7 @@ module ts { A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', or 'any'." }, this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." }, super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." }, + A_computed_property_name_cannot_reference_a_type_parameter_from_its_contained_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its contained type." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2d1b4e4daf0..6b00591556f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1302,6 +1302,10 @@ "category": "Error", "code": 2466 }, + "A computed property name cannot reference a type parameter from its contained type.": { + "category": "Error", + "code": 2466 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/computedPropertyNames32.errors.txt b/tests/baselines/reference/computedPropertyNames32.errors.txt new file mode 100644 index 00000000000..8a7b0995153 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames32.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts(6,10): error TS2466: A computed property name cannot reference a type parameter from its contained type. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts (1 errors) ==== + function foo() { return '' } + class C { + bar() { + return 0; + } + [foo()]() { } + ~ +!!! error TS2466: A computed property name cannot reference a type parameter from its contained type. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames32.js b/tests/baselines/reference/computedPropertyNames32.js new file mode 100644 index 00000000000..d3e98681369 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames32.js @@ -0,0 +1,23 @@ +//// [computedPropertyNames32.ts] +function foo() { return '' } +class C { + bar() { + return 0; + } + [foo()]() { } +} + +//// [computedPropertyNames32.js] +function foo() { + return ''; +} +var C = (function () { + function C() { + } + C.prototype.bar = function () { + return 0; + }; + C.prototype[foo()] = function () { + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames33.js b/tests/baselines/reference/computedPropertyNames33.js new file mode 100644 index 00000000000..554ec315897 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames33.js @@ -0,0 +1,27 @@ +//// [computedPropertyNames33.ts] +function foo() { return '' } +class C { + bar() { + var obj = { + [foo()]() { } + }; + return 0; + } +} + +//// [computedPropertyNames33.js] +function foo() { + return ''; +} +var C = (function () { + function C() { + } + C.prototype.bar = function () { + var obj = { + [foo()]() { + } + }; + return 0; + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames33.types b/tests/baselines/reference/computedPropertyNames33.types new file mode 100644 index 00000000000..8cbe8e93ef2 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames33.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames33.ts === +function foo() { return '' } +>foo : () => string +>T : T + +class C { +>C : C +>T : T + + bar() { +>bar : () => number + + var obj = { +>obj : {} +>{ [foo()]() { } } : {} + + [foo()]() { } +>foo() : string +>foo : () => string +>T : T + + }; + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames34.errors.txt b/tests/baselines/reference/computedPropertyNames34.errors.txt new file mode 100644 index 00000000000..c6d4a9aa4eb --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames34.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts(5,18): error TS2302: Static members cannot reference class type parameters. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts (1 errors) ==== + function foo() { return '' } + class C { + static bar() { + var obj = { + [foo()]() { } + ~ +!!! error TS2302: Static members cannot reference class type parameters. + }; + return 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames34.js b/tests/baselines/reference/computedPropertyNames34.js new file mode 100644 index 00000000000..f1d774139b1 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames34.js @@ -0,0 +1,27 @@ +//// [computedPropertyNames34.ts] +function foo() { return '' } +class C { + static bar() { + var obj = { + [foo()]() { } + }; + return 0; + } +} + +//// [computedPropertyNames34.js] +function foo() { + return ''; +} +var C = (function () { + function C() { + } + C.bar = function () { + var obj = { + [foo()]() { + } + }; + return 0; + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames35.errors.txt b/tests/baselines/reference/computedPropertyNames35.errors.txt new file mode 100644 index 00000000000..665831d6382 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames35.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,5): error TS1169: Computed property names are not allowed in interfaces. +tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,10): error TS2466: A computed property name cannot reference a type parameter from its contained type. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts (2 errors) ==== + function foo() { return '' } + interface I { + bar(): string; + [foo()](): void; + ~~~~~~~~~~ +!!! error TS1169: Computed property names are not allowed in interfaces. + ~ +!!! error TS2466: A computed property name cannot reference a type parameter from its contained type. + } \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts new file mode 100644 index 00000000000..bf888a0c44b --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts @@ -0,0 +1,8 @@ +// @target: es6 +function foo() { return '' } +class C { + bar() { + return 0; + } + [foo()]() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames33.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames33.ts new file mode 100644 index 00000000000..2a62d003a2e --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames33.ts @@ -0,0 +1,10 @@ +// @target: es6 +function foo() { return '' } +class C { + bar() { + var obj = { + [foo()]() { } + }; + return 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts new file mode 100644 index 00000000000..2a56735701c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts @@ -0,0 +1,10 @@ +// @target: es6 +function foo() { return '' } +class C { + static bar() { + var obj = { + [foo()]() { } + }; + return 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts new file mode 100644 index 00000000000..f2e2929bf75 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts @@ -0,0 +1,6 @@ +// @target: es6 +function foo() { return '' } +interface I { + bar(): string; + [foo()](): void; +} \ No newline at end of file From 13ba516a7aba85ae50de905a56d680241bf36717 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 19 Jan 2015 21:37:21 -0800 Subject: [PATCH 24/71] Address CR feedback; refactor out tsc invocation --- scripts/bisect-test.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/bisect-test.ts b/scripts/bisect-test.ts index 6ad53991462..93a516bc899 100644 --- a/scripts/bisect-test.ts +++ b/scripts/bisect-test.ts @@ -3,16 +3,23 @@ import cp = require('child_process'); import fs = require('fs'); +// Slice off 'node bisect-test.js' from the commandline args var args = process.argv.slice(2); +function tsc(tscArgs: string, onExit: (exitCode: number) => void) { + var tsc = cp.exec('node built/local/tsc.js ' + tscArgs,() => void 0); + tsc.on('close', tscExitCode => { + onExit(tscExitCode); + }); +} + var jake = cp.exec('jake clean local', () => void 0); -jake.on('close', code => { - if (code === 0) { +jake.on('close', jakeExitCode => { + if (jakeExitCode === 0) { // See what we're being asked to do if (args[1] === 'compiles' || args[1] === '!compiles') { - var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); - tsc.on('close', tscCode => { - if ((tscCode === 0) === (args[1] === 'compiles')) { + tsc(args[0], tscExitCode => { + if ((tscExitCode === 0) === (args[1] === 'compiles')) { console.log('Good'); process.exit(0); // Good } else { @@ -21,8 +28,7 @@ jake.on('close', code => { } }); } else if (args[1] === 'emits' || args[1] === '!emits') { - var tsc = cp.exec('node built/local/tsc.js ' + args[0], () => void 0); - tsc.on('close', tscCode => { + tsc(args[0], tscExitCode => { fs.readFile(args[2], 'utf-8', (err, data) => { var doesContains = data.indexOf(args[3]) >= 0; if (doesContains === (args[1] === 'emits')) { @@ -38,10 +44,12 @@ jake.on('close', code => { console.log('Unknown command line arguments.'); console.log('Usage (compile errors): git bisect run scripts\bisect.js "foo.ts --module amd" compiles'); console.log('Usage (emit check): git bisect run scripts\bisect.js bar.ts emits bar.js "_this = this"'); + // Aborts the 'git bisect run' process process.exit(-1); } } else { - // Build failed + // Compiler build failed; skip this commit + console.log('Skip'); process.exit(125); // bisect skip } }); From fa239326f098bd2559c08490a33e7898a9f34dfa Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 20 Jan 2015 14:18:22 -0800 Subject: [PATCH 25/71] Elaborate relational errors at least once when reporting them --- src/compiler/checker.ts | 36 ++-- src/compiler/types.ts | 6 + .../reference/arrayAssignmentTest3.errors.txt | 2 + .../reference/assignmentCompatBug5.errors.txt | 6 + ...terfaceWithStringIndexSignature.errors.txt | 2 + ...ConstrainedToOtherTypeParameter.errors.txt | 4 +- ...onstrainedToOtherTypeParameter2.errors.txt | 4 + ...fGenericFunctionTypedArguments1.errors.txt | 4 + ...ontextualTypingOfObjectLiterals.errors.txt | 4 +- ...structuringParameterProperties2.errors.txt | 4 + .../reference/elaboratedErrors.errors.txt | 52 ++++++ ...ssignmentConstrainedGenericType.errors.txt | 2 + .../reference/functionCall7.errors.txt | 2 + ...functionConstraintSatisfaction2.errors.txt | 8 + ...edMethodWithOverloadedArguments.errors.txt | 16 ++ ...nstraintsTypeArgumentInference2.errors.txt | 2 + ...lWithConstructorTypedArguments5.errors.txt | 8 + ...llWithGenericSignatureArguments.errors.txt | 4 + ...lWithGenericSignatureArguments2.errors.txt | 10 ++ ...lWithGenericSignatureArguments3.errors.txt | 2 + ...ricCallWithNonSymmetricSubtypes.errors.txt | 4 + .../genericCallWithObjectTypeArgs.errors.txt | 2 + ...thObjectTypeArgsAndConstraints3.errors.txt | 2 + .../reference/genericCombinators2.errors.txt | 6 +- .../reference/genericConstraint2.errors.txt | 4 +- .../reference/genericRestArgs.errors.txt | 4 +- .../reference/incompatibleTypes.errors.txt | 4 + .../indexSignatureTypeInference.errors.txt | 2 + .../interfaceAssignmentCompat.errors.txt | 6 + .../reference/maxConstraints.errors.txt | 4 +- ...handPropertiesFunctionArgument2.errors.txt | 2 + .../optionalBindingParameters1.errors.txt | 6 +- ...alBindingParametersInOverloads1.errors.txt | 6 +- .../overloadResolutionOverCTLambda.errors.txt | 4 +- ...nWithConstraintCheckingDeferred.errors.txt | 6 + .../overloadsWithProvisionalErrors.errors.txt | 4 + .../reference/parser536727.errors.txt | 4 + .../reference/promiseChaining1.errors.txt | 2 + .../reference/promiseChaining2.errors.txt | 2 + .../reference/promisePermutations.errors.txt | 85 ++++++++- .../reference/promisePermutations2.errors.txt | 169 +++++++++++++++--- .../reference/promisePermutations3.errors.txt | 60 +++++++ .../recursiveClassReferenceTest.errors.txt | 2 + .../subtypingWithCallSignaturesA.errors.txt | 4 +- ...ateStringsTypeArgumentInference.errors.txt | 2 + ...StringsTypeArgumentInferenceES6.errors.txt | 2 + .../reference/typeArgInference2.errors.txt | 4 +- ...peArgumentConstraintResolution1.errors.txt | 2 + .../typeArgumentInference.errors.txt | 2 + ...entInferenceConstructSignatures.errors.txt | 14 ++ .../typeArgumentInferenceErrors.errors.txt | 12 ++ ...renceWithConstraintAsCommonRoot.errors.txt | 4 +- ...rgumentInferenceWithConstraints.errors.txt | 14 ++ .../reference/typeAssertions.errors.txt | 4 + .../typeIdentityConsidersBrands.errors.txt | 2 + .../reference/typeOfOnTypeArg.errors.txt | 2 + .../undeclaredModuleError.errors.txt | 2 + tests/cases/compiler/elaboratedErrors.ts | 25 +++ 58 files changed, 613 insertions(+), 50 deletions(-) create mode 100644 tests/baselines/reference/elaboratedErrors.errors.txt create mode 100644 tests/cases/compiler/elaboratedErrors.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ad62c1d639..66220682746 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3365,9 +3365,9 @@ module ts { // TYPE CHECKING - var subtypeRelation: Map = {}; - var assignableRelation: Map = {}; - var identityRelation: Map = {}; + var subtypeRelation: Map = {}; + var assignableRelation: Map = {}; + var identityRelation: Map = {}; function isTypeIdenticalTo(source: Type, target: Type): boolean { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); @@ -3402,7 +3402,7 @@ module ts { function checkTypeRelatedTo( source: Type, target: Type, - relation: Map, + relation: Map, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { @@ -3422,6 +3422,14 @@ module ts { error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); } else if (errorInfo) { + // If we already computed this relation, but in a context where we didn't want to report errors (e.g. overload resolution), + // then we'll only have a top-level error (e.g. 'Class X does not implement interface Y') without any details. If this happened, + // request a recompuation to get a complete error message. This will be skipped if we've already done this computation in a context + // where errors were being reported. + if (errorInfo.next === undefined) { + errorInfo = undefined; + isRelatedTo(source, target, errorNode !== undefined, headMessage, true); + } if (containingMessageChain) { errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } @@ -3437,7 +3445,7 @@ module ts { // Ternary.True if they are related with no assumptions, // Ternary.Maybe if they are related with assumptions of other relationships, or // Ternary.False if they are not related. - function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary { + function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, mustRecompute = false): Ternary { var result: Ternary; // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; @@ -3504,7 +3512,7 @@ module ts { // identity relation does not use apparent type var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType && - (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors))) { + (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, mustRecompute))) { errorInfo = saveErrorInfo; return result; } @@ -3595,14 +3603,16 @@ module ts { // Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are // equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion // and issue an error. Otherwise, actually compare the structure of the two types. - function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { + function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean, elaborateErrors = false): Ternary { if (overflow) { return Ternary.False; } var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; var related = relation[id]; if (related !== undefined) { - return related ? Ternary.True : Ternary.False; + if (!elaborateErrors || related === RelationComparisonResult.FailedAndReported) { + return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False; + } } if (depth > 0) { for (var i = 0; i < depth; i++) { @@ -3654,12 +3664,14 @@ module ts { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1]; - copyMap(/*source*/maybeCache, /*target*/destinationCache); + for (var key in maybeCache) { + destinationCache[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : RelationComparisonResult.Failed; + } } else { // A false result goes straight into global cache (when something is false under assumptions it // will also be false without assumptions) - relation[id] = false; + relation[id] = reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed; } return result; } @@ -5865,7 +5877,7 @@ module ts { return typeArgumentsAreAssignable; } - function checkApplicableSignature(node: CallLikeExpression, args: Node[], signature: Signature, relation: Map, excludeArgument: boolean[], reportErrors: boolean) { + function checkApplicableSignature(node: CallLikeExpression, args: Node[], signature: Signature, relation: Map, excludeArgument: boolean[], reportErrors: boolean) { for (var i = 0; i < args.length; i++) { var arg = args[i]; var argType: Type; @@ -6059,7 +6071,7 @@ module ts { return resolveErrorCall(node); - function chooseOverload(candidates: Signature[], relation: Map) { + function chooseOverload(candidates: Signature[], relation: Map) { for (var i = 0; i < candidates.length; i++) { if (!hasCorrectArity(node, args, candidates[i])) { continue; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9ebab8dc220..9157786737b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -330,6 +330,12 @@ module ts { HasAggregatedChildData = 1 << 6 } + export const enum RelationComparisonResult { + Succeeded = 0, + Failed = 1, + FailedAndReported = 2 + } + export interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; diff --git a/tests/baselines/reference/arrayAssignmentTest3.errors.txt b/tests/baselines/reference/arrayAssignmentTest3.errors.txt index 1c88408eb52..31347782c5d 100644 --- a/tests/baselines/reference/arrayAssignmentTest3.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest3.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/arrayAssignmentTest3.ts(12,25): error TS2345: Argument of type 'B' is not assignable to parameter of type 'B[]'. + Property 'length' is missing in type 'B'. ==== tests/cases/compiler/arrayAssignmentTest3.ts (1 errors) ==== @@ -16,5 +17,6 @@ tests/cases/compiler/arrayAssignmentTest3.ts(12,25): error TS2345: Argument of t var xx = new a(null, 7, new B()); ~~~~~~~ !!! error TS2345: Argument of type 'B' is not assignable to parameter of type 'B[]'. +!!! error TS2345: Property 'length' is missing in type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatBug5.errors.txt b/tests/baselines/reference/assignmentCompatBug5.errors.txt index a015cc3bbcf..fd13a07a948 100644 --- a/tests/baselines/reference/assignmentCompatBug5.errors.txt +++ b/tests/baselines/reference/assignmentCompatBug5.errors.txt @@ -3,7 +3,10 @@ tests/cases/compiler/assignmentCompatBug5.ts(2,6): error TS2345: Argument of typ tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/assignmentCompatBug5.ts(8,6): error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'. + Types of parameters 's' and 'n' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of type '(n: number) => void' is not assignable to parameter of type '(n: number) => number'. + Type 'void' is not assignable to type 'number'. ==== tests/cases/compiler/assignmentCompatBug5.ts (4 errors) ==== @@ -23,8 +26,11 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ foo3((s:string) => { }); ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'. +!!! error TS2345: Types of parameters 's' and 'n' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. foo3((n) => { return; }); ~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(n: number) => void' is not assignable to parameter of type '(n: number) => number'. +!!! error TS2345: Type 'void' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatInterfaceWithStringIndexSignature.errors.txt b/tests/baselines/reference/assignmentCompatInterfaceWithStringIndexSignature.errors.txt index f972c9a925e..65c1d307793 100644 --- a/tests/baselines/reference/assignmentCompatInterfaceWithStringIndexSignature.errors.txt +++ b/tests/baselines/reference/assignmentCompatInterfaceWithStringIndexSignature.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/assignmentCompatInterfaceWithStringIndexSignature.ts(15,5): error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'IHandlerMap'. + Index signature is missing in type 'Foo'. ==== tests/cases/compiler/assignmentCompatInterfaceWithStringIndexSignature.ts (1 errors) ==== @@ -19,4 +20,5 @@ tests/cases/compiler/assignmentCompatInterfaceWithStringIndexSignature.ts(15,5): Biz(new Foo()); ~~~~~~~~~ !!! error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'IHandlerMap'. +!!! error TS2345: Index signature is missing in type 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.errors.txt b/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.errors.txt index be465275de5..f9edcf4eef6 100644 --- a/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.errors.txt +++ b/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts(19,59): error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'. + Type 'B' is not assignable to type 'C'. ==== tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts (1 errors) ==== @@ -22,4 +23,5 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete // Ok to go down the chain, but error to try to climb back up (new Chain(new A)).then(a => new B).then(b => new C).then(c => new B).then(b => new A); ~~~~~~~~~~ -!!! error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'. \ No newline at end of file +!!! error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'. +!!! error TS2345: Type 'B' is not assignable to type 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.errors.txt b/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.errors.txt index e307cc9be89..8f5924586df 100644 --- a/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.errors.txt +++ b/tests/baselines/reference/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.errors.txt @@ -1,5 +1,7 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(7,43): error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'. + Type 'T' is not assignable to type 'S'. tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(10,29): error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'. + Type 'T' is not assignable to type 'S'. tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(32,9): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(36,9): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(37,9): error TS2322: Type 'string' is not assignable to type 'number'. @@ -15,11 +17,13 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete (new Chain(t)).then(tt => s).then(ss => t); ~~~~~~~ !!! error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'. +!!! error TS2345: Type 'T' is not assignable to type 'S'. // But error to try to climb up the chain (new Chain(s)).then(ss => t); ~~~~~~~ !!! error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'. +!!! error TS2345: Type 'T' is not assignable to type 'S'. // Staying at T or S should be fine (new Chain(t)).then(tt => t).then(tt => t).then(tt => t); diff --git a/tests/baselines/reference/contextualTypingOfGenericFunctionTypedArguments1.errors.txt b/tests/baselines/reference/contextualTypingOfGenericFunctionTypedArguments1.errors.txt index f7bac878950..c7b15e8efef 100644 --- a/tests/baselines/reference/contextualTypingOfGenericFunctionTypedArguments1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfGenericFunctionTypedArguments1.errors.txt @@ -1,5 +1,7 @@ tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(16,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. + Type 'string' is not assignable to type 'Date'. tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(17,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. + Type 'string' is not assignable to type 'Date'. ==== tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts (2 errors) ==== @@ -21,7 +23,9 @@ tests/cases/compiler/contextualTypingOfGenericFunctionTypedArguments1.ts(17,32): var r5 = _.forEach(c2, f); ~ !!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. +!!! error TS2345: Type 'string' is not assignable to type 'Date'. var r6 = _.forEach(c2, (x) => { return x.toFixed() }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. +!!! error TS2345: Type 'string' is not assignable to type 'Date'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt b/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt index 5d41b312f72..ac8063a4378 100644 --- a/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt +++ b/tests/baselines/reference/contextualTypingOfObjectLiterals.errors.txt @@ -1,6 +1,7 @@ tests/cases/compiler/contextualTypingOfObjectLiterals.ts(4,1): error TS2322: Type '{ x: string; }' is not assignable to type '{ [x: string]: string; }'. Index signature is missing in type '{ x: string; }'. tests/cases/compiler/contextualTypingOfObjectLiterals.ts(10,3): error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. + Index signature is missing in type '{ x: string; }'. ==== tests/cases/compiler/contextualTypingOfObjectLiterals.ts (2 errors) ==== @@ -18,4 +19,5 @@ tests/cases/compiler/contextualTypingOfObjectLiterals.ts(10,3): error TS2345: Ar f(obj1); // Ok f(obj2); // Error - indexer doesn't match ~~~~ -!!! error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. \ No newline at end of file +!!! error TS2345: Argument of type '{ x: string; }' is not assignable to parameter of type '{ [s: string]: string; }'. +!!! error TS2345: Index signature is missing in type '{ x: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties2.errors.txt b/tests/baselines/reference/destructuringParameterProperties2.errors.txt index 61c0e61611a..bc7588a853d 100644 --- a/tests/baselines/reference/destructuringParameterProperties2.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties2.errors.txt @@ -6,6 +6,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(9 tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'. tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. + Types of property '2' are incompatible. + Type 'string' is not assignable to type 'boolean'. ==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts (8 errors) ==== @@ -46,6 +48,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties2.ts(2 var x = new C1(undefined, [0, undefined, ""]); ~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'boolean'. var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()]; var y = new C1(10, [0, "", true]); diff --git a/tests/baselines/reference/elaboratedErrors.errors.txt b/tests/baselines/reference/elaboratedErrors.errors.txt new file mode 100644 index 00000000000..7bc83a19a50 --- /dev/null +++ b/tests/baselines/reference/elaboratedErrors.errors.txt @@ -0,0 +1,52 @@ +tests/cases/compiler/elaboratedErrors.ts(10,7): error TS2420: Class 'WorkerFS' incorrectly implements interface 'FileSystem'. + Types of property 'read' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/elaboratedErrors.ts(20,1): error TS2322: Type 'Beta' is not assignable to type 'Alpha'. + Property 'x' is missing in type 'Beta'. +tests/cases/compiler/elaboratedErrors.ts(21,1): error TS2322: Type 'Beta' is not assignable to type 'Alpha'. +tests/cases/compiler/elaboratedErrors.ts(24,1): error TS2322: Type 'Alpha' is not assignable to type 'Beta'. + Property 'y' is missing in type 'Alpha'. +tests/cases/compiler/elaboratedErrors.ts(25,1): error TS2322: Type 'Alpha' is not assignable to type 'Beta'. + + +==== tests/cases/compiler/elaboratedErrors.ts (5 errors) ==== + interface FileSystem { + read: number; + } + + function fn(s: WorkerFS): void; + function fn(s: FileSystem): void; + function fn(s: FileSystem|WorkerFS) { } + + // This should issue a large error, not a small one + class WorkerFS implements FileSystem { + ~~~~~~~~ +!!! error TS2420: Class 'WorkerFS' incorrectly implements interface 'FileSystem'. +!!! error TS2420: Types of property 'read' are incompatible. +!!! error TS2420: Type 'string' is not assignable to type 'number'. + read: string; + } + + interface Alpha { x: string; } + interface Beta { y: number; } + var x: Alpha; + var y: Beta; + + // Only one of these errors should be large + x = y; + ~ +!!! error TS2322: Type 'Beta' is not assignable to type 'Alpha'. +!!! error TS2322: Property 'x' is missing in type 'Beta'. + x = y; + ~ +!!! error TS2322: Type 'Beta' is not assignable to type 'Alpha'. + + // Only one of these errors should be large + y = x; + ~ +!!! error TS2322: Type 'Alpha' is not assignable to type 'Beta'. +!!! error TS2322: Property 'y' is missing in type 'Alpha'. + y = x; + ~ +!!! error TS2322: Type 'Alpha' is not assignable to type 'Beta'. + \ No newline at end of file diff --git a/tests/baselines/reference/exportAssignmentConstrainedGenericType.errors.txt b/tests/baselines/reference/exportAssignmentConstrainedGenericType.errors.txt index cf63c48925f..946bc8ee8b1 100644 --- a/tests/baselines/reference/exportAssignmentConstrainedGenericType.errors.txt +++ b/tests/baselines/reference/exportAssignmentConstrainedGenericType.errors.txt @@ -1,4 +1,5 @@ tests/cases/conformance/externalModules/foo_1.ts(2,17): error TS2345: Argument of type 'boolean' is not assignable to parameter of type '{ a: string; b: number; }'. + Property 'a' is missing in type 'Boolean'. ==== tests/cases/conformance/externalModules/foo_1.ts (1 errors) ==== @@ -6,6 +7,7 @@ tests/cases/conformance/externalModules/foo_1.ts(2,17): error TS2345: Argument o var x = new foo(true); // Should error ~~~~ !!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type '{ a: string; b: number; }'. +!!! error TS2345: Property 'a' is missing in type 'Boolean'. var y = new foo({a: "test", b: 42}); // Should be OK var z: number = y.test.b; ==== tests/cases/conformance/externalModules/foo_0.ts (0 errors) ==== diff --git a/tests/baselines/reference/functionCall7.errors.txt b/tests/baselines/reference/functionCall7.errors.txt index 576ea9c266e..19e572fa58d 100644 --- a/tests/baselines/reference/functionCall7.errors.txt +++ b/tests/baselines/reference/functionCall7.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/functionCall7.ts(5,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/functionCall7.ts(6,5): error TS2345: Argument of type 'number' is not assignable to parameter of type 'c1'. + Property 'a' is missing in type 'Number'. tests/cases/compiler/functionCall7.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target. @@ -14,6 +15,7 @@ tests/cases/compiler/functionCall7.ts(7,1): error TS2346: Supplied parameters do foo(4); ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'c1'. +!!! error TS2345: Property 'a' is missing in type 'Number'. foo(); ~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt b/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt index 4af5c01c505..03ce9952938 100644 --- a/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt +++ b/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt @@ -1,8 +1,11 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(5,5): error TS2345: Argument of type 'number' is not assignable to parameter of type 'Function'. + Property 'apply' is missing in type 'Number'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(6,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(23,14): error TS2345: Argument of type 'Function' is not assignable to parameter of type '(x: string) => string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(24,15): error TS2345: Argument of type '(x: string[]) => string[]' is not assignable to parameter of type '(x: string) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string[]' is not assignable to type 'string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(25,15): error TS2345: Argument of type 'typeof C' is not assignable to parameter of type '(x: string) => string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(26,15): error TS2345: Argument of type 'new (x: string) => string' is not assignable to parameter of type '(x: string) => string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(28,16): error TS2345: Argument of type '(x: U, y: V) => U' is not assignable to parameter of type '(x: string) => string'. @@ -11,6 +14,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(34,16): error TS2345: Argument of type 'F2' is not assignable to parameter of type '(x: string) => string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(36,38): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(37,10): error TS2345: Argument of type 'T' is not assignable to parameter of type '(x: string) => string'. + Type 'void' is not assignable to type 'string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(38,10): error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'. @@ -22,6 +26,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain foo(1); ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'Function'. +!!! error TS2345: Property 'apply' is missing in type 'Number'. foo(() => { }, 1); ~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. @@ -49,6 +54,8 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain var r2 = foo2((x: string[]) => x); ~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string[]) => string[]' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string[]' is not assignable to type 'string'. var r6 = foo2(C); ~ !!! error TS2345: Argument of type 'typeof C' is not assignable to parameter of type '(x: string) => string'. @@ -78,6 +85,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain foo2(x); ~ !!! error TS2345: Argument of type 'T' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Type 'void' is not assignable to type 'string'. foo2(y); ~ !!! error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'. diff --git a/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt b/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt index 8900e975030..428ebecf5b0 100644 --- a/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt +++ b/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt @@ -1,7 +1,15 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(24,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(53,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(69,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(85,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; (b: boolean): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'boolean'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts (4 errors) ==== @@ -31,6 +39,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverl var newPromise = numPromise.then(testFunction); ~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. } ////////////////////////////////////// @@ -62,6 +72,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverl var newPromise = numPromise.then(testFunction); ~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. } ////////////////////////////////////// @@ -80,6 +92,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverl var newPromise = numPromise.then(testFunction); ~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. } ////////////////////////////////////// @@ -98,5 +112,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverl var newPromise = numPromise.then(testFunction); ~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; (b: boolean): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'boolean'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithConstraintsTypeArgumentInference2.errors.txt b/tests/baselines/reference/genericCallWithConstraintsTypeArgumentInference2.errors.txt index 604896319ca..d8228dd2243 100644 --- a/tests/baselines/reference/genericCallWithConstraintsTypeArgumentInference2.errors.txt +++ b/tests/baselines/reference/genericCallWithConstraintsTypeArgumentInference2.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference2.ts(3,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference2.ts(11,26): error TS2345: Argument of type 'number' is not assignable to parameter of type 'Date'. + Property 'toDateString' is missing in type 'Number'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference2.ts (2 errors) ==== @@ -18,4 +19,5 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithCon var r4 = foo(1); // error ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'Date'. +!!! error TS2345: Property 'toDateString' is missing in type 'Number'. var r5 = foo(new Date()); // no error \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithConstructorTypedArguments5.errors.txt b/tests/baselines/reference/genericCallWithConstructorTypedArguments5.errors.txt index 48e615bdb3e..a014ef85b6c 100644 --- a/tests/baselines/reference/genericCallWithConstructorTypedArguments5.errors.txt +++ b/tests/baselines/reference/genericCallWithConstructorTypedArguments5.errors.txt @@ -1,5 +1,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstructorTypedArguments5.ts(11,14): error TS2345: Argument of type '{ cb: new (x: T, y: T) => string; }' is not assignable to parameter of type '{ cb: new (t: any) => string; }'. + Types of property 'cb' are incompatible. + Type 'new (x: T, y: T) => string' is not assignable to type 'new (t: any) => string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstructorTypedArguments5.ts(13,14): error TS2345: Argument of type '{ cb: new (x: string, y: number) => string; }' is not assignable to parameter of type '{ cb: new (t: string) => string; }'. + Types of property 'cb' are incompatible. + Type 'new (x: string, y: number) => string' is not assignable to type 'new (t: string) => string'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstructorTypedArguments5.ts (2 errors) ==== @@ -16,10 +20,14 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithCon var r2 = foo(arg2); // error ~~~~ !!! error TS2345: Argument of type '{ cb: new (x: T, y: T) => string; }' is not assignable to parameter of type '{ cb: new (t: any) => string; }'. +!!! error TS2345: Types of property 'cb' are incompatible. +!!! error TS2345: Type 'new (x: T, y: T) => string' is not assignable to type 'new (t: any) => string'. var arg3: { cb: new (x: string, y: number) => string }; var r3 = foo(arg3); // error ~~~~ !!! error TS2345: Argument of type '{ cb: new (x: string, y: number) => string; }' is not assignable to parameter of type '{ cb: new (t: string) => string; }'. +!!! error TS2345: Types of property 'cb' are incompatible. +!!! error TS2345: Type 'new (x: string, y: number) => string' is not assignable to type 'new (t: string) => string'. function foo2(arg: { cb: new(t: T, t2: T) => U }) { return new arg.cb(null, null); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt index 2d5ad21959e..33c01aa544a 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(18,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'. + Property 'y' is missing in type '{ x: number; z?: number; }'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(19,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'. + Property 'z' is missing in type '{ x: number; y?: number; }'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts (2 errors) ==== @@ -26,10 +28,12 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'. +!!! error TS2453: Property 'y' is missing in type '{ x: number; z?: number; }'. var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y?: number; }'. function other(x: T) { var r6 = foo((a: T) => a, (b: T) => b); // T => T diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt index a8ee6ac6ca9..5b5d4ad66f0 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt @@ -3,10 +3,15 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(16,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. + Types of parameters 'a' and 'x' are incompatible. + Type 'T' is not assignable to type 'Date'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(37,36): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. + Type 'F' is not assignable to type 'E'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(51,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(60,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. + Types of parameters 'a' and 'x' are incompatible. + Type 'T' is not assignable to type 'Date'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,51): error TS2304: Cannot find name 'U'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,57): error TS2304: Cannot find name 'U'. @@ -46,6 +51,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen var r7 = foo2((a: T) => a, (b: T) => b); // error ~~~~~~~~~~~ !!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. +!!! error TS2345: Types of parameters 'a' and 'x' are incompatible. +!!! error TS2345: Type 'T' is not assignable to type 'Date'. var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date } @@ -60,6 +67,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error ~~~~~~~~~~ !!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. +!!! error TS2345: Type 'F' is not assignable to type 'E'. } module TU { @@ -89,6 +97,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen var r7 = foo2((a: T) => a, (b: T) => b); ~~~~~~~~~~~ !!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. +!!! error TS2345: Types of parameters 'a' and 'x' are incompatible. +!!! error TS2345: Type 'T' is not assignable to type 'Date'. var r7b = foo2((a) => a, (b) => b); } diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt index 574cc5ca50d..87ae6b63855 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '(y: string) => string' is not a valid type argument because it is not a supertype of candidate '(a: string) => boolean'. + Type 'boolean' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '(n: Object) => number' is not a valid type argument because it is not a supertype of candidate 'number'. @@ -40,6 +41,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen ~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '(y: string) => string' is not a valid type argument because it is not a supertype of candidate '(a: string) => boolean'. +!!! error TS2453: Type 'boolean' is not assignable to type 'string'. var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error ~~~~ !!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. diff --git a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt index 2efcd043d78..3b896d9a7d8 100644 --- a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt +++ b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(12,9): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'. + Property 'y' is missing in type '{ x: number; z?: number; }'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(13,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'. + Property 'z' is missing in type '{ x: number; y?: number; }'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts (2 errors) ==== @@ -20,10 +22,12 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNon ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'. +!!! error TS2453: Property 'y' is missing in type '{ x: number; z?: number; }'. var r2 = foo(b, a); // { x: number; z?: number; }; ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y?: number; }'. var x: { x: number; }; var y: { x?: number; }; diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt index 97b09a7d43f..ecd76d4ea1b 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts(20,9): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'D'. + Types have separate declarations of a private property 'x'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts (1 errors) ==== @@ -26,4 +27,5 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'D'. +!!! error TS2453: Types have separate declarations of a private property 'x'. var r2 = foo(c1, c1); // ok \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt index 02b38ddeb74..54455782cc2 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(18,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Derived' is not a valid type argument because it is not a supertype of candidate 'Derived2'. + Property 'y' is missing in type 'Derived2'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(20,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -25,6 +26,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj ~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate 'Derived' is not a valid type argument because it is not a supertype of candidate 'Derived2'. +!!! error TS2453: Property 'y' is missing in type 'Derived2'. function f2(a: U) { ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCombinators2.errors.txt b/tests/baselines/reference/genericCombinators2.errors.txt index c09ef79b29b..5be717109c8 100644 --- a/tests/baselines/reference/genericCombinators2.errors.txt +++ b/tests/baselines/reference/genericCombinators2.errors.txt @@ -1,5 +1,7 @@ tests/cases/compiler/genericCombinators2.ts(15,43): error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'. + Type 'string' is not assignable to type 'Date'. tests/cases/compiler/genericCombinators2.ts(16,43): error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'. + Type 'string' is not assignable to type 'Date'. ==== tests/cases/compiler/genericCombinators2.ts (2 errors) ==== @@ -20,6 +22,8 @@ tests/cases/compiler/genericCombinators2.ts(16,43): error TS2345: Argument of ty var r5a = _.map(c2, (x, y) => { return x.toFixed() }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'. +!!! error TS2345: Type 'string' is not assignable to type 'Date'. var r5b = _.map(c2, rf1); ~~~ -!!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'. \ No newline at end of file +!!! error TS2345: Argument of type '(x: number, y: string) => string' is not assignable to parameter of type '(x: number, y: string) => Date'. +!!! error TS2345: Type 'string' is not assignable to type 'Date'. \ No newline at end of file diff --git a/tests/baselines/reference/genericConstraint2.errors.txt b/tests/baselines/reference/genericConstraint2.errors.txt index 3ab29b585d8..c1be6fc2325 100644 --- a/tests/baselines/reference/genericConstraint2.errors.txt +++ b/tests/baselines/reference/genericConstraint2.errors.txt @@ -2,6 +2,7 @@ tests/cases/compiler/genericConstraint2.ts(5,18): error TS2313: Constraint of a tests/cases/compiler/genericConstraint2.ts(11,7): error TS2420: Class 'ComparableString' incorrectly implements interface 'Comparable'. Property 'comparer' is missing in type 'ComparableString'. tests/cases/compiler/genericConstraint2.ts(21,17): error TS2344: Type 'ComparableString' does not satisfy the constraint 'Comparable'. + Property 'comparer' is missing in type 'ComparableString'. ==== tests/cases/compiler/genericConstraint2.ts (3 errors) ==== @@ -32,4 +33,5 @@ tests/cases/compiler/genericConstraint2.ts(21,17): error TS2344: Type 'Comparabl var b = new ComparableString("b"); var c = compare(a, b); ~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'ComparableString' does not satisfy the constraint 'Comparable'. \ No newline at end of file +!!! error TS2344: Type 'ComparableString' does not satisfy the constraint 'Comparable'. +!!! error TS2344: Property 'comparer' is missing in type 'ComparableString'. \ No newline at end of file diff --git a/tests/baselines/reference/genericRestArgs.errors.txt b/tests/baselines/reference/genericRestArgs.errors.txt index 8a977452958..99106ebd795 100644 --- a/tests/baselines/reference/genericRestArgs.errors.txt +++ b/tests/baselines/reference/genericRestArgs.errors.txt @@ -4,6 +4,7 @@ tests/cases/compiler/genericRestArgs.ts(5,34): error TS2345: Argument of type 's tests/cases/compiler/genericRestArgs.ts(10,12): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type 'number' is not assignable to parameter of type 'any[]'. + Property 'length' is missing in type 'Number'. ==== tests/cases/compiler/genericRestArgs.ts (4 errors) ==== @@ -28,4 +29,5 @@ tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type ' var a2Gb = makeArrayG(1, ""); var a2Gc = makeArrayG(1, ""); // error ~ -!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'any[]'. \ No newline at end of file +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'any[]'. +!!! error TS2345: Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/incompatibleTypes.errors.txt b/tests/baselines/reference/incompatibleTypes.errors.txt index 14dfa883f45..01e4531031a 100644 --- a/tests/baselines/reference/incompatibleTypes.errors.txt +++ b/tests/baselines/reference/incompatibleTypes.errors.txt @@ -15,6 +15,8 @@ tests/cases/compiler/incompatibleTypes.ts(33,7): error TS2420: Class 'C4' incorr Type '{ c: { b: string; }; d: string; }' is not assignable to type '{ a: { a: string; }; b: string; }'. Property 'a' is missing in type '{ c: { b: string; }; d: string; }'. tests/cases/compiler/incompatibleTypes.ts(42,5): error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'. + Types of property 'p1' are incompatible. + Type '() => string' is not assignable to type '(s: string) => number'. tests/cases/compiler/incompatibleTypes.ts(49,5): error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'. Property 'c' is missing in type '{ e: number; f: number; }'. tests/cases/compiler/incompatibleTypes.ts(66,5): error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'. @@ -88,6 +90,8 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) => if1(c1); ~~ !!! error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'. +!!! error TS2345: Types of property 'p1' are incompatible. +!!! error TS2345: Type '() => string' is not assignable to type '(s: string) => number'. function of1(n: { a: { a: string; }; b: string; }): number; diff --git a/tests/baselines/reference/indexSignatureTypeInference.errors.txt b/tests/baselines/reference/indexSignatureTypeInference.errors.txt index 55bd2ce884f..f93bfc6ce40 100644 --- a/tests/baselines/reference/indexSignatureTypeInference.errors.txt +++ b/tests/baselines/reference/indexSignatureTypeInference.errors.txt @@ -1,4 +1,5 @@ tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts(18,27): error TS2345: Argument of type 'NumberMap' is not assignable to parameter of type 'StringMap<{}>'. + Index signature is missing in type 'NumberMap'. ==== tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts (1 errors) ==== @@ -22,5 +23,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureType var v1 = stringMapToArray(numberMap); // Error expected here ~~~~~~~~~ !!! error TS2345: Argument of type 'NumberMap' is not assignable to parameter of type 'StringMap<{}>'. +!!! error TS2345: Index signature is missing in type 'NumberMap'. var v1 = stringMapToArray(stringMap); // Ok \ No newline at end of file diff --git a/tests/baselines/reference/interfaceAssignmentCompat.errors.txt b/tests/baselines/reference/interfaceAssignmentCompat.errors.txt index 35cf2df71ff..425aa3b3e97 100644 --- a/tests/baselines/reference/interfaceAssignmentCompat.errors.txt +++ b/tests/baselines/reference/interfaceAssignmentCompat.errors.txt @@ -1,6 +1,9 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(32,18): error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'. + Types of parameters 'a' and 'a' are incompatible. + Type 'IFrenchEye' is not assignable to type 'IEye'. tests/cases/compiler/interfaceAssignmentCompat.ts(37,29): error TS2339: Property '_map' does not exist on type 'typeof Color'. tests/cases/compiler/interfaceAssignmentCompat.ts(42,13): error TS2322: Type 'IEye' is not assignable to type 'IFrenchEye'. + Property 'coleur' is missing in type 'IEye'. tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2322: Type 'IEye[]' is not assignable to type 'IFrenchEye[]'. Type 'IEye' is not assignable to type 'IFrenchEye'. @@ -40,6 +43,8 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2322: Type 'IEy x=x.sort(CompareYeux); // parameter mismatch ~~~~~~~~~~~ !!! error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'. +!!! error TS2345: Types of parameters 'a' and 'a' are incompatible. +!!! error TS2345: Type 'IFrenchEye' is not assignable to type 'IEye'. // type of z inferred from specialized array type var z=x.sort(CompareEyes); // ok @@ -54,6 +59,7 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2322: Type 'IEy eeks[j]=z[j]; // nope: element assignment ~~~~~~~ !!! error TS2322: Type 'IEye' is not assignable to type 'IFrenchEye'. +!!! error TS2322: Property 'coleur' is missing in type 'IEye'. } eeks=z; // nope: array assignment ~~~~ diff --git a/tests/baselines/reference/maxConstraints.errors.txt b/tests/baselines/reference/maxConstraints.errors.txt index 1c3844d6974..16ae5bd2063 100644 --- a/tests/baselines/reference/maxConstraints.errors.txt +++ b/tests/baselines/reference/maxConstraints.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/maxConstraints.ts(5,6): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/compiler/maxConstraints.ts(8,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'Comparable'. + Property 'compareTo' is missing in type 'Number'. ==== tests/cases/compiler/maxConstraints.ts (2 errors) ==== @@ -14,4 +15,5 @@ tests/cases/compiler/maxConstraints.ts(8,22): error TS2345: Argument of type 'nu var max2: Comparer = (x, y) => { return (x.compareTo(y) > 0) ? x : y }; var maxResult = max2(1, 2); ~ -!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'Comparable'. \ No newline at end of file +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'Comparable'. +!!! error TS2345: Property 'compareTo' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesFunctionArgument2.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesFunctionArgument2.errors.txt index 44426a8afb0..00ac59319ec 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesFunctionArgument2.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesFunctionArgument2.errors.txt @@ -1,4 +1,5 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesFunctionArgument2.ts(7,5): error TS2345: Argument of type '{ name: string; id: number; }' is not assignable to parameter of type '{ a: string; id: number; }'. + Property 'a' is missing in type '{ name: string; id: number; }'. ==== tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesFunctionArgument2.ts (1 errors) ==== @@ -11,4 +12,5 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr foo(person); // error ~~~~~~ !!! error TS2345: Argument of type '{ name: string; id: number; }' is not assignable to parameter of type '{ a: string; id: number; }'. +!!! error TS2345: Property 'a' is missing in type '{ name: string; id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalBindingParameters1.errors.txt b/tests/baselines/reference/optionalBindingParameters1.errors.txt index a2961fb9651..78fc1cbddf1 100644 --- a/tests/baselines/reference/optionalBindingParameters1.errors.txt +++ b/tests/baselines/reference/optionalBindingParameters1.errors.txt @@ -1,5 +1,7 @@ tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts(2,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts(8,5): error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. + Types of property '0' are incompatible. + Type 'boolean' is not assignable to type 'string'. ==== tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts (2 errors) ==== @@ -14,4 +16,6 @@ tests/cases/conformance/es6/destructuring/optionalBindingParameters1.ts(8,5): er foo([false, 0, ""]); ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. \ No newline at end of file +!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt b/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt index 5999ec514b0..312603d2c2e 100644 --- a/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt +++ b/tests/baselines/reference/optionalBindingParametersInOverloads1.errors.txt @@ -1,4 +1,6 @@ tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts(9,5): error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. + Types of property '0' are incompatible. + Type 'boolean' is not assignable to type 'string'. ==== tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1.ts (1 errors) ==== @@ -12,4 +14,6 @@ tests/cases/conformance/es6/destructuring/optionalBindingParametersInOverloads1. foo([false, 0, ""]); ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. \ No newline at end of file +!!! error TS2345: Argument of type '[boolean, number, string]' is not assignable to parameter of type '[string, number, boolean]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadResolutionOverCTLambda.errors.txt b/tests/baselines/reference/overloadResolutionOverCTLambda.errors.txt index 03901cf67a4..9fc11b681c7 100644 --- a/tests/baselines/reference/overloadResolutionOverCTLambda.errors.txt +++ b/tests/baselines/reference/overloadResolutionOverCTLambda.errors.txt @@ -1,8 +1,10 @@ tests/cases/compiler/overloadResolutionOverCTLambda.ts(2,5): error TS2345: Argument of type '(a: number) => number' is not assignable to parameter of type '(item: number) => boolean'. + Type 'number' is not assignable to type 'boolean'. ==== tests/cases/compiler/overloadResolutionOverCTLambda.ts (1 errors) ==== function foo(b: (item: number) => boolean) { } foo(a => a); // can not convert (number)=>bool to (number)=>number ~~~~~~ -!!! error TS2345: Argument of type '(a: number) => number' is not assignable to parameter of type '(item: number) => boolean'. \ No newline at end of file +!!! error TS2345: Argument of type '(a: number) => number' is not assignable to parameter of type '(item: number) => boolean'. +!!! error TS2345: Type 'number' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt index 4a119c5ca22..ed504fd410d 100644 --- a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt +++ b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt @@ -1,8 +1,11 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,37): error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'. + Property 'x' is missing in type 'D'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,38): error TS2344: Type 'D' does not satisfy the constraint 'A'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(18,27): error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. + Types of parameters 'x' and 'x' are incompatible. + Type 'D' is not assignable to type 'B'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12): error TS2344: Type 'D' does not satisfy the constraint 'A'. @@ -25,6 +28,7 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12): !!! error TS2322: Type 'string' is not assignable to type 'number'. ~ !!! error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'. +!!! error TS2345: Property 'x' is missing in type 'D'. var result2: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. ~~~~~~~ @@ -43,4 +47,6 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12): }); ~ !!! error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'D' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadsWithProvisionalErrors.errors.txt b/tests/baselines/reference/overloadsWithProvisionalErrors.errors.txt index bd918de55fe..55fe8ed4fde 100644 --- a/tests/baselines/reference/overloadsWithProvisionalErrors.errors.txt +++ b/tests/baselines/reference/overloadsWithProvisionalErrors.errors.txt @@ -1,6 +1,8 @@ tests/cases/compiler/overloadsWithProvisionalErrors.ts(6,6): error TS2345: Argument of type '(s: string) => {}' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'. + Type '{}' is not assignable to type '{ a: number; b: number; }'. tests/cases/compiler/overloadsWithProvisionalErrors.ts(7,17): error TS2304: Cannot find name 'blah'. tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,6): error TS2345: Argument of type '(s: string) => { a: any; }' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'. + Type '{ a: any; }' is not assignable to type '{ a: number; b: number; }'. tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cannot find name 'blah'. @@ -13,11 +15,13 @@ tests/cases/compiler/overloadsWithProvisionalErrors.ts(8,17): error TS2304: Cann func(s => ({})); // Error for no applicable overload (object type is missing a and b) ~~~~~~~~~ !!! error TS2345: Argument of type '(s: string) => {}' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'. +!!! error TS2345: Type '{}' is not assignable to type '{ a: number; b: number; }'. func(s => ({ a: blah, b: 3 })); // Only error inside the function, but not outside (since it would be applicable if not for the provisional error) ~~~~ !!! error TS2304: Cannot find name 'blah'. func(s => ({ a: blah })); // Two errors here, one for blah not being defined, and one for the overload since it would not be applicable anyway ~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(s: string) => { a: any; }' is not assignable to parameter of type '(s: string) => { a: number; b: number; }'. +!!! error TS2345: Type '{ a: any; }' is not assignable to type '{ a: number; b: number; }'. ~~~~ !!! error TS2304: Cannot find name 'blah'. \ No newline at end of file diff --git a/tests/baselines/reference/parser536727.errors.txt b/tests/baselines/reference/parser536727.errors.txt index a25859f78a1..4204e62c93b 100644 --- a/tests/baselines/reference/parser536727.errors.txt +++ b/tests/baselines/reference/parser536727.errors.txt @@ -1,5 +1,7 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(7,5): error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'. + Type '(x: string) => string' is not assignable to type 'string'. tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(8,5): error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'. + Type '(x: string) => string' is not assignable to type 'string'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts (2 errors) ==== @@ -12,7 +14,9 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(8,5): foo(() => g); ~~~~~~~ !!! error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Type '(x: string) => string' is not assignable to type 'string'. foo(x); ~ !!! error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Type '(x: string) => string' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/promiseChaining1.errors.txt b/tests/baselines/reference/promiseChaining1.errors.txt index e0fac7c2893..7396d03059a 100644 --- a/tests/baselines/reference/promiseChaining1.errors.txt +++ b/tests/baselines/reference/promiseChaining1.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/promiseChaining1.ts(7,50): error TS2345: Argument of type '(x: S) => string' is not assignable to parameter of type '(x: S) => Function'. + Type 'string' is not assignable to type 'Function'. ==== tests/cases/compiler/promiseChaining1.ts (1 errors) ==== @@ -11,6 +12,7 @@ tests/cases/compiler/promiseChaining1.ts(7,50): error TS2345: Argument of type ' var z = this.then(x => result)/*S*/.then(x => "abc")/*Function*/.then(x => x.length)/*number*/; // Should error on "abc" because it is not a Function ~~~~~~~~~~ !!! error TS2345: Argument of type '(x: S) => string' is not assignable to parameter of type '(x: S) => Function'. +!!! error TS2345: Type 'string' is not assignable to type 'Function'. return new Chain2(result); } } \ No newline at end of file diff --git a/tests/baselines/reference/promiseChaining2.errors.txt b/tests/baselines/reference/promiseChaining2.errors.txt index c5b3f2fc1f0..a31c4335da7 100644 --- a/tests/baselines/reference/promiseChaining2.errors.txt +++ b/tests/baselines/reference/promiseChaining2.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/promiseChaining2.ts(7,45): error TS2345: Argument of type '(x: S) => string' is not assignable to parameter of type '(x: S) => Function'. + Type 'string' is not assignable to type 'Function'. ==== tests/cases/compiler/promiseChaining2.ts (1 errors) ==== @@ -11,6 +12,7 @@ tests/cases/compiler/promiseChaining2.ts(7,45): error TS2345: Argument of type ' var z = this.then(x => result).then(x => "abc").then(x => x.length); ~~~~~~~~~~ !!! error TS2345: Argument of type '(x: S) => string' is not assignable to parameter of type '(x: S) => Function'. +!!! error TS2345: Type 'string' is not assignable to type 'Function'. return new Chain2(result); } } \ No newline at end of file diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index 9104d924e66..d4082015054 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -1,8 +1,23 @@ -tests/cases/compiler/promisePermutations.ts(74,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +tests/cases/compiler/promisePermutations.ts(55,34): error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. +tests/cases/compiler/promisePermutations.ts(56,34): error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. +tests/cases/compiler/promisePermutations.ts(73,35): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. +tests/cases/compiler/promisePermutations.ts(74,35): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. tests/cases/compiler/promisePermutations.ts(79,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(84,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(88,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(91,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(92,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -12,9 +27,17 @@ tests/cases/compiler/promisePermutations.ts(100,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations.ts(101,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. tests/cases/compiler/promisePermutations.ts(102,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(106,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(109,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(111,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(117,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. @@ -32,15 +55,28 @@ tests/cases/compiler/promisePermutations.ts(137,11): error TS2453: The type argu tests/cases/compiler/promisePermutations.ts(144,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. +tests/cases/compiler/promisePermutations.ts(151,21): error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(value: {}) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. tests/cases/compiler/promisePermutations.ts(152,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. +tests/cases/compiler/promisePermutations.ts(153,36): error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'IPromise' is not assignable to type 'IPromise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'IPromise' is not assignable to type 'IPromise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'Promise' is not assignable to type 'IPromise'. -==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== +==== tests/cases/compiler/promisePermutations.ts (38 errors) ==== interface Promise { then(success?: (value: T) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; then(success?: (value: T) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; @@ -96,7 +132,13 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s1a = s1.then(testFunction, testFunction, testFunction); var s1b = s1.then(testFunctionP, testFunctionP, testFunctionP); var s1c = s1.then(testFunctionP, testFunction, testFunction); + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s1d = s1.then(testFunctionP, testFunction, testFunction).then(testFunction, testFunction, testFunction); + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var r2: IPromise<{ x: number; }>; var r2a = r2.then(testFunction2, testFunction2, testFunction2); @@ -114,9 +156,13 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error - ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -124,17 +170,25 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var r4a = r4.then(testFunction4, testFunction4, testFunction4); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r4b = r4.then(sIPromise, testFunction4, testFunction4).then(sIPromise, testFunction4, testFunction4); // ok var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; @@ -175,17 +229,25 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var r7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var r7b = r7.then(sIPromise, sIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s7: Promise; var s7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7b = r7.then(testFunction7P, testFunction7P, testFunction7P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7c = r7.then(testFunction7P, testFunction7, testFunction7); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7d = r7.then(sPromise, sPromise, sPromise).then(sPromise, sPromise, sPromise); // ok? var r8: IPromise; @@ -254,26 +316,41 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok + ~~~~~~~~~ +!!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(value: {}) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~ !!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok + ~~~~~~~~~ +!!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 3c316115a27..1e2c13edd15 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -1,46 +1,104 @@ -tests/cases/compiler/promisePermutations2.ts(73,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(54,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: number) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. +tests/cases/compiler/promisePermutations2.ts(55,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(63,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: { x: number; }) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. +tests/cases/compiler/promisePermutations2.ts(64,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. +tests/cases/compiler/promisePermutations2.ts(72,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(73,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. tests/cases/compiler/promisePermutations2.ts(78,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(81,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. -tests/cases/compiler/promisePermutations2.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/promisePermutations2.ts(83,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. +tests/cases/compiler/promisePermutations2.ts(84,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'Promise'. + Types of property 'then' are incompatible. + Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. tests/cases/compiler/promisePermutations2.ts(87,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(90,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(91,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. -tests/cases/compiler/promisePermutations2.ts(92,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(92,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. tests/cases/compiler/promisePermutations2.ts(96,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(99,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(100,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. -tests/cases/compiler/promisePermutations2.ts(101,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(101,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. tests/cases/compiler/promisePermutations2.ts(105,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(108,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(109,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. -tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(121,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: any) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(128,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. -tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(133,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. tests/cases/compiler/promisePermutations2.ts(136,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations2.ts(143,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. +tests/cases/compiler/promisePermutations2.ts(148,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise<{}>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{}>'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: {}) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. +tests/cases/compiler/promisePermutations2.ts(150,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. tests/cases/compiler/promisePermutations2.ts(151,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + Types of property 'then' are incompatible. + Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. +tests/cases/compiler/promisePermutations2.ts(152,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'IPromise' is not assignable to type 'IPromise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'IPromise' is not assignable to type 'IPromise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. -tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. -==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== +==== tests/cases/compiler/promisePermutations2.ts (42 errors) ==== // same as promisePermutations but without the same overloads in Promise interface Promise { @@ -95,7 +153,15 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s1a = s1.then(testFunction, testFunction, testFunction); var s1b = s1.then(testFunctionP, testFunctionP, testFunctionP); var s1c = s1.then(testFunctionP, testFunction, testFunction); + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: number) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s1d = s1.then(testFunctionP, testFunction, testFunction).then(testFunction, testFunction, testFunction); + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var r2: IPromise<{ x: number; }>; var r2a = r2.then(testFunction2, testFunction2, testFunction2); @@ -104,7 +170,15 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s2a = s2.then(testFunction2, testFunction2, testFunction2); var s2b = s2.then(testFunction2P, testFunction2P, testFunction2P); var s2c = s2.then(testFunction2P, testFunction2, testFunction2); + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: { x: number; }) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s2d = s2.then(testFunction2P, testFunction2, testFunction2).then(testFunction2, testFunction2, testFunction2); + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. var r3: IPromise; var r3a = r3.then(testFunction3, testFunction3, testFunction3); @@ -113,9 +187,13 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // Should error - ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -123,18 +201,32 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var r4a = r4.then(testFunction4, testFunction4, testFunction4); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r4b = r4.then(sIPromise, testFunction4, testFunction4).then(sIPromise, testFunction4, testFunction4); // ok var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error - ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'Promise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -149,8 +241,9 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. var s5c = s5.then(testFunction5P, testFunction5, testFunction5); // error - ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var s5d = s5.then(sPromise, sPromise, sPromise).then(sIPromise, sIPromise, sIPromise); // ok var r6: IPromise; @@ -166,25 +259,34 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. var s6c = s6.then(testFunction6P, testFunction6, testFunction6); // error - ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var s6d = s6.then(sPromise, sPromise, sPromise).then(sIPromise, sIPromise, sIPromise); // ok var r7: IPromise; var r7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var r7b = r7.then(sIPromise, sIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s7: Promise; var s7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7b = r7.then(testFunction7P, testFunction7P, testFunction7P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7c = r7.then(testFunction7P, testFunction7, testFunction7); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7d = r7.then(sPromise, sPromise, sPromise).then(sPromise, sPromise, sPromise); // ok? var r8: IPromise; @@ -202,8 +304,11 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error - ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: any) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s8d = s8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var r9: IPromise; @@ -226,8 +331,9 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error - ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. + ~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok var s9f = s9.then(testFunction, sIPromise, nIPromise); // error @@ -251,28 +357,47 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok + ~~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise<{}>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{}>'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: {}) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok + ~~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~ !!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok - ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. + ~~~~~~~~ +!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index f8edf83c694..d0874ea7f57 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -1,9 +1,21 @@ tests/cases/compiler/promisePermutations3.ts(68,69): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'IPromise'. tests/cases/compiler/promisePermutations3.ts(73,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'IPromise'. tests/cases/compiler/promisePermutations3.ts(78,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(81,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(87,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(90,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(91,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -13,9 +25,17 @@ tests/cases/compiler/promisePermutations3.ts(99,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations3.ts(100,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. tests/cases/compiler/promisePermutations3.ts(101,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(105,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(108,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(109,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'cb' and 'value' are incompatible. + Type '(a: T) => T' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. @@ -35,11 +55,21 @@ tests/cases/compiler/promisePermutations3.ts(143,12): error TS2453: The type arg Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations3.ts(151,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + Types of property 'then' are incompatible. + Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'IPromise' is not assignable to type 'IPromise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'IPromise' is not assignable to type 'IPromise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. + Type 'Promise' is not assignable to type 'Promise'. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'Promise' is not assignable to type 'IPromise'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. + Type 'IPromise' is not assignable to type 'Promise'. ==== tests/cases/compiler/promisePermutations3.ts (35 errors) ==== @@ -113,6 +143,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r3b = r3.then(testFunction3, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'IPromise'. var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); @@ -120,6 +152,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -127,17 +161,25 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r4a = r4.then(testFunction4, testFunction4, testFunction4); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r4b = r4.then(sIPromise, testFunction4, testFunction4).then(sIPromise, testFunction4, testFunction4); // ok var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; @@ -178,17 +220,25 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var r7b = r7.then(sIPromise, sIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s7: Promise; var s7a = r7.then(testFunction7, testFunction7, testFunction7); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7b = r7.then(testFunction7P, testFunction7P, testFunction7P); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7c = r7.then(testFunction7P, testFunction7, testFunction7); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'cb' and 'value' are incompatible. +!!! error TS2345: Type '(a: T) => T' is not assignable to type 'string'. var s7d = r7.then(sPromise, sPromise, sPromise).then(sPromise, sPromise, sPromise); // ok? var r8: IPromise; @@ -261,22 +311,31 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~ !!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +!!! error TS2453: Types of property 'then' are incompatible. +!!! error TS2453: Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -285,4 +344,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s12b = s12.then(testFunction12P, testFunction12P, testFunction12P); // ok ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file diff --git a/tests/baselines/reference/recursiveClassReferenceTest.errors.txt b/tests/baselines/reference/recursiveClassReferenceTest.errors.txt index f2561724475..088d7222f48 100644 --- a/tests/baselines/reference/recursiveClassReferenceTest.errors.txt +++ b/tests/baselines/reference/recursiveClassReferenceTest.errors.txt @@ -2,6 +2,7 @@ tests/cases/compiler/recursiveClassReferenceTest.ts(16,19): error TS2304: Cannot tests/cases/compiler/recursiveClassReferenceTest.ts(56,11): error TS2304: Cannot find name 'domNode'. tests/cases/compiler/recursiveClassReferenceTest.ts(88,36): error TS2304: Cannot find name 'mode'. tests/cases/compiler/recursiveClassReferenceTest.ts(95,21): error TS2345: Argument of type 'Window' is not assignable to parameter of type 'IMode'. + Property 'getInitialState' is missing in type 'Window'. ==== tests/cases/compiler/recursiveClassReferenceTest.ts (4 errors) ==== @@ -108,6 +109,7 @@ tests/cases/compiler/recursiveClassReferenceTest.ts(95,21): error TS2345: Argume return new State(self); ~~~~ !!! error TS2345: Argument of type 'Window' is not assignable to parameter of type 'IMode'. +!!! error TS2345: Property 'getInitialState' is missing in type 'Window'. } diff --git a/tests/baselines/reference/subtypingWithCallSignaturesA.errors.txt b/tests/baselines/reference/subtypingWithCallSignaturesA.errors.txt index 31f6e5572d3..3821c707f4b 100644 --- a/tests/baselines/reference/subtypingWithCallSignaturesA.errors.txt +++ b/tests/baselines/reference/subtypingWithCallSignaturesA.errors.txt @@ -1,8 +1,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesA.ts(2,15): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => number'. + Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesA.ts (1 errors) ==== declare function foo3(cb: (x: number) => number): typeof cb; var r5 = foo3((x: number) => ''); // error ~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => number'. \ No newline at end of file +!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt index 99e90d57148..275fdac6ac7 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt @@ -26,6 +26,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(64,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. + Property 'z' is missing in type '{ x: number; y: string; }'. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(81,25): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(86,23): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. @@ -164,6 +165,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. ~~~ !!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. var a9e: {}; diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt index 170c10c7381..1a4a1dc5aac 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt @@ -2,6 +2,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts(76,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. + Property 'z' is missing in type '{ x: number; y: string; }'. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts (2 errors) ==== @@ -87,6 +88,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. var a9e: {}; // Generic tag with multiple parameters of generic type passed arguments with a single best common type diff --git a/tests/baselines/reference/typeArgInference2.errors.txt b/tests/baselines/reference/typeArgInference2.errors.txt index 08fc2f4e232..dd2e227f2ff 100644 --- a/tests/baselines/reference/typeArgInference2.errors.txt +++ b/tests/baselines/reference/typeArgInference2.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/typeArgInference2.ts(12,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ name: string; a: number; }' is not a valid type argument because it is not a supertype of candidate '{ name: string; b: number; }'. + Property 'a' is missing in type '{ name: string; b: number; }'. ==== tests/cases/compiler/typeArgInference2.ts (1 errors) ==== @@ -17,4 +18,5 @@ tests/cases/compiler/typeArgInference2.ts(12,10): error TS2453: The type argumen var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate '{ name: string; a: number; }' is not a valid type argument because it is not a supertype of candidate '{ name: string; b: number; }'. \ No newline at end of file +!!! error TS2453: Type argument candidate '{ name: string; a: number; }' is not a valid type argument because it is not a supertype of candidate '{ name: string; b: number; }'. +!!! error TS2453: Property 'a' is missing in type '{ name: string; b: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt b/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt index 1131b6e1a68..d7cf5e83b8f 100644 --- a/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt +++ b/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/typeArgumentConstraintResolution1.ts(4,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. + Property 'toDateString' is missing in type 'String'. tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. @@ -9,6 +10,7 @@ tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,12): error TS2345: foo1(""); // should error ~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. +!!! error TS2345: Property 'toDateString' is missing in type 'String'. diff --git a/tests/baselines/reference/typeArgumentInference.errors.txt b/tests/baselines/reference/typeArgumentInference.errors.txt index e374de7b13a..126fe3d772f 100644 --- a/tests/baselines/reference/typeArgumentInference.errors.txt +++ b/tests/baselines/reference/typeArgumentInference.errors.txt @@ -2,6 +2,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(68,11 Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. + Property 'z' is missing in type '{ x: number; y: string; }'. ==== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts (2 errors) ==== @@ -93,6 +94,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11 ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. var a9e: {}; var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); var a9f: A92; diff --git a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt index c251f860adb..c82dab89e94 100644 --- a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt @@ -1,13 +1,20 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(25,35): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(51,19): error TS2304: Cannot find name 'Window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(61,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(71,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(81,45): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. + Types of parameters 'n' and 'b' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(106,15): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(118,9): error TS2304: Cannot find name 'Window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,15): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. + Property 'z' is missing in type '{ x: number; y: string; }'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,51): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(122,56): error TS2304: Cannot find name 'window'. @@ -80,6 +87,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct new someGenerics4('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. new someGenerics4(null, null); // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type @@ -92,6 +101,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct new someGenerics5('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. new someGenerics5(null, null); // Generic call with multiple arguments of function types that each have parameters of the same generic type @@ -104,6 +115,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct new someGenerics6((n: number) => n, (n: string) => n, (n: number) => n); // Error ~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. +!!! error TS2345: Types of parameters 'n' and 'b' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. new someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); // Generic call with multiple arguments of function types that each have parameters of different generic type @@ -151,6 +164,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeArgumentInferenceErrors.errors.txt b/tests/baselines/reference/typeArgumentInferenceErrors.errors.txt index bb08cac4e0b..9bd25dda4e6 100644 --- a/tests/baselines/reference/typeArgumentInferenceErrors.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceErrors.errors.txt @@ -1,7 +1,13 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceErrors.ts(3,31): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceErrors.ts(7,35): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceErrors.ts(11,35): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceErrors.ts(15,41): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. + Types of parameters 'n' and 'b' are incompatible. + Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceErrors.ts (4 errors) ==== @@ -16,16 +22,22 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceErrors.ts someGenerics4('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type function someGenerics5(n: T, f: (x: U) => void) { } someGenerics5('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. // Generic call with multiple arguments of function types that each have parameters of the same generic type function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6((n: number) => n, (n: string) => n, (n: number) => n); // Error ~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. +!!! error TS2345: Types of parameters 'n' and 'b' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt index 72db7214c45..3d24175c757 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts(7,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Giraffe' is not a valid type argument because it is not a supertype of candidate 'Elephant'. + Property 'y' is missing in type 'Elephant'. ==== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts (1 errors) ==== @@ -12,4 +13,5 @@ tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts(7,1): er f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal ~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Giraffe' is not a valid type argument because it is not a supertype of candidate 'Elephant'. \ No newline at end of file +!!! error TS2453: Type argument candidate 'Giraffe' is not a valid type argument because it is not a supertype of candidate 'Elephant'. +!!! error TS2453: Property 'y' is missing in type 'Elephant'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt index a607bc2dc9d..56370ac03d5 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt @@ -4,15 +4,22 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(32,34): error TS2304: Cannot find name 'Window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(34,15): error TS2304: Cannot find name 'Window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(41,35): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(48,35): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(49,15): error TS2344: Type 'string' does not satisfy the constraint 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(55,41): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. + Types of parameters 'n' and 'b' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(66,31): error TS2345: Argument of type '(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(73,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(85,9): error TS2304: Cannot find name 'Window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. + Property 'z' is missing in type '{ x: number; y: string; }'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,47): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(89,52): error TS2304: Cannot find name 'window'. @@ -71,6 +78,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst someGenerics4('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. someGenerics4(null, null); // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type @@ -80,6 +89,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst someGenerics5('', (x: string) => ''); // Error ~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. someGenerics5(null, null); // Error ~~~~~~ !!! error TS2344: Type 'string' does not satisfy the constraint 'number'. @@ -91,6 +102,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst someGenerics6((n: number) => n, (n: string) => n, (n: number) => n); // Error ~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. +!!! error TS2345: Types of parameters 'n' and 'b' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); // Generic call with multiple arguments of function types that each have parameters of different generic type @@ -133,6 +146,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. +!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index ab5eb19ce2a..a2ad28801c8 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -4,7 +4,9 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): err tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other. Property 'x' is missing in type 'SomeOther'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2352: Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other. + Property 'q' is missing in type 'SomeDerived'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other. + Property 'q' is missing in type 'SomeBase'. ==== tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts (5 errors) ==== @@ -55,9 +57,11 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): err someOther = someDerived; // Error ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other. +!!! error TS2352: Property 'q' is missing in type 'SomeDerived'. someOther = someBase; // Error ~~~~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other. +!!! error TS2352: Property 'q' is missing in type 'SomeBase'. someOther = someOther; diff --git a/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt b/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt index 99264a00351..0e291769afe 100644 --- a/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt +++ b/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt @@ -1,6 +1,7 @@ tests/cases/compiler/typeIdentityConsidersBrands.ts(30,1): error TS2322: Type 'X_1' is not assignable to type 'Y_1'. Types have separate declarations of a private property 'name'. tests/cases/compiler/typeIdentityConsidersBrands.ts(31,6): error TS2345: Argument of type 'Y_1' is not assignable to parameter of type 'X_1'. + Types have separate declarations of a private property 'name'. ==== tests/cases/compiler/typeIdentityConsidersBrands.ts (2 errors) ==== @@ -40,4 +41,5 @@ tests/cases/compiler/typeIdentityConsidersBrands.ts(31,6): error TS2345: Argumen foo2(a2); // should error ~~ !!! error TS2345: Argument of type 'Y_1' is not assignable to parameter of type 'X_1'. +!!! error TS2345: Types have separate declarations of a private property 'name'. \ No newline at end of file diff --git a/tests/baselines/reference/typeOfOnTypeArg.errors.txt b/tests/baselines/reference/typeOfOnTypeArg.errors.txt index 46b48983f21..8562b7f134a 100644 --- a/tests/baselines/reference/typeOfOnTypeArg.errors.txt +++ b/tests/baselines/reference/typeOfOnTypeArg.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/typeOfOnTypeArg.ts(7,6): error TS2345: Argument of type 'number' is not assignable to parameter of type '{ '': number; }'. + Property '''' is missing in type 'Number'. ==== tests/cases/compiler/typeOfOnTypeArg.ts (1 errors) ==== @@ -11,4 +12,5 @@ tests/cases/compiler/typeOfOnTypeArg.ts(7,6): error TS2345: Argument of type 'nu fill(32); ~~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type '{ '': number; }'. +!!! error TS2345: Property '''' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/undeclaredModuleError.errors.txt b/tests/baselines/reference/undeclaredModuleError.errors.txt index 9ce6cbfd89f..62faef02eea 100644 --- a/tests/baselines/reference/undeclaredModuleError.errors.txt +++ b/tests/baselines/reference/undeclaredModuleError.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/undeclaredModuleError.ts(1,21): error TS2307: Cannot find external module 'fs'. tests/cases/compiler/undeclaredModuleError.ts(8,29): error TS2345: Argument of type '() => void' is not assignable to parameter of type '(stat: any, name: string) => boolean'. + Type 'void' is not assignable to type 'boolean'. tests/cases/compiler/undeclaredModuleError.ts(11,41): error TS2304: Cannot find name 'IDoNotExist'. @@ -18,6 +19,7 @@ tests/cases/compiler/undeclaredModuleError.ts(11,41): error TS2304: Cannot find } , (error: Error, files: {}[]) => { ~~~~~~~~~ !!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '(stat: any, name: string) => boolean'. +!!! error TS2345: Type 'void' is not assignable to type 'boolean'. files.forEach((file) => { var fullPath = join(IDoNotExist); ~~~~~~~~~~~ diff --git a/tests/cases/compiler/elaboratedErrors.ts b/tests/cases/compiler/elaboratedErrors.ts new file mode 100644 index 00000000000..e985a9362f3 --- /dev/null +++ b/tests/cases/compiler/elaboratedErrors.ts @@ -0,0 +1,25 @@ +interface FileSystem { + read: number; +} + +function fn(s: WorkerFS): void; +function fn(s: FileSystem): void; +function fn(s: FileSystem|WorkerFS) { } + +// This should issue a large error, not a small one +class WorkerFS implements FileSystem { + read: string; +} + +interface Alpha { x: string; } +interface Beta { y: number; } +var x: Alpha; +var y: Beta; + +// Only one of these errors should be large +x = y; +x = y; + +// Only one of these errors should be large +y = x; +y = x; From 85219ee5e1acc9c855c6377357bc70b5bb03f8f8 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 20 Jan 2015 17:07:00 -0800 Subject: [PATCH 26/71] Check computed properties against indexers in classes --- src/compiler/checker.ts | 45 +++++++++++---- .../computedPropertyNames36.errors.txt | 16 ++++++ .../reference/computedPropertyNames36.js | 42 ++++++++++++++ .../reference/computedPropertyNames37.js | 42 ++++++++++++++ .../reference/computedPropertyNames37.types | 26 +++++++++ .../computedPropertyNames38.errors.txt | 16 ++++++ .../reference/computedPropertyNames38.js | 42 ++++++++++++++ .../computedPropertyNames39.errors.txt | 16 ++++++ .../reference/computedPropertyNames39.js | 42 ++++++++++++++ .../computedPropertyNames40.errors.txt | 16 ++++++ .../reference/computedPropertyNames40.js | 35 ++++++++++++ .../reference/computedPropertyNames41.js | 31 ++++++++++ .../reference/computedPropertyNames41.types | 22 +++++++ .../computedPropertyNames42.errors.txt | 18 ++++++ .../computedPropertyNames43.errors.txt | 18 ++++++ .../reference/computedPropertyNames43.js | 57 +++++++++++++++++++ .../computedPropertyNames44.errors.txt | 20 +++++++ .../reference/computedPropertyNames44.js | 55 ++++++++++++++++++ .../computedPropertyNames45.errors.txt | 18 ++++++ .../reference/computedPropertyNames45.js | 56 ++++++++++++++++++ .../computedPropertyNames36.ts | 11 ++++ .../computedPropertyNames37.ts | 11 ++++ .../computedPropertyNames38.ts | 11 ++++ .../computedPropertyNames39.ts | 11 ++++ .../computedPropertyNames40.ts | 11 ++++ .../computedPropertyNames41.ts | 10 ++++ .../computedPropertyNames42.ts | 10 ++++ .../computedPropertyNames43.ts | 13 +++++ .../computedPropertyNames44.ts | 12 ++++ .../computedPropertyNames45.ts | 13 +++++ 30 files changed, 734 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNames36.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames36.js create mode 100644 tests/baselines/reference/computedPropertyNames37.js create mode 100644 tests/baselines/reference/computedPropertyNames37.types create mode 100644 tests/baselines/reference/computedPropertyNames38.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames38.js create mode 100644 tests/baselines/reference/computedPropertyNames39.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames39.js create mode 100644 tests/baselines/reference/computedPropertyNames40.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames40.js create mode 100644 tests/baselines/reference/computedPropertyNames41.js create mode 100644 tests/baselines/reference/computedPropertyNames41.types create mode 100644 tests/baselines/reference/computedPropertyNames42.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames43.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames43.js create mode 100644 tests/baselines/reference/computedPropertyNames44.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames44.js create mode 100644 tests/baselines/reference/computedPropertyNames45.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames45.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames37.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames38.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames39.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames40.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames41.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames43.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames45.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 42612ed4cdc..35b2fb244e5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4767,6 +4767,7 @@ module ts { return type; } } + /*Transitively mark all linked imports as referenced*/ function markLinkedImportsAsReferenced(node: ImportDeclaration): void { var nodeLinks = getNodeLinks(node); @@ -8466,41 +8467,46 @@ module ts { if (node.finallyBlock) checkBlock(node.finallyBlock); } - function checkIndexConstraints(type: Type) { + function checkIndexConstraints(type: Type) { + function checkIndexConstraintForProperty( + prop: Symbol, + propertyType: Type, + containingType: Type, + indexDeclaration: Declaration, + indexType: Type, + indexKind: IndexKind): void { - function checkIndexConstraintForProperty(prop: Symbol, propertyType: Type, indexDeclaration: Declaration, indexType: Type, indexKind: IndexKind): void { if (!indexType) { return; } // index is numeric and property name is not valid numeric literal - if (indexKind === IndexKind.Number && !isNumericLiteralName(prop.name)) { + if (indexKind === IndexKind.Number && !isNumericName(prop.valueDeclaration.name)) { return; } // perform property check if property or indexer is declared in 'type' // this allows to rule out cases when both property and indexer are inherited from the base class var errorNode: Node; - if (prop.parent === type.symbol) { + if (prop.valueDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { errorNode = indexDeclaration; } - - else if (type.flags & TypeFlags.Interface) { + else if (containingType.flags & TypeFlags.Interface) { // for interfaces property and indexer might be inherited from different bases // check if any base class already has both property and indexer. // check should be performed only if 'type' is the first type that brings property\indexer together - var someBaseClassHasBothPropertyAndIndexer = forEach((type).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind)); - errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; + var someBaseClassHasBothPropertyAndIndexer = forEach((containingType).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind)); + errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { var errorMessage = indexKind === IndexKind.String - ? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 - : Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; + ? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 + : Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); } } @@ -8514,9 +8520,24 @@ module ts { if (stringIndexType || numberIndexType) { forEach(getPropertiesOfObjectType(type), prop => { var propType = getTypeOfSymbol(prop); - checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, IndexKind.String); - checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, IndexKind.Number); + checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String); + checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number); }); + + if (type.flags & TypeFlags.Class && type.symbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration) { + var classDeclaration = type.symbol.valueDeclaration; + for (var i = 0; i < classDeclaration.members.length; i++) { + var member = classDeclaration.members[i]; + // Only process instance properties with computed names here. + // Static properties cannot be in conflict with indexers, + // and properties with literal names were already checked. + if (!(member.flags & NodeFlags.Static) && hasComputedNameButNotSymbol(member)) { + var propType = getTypeOfSymbol(member.symbol); + checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String); + checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number); + } + } + } } var errorNode: Node; diff --git a/tests/baselines/reference/computedPropertyNames36.errors.txt b/tests/baselines/reference/computedPropertyNames36.errors.txt new file mode 100644 index 00000000000..a473ebfba8e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames36.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts(8,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts (1 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: string]: Foo2; + + // Computed properties + get ["get1"]() { return new Foo } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + set ["set1"](p: Foo2) { } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames36.js b/tests/baselines/reference/computedPropertyNames36.js new file mode 100644 index 00000000000..7c731014d1e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames36.js @@ -0,0 +1,42 @@ +//// [computedPropertyNames36.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + + // Computed properties + get ["get1"]() { return new Foo } + set ["set1"](p: Foo2) { } +} + +//// [computedPropertyNames36.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "get1", { + // Computed properties + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "set1", { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames37.js b/tests/baselines/reference/computedPropertyNames37.js new file mode 100644 index 00000000000..fb4c32909d5 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames37.js @@ -0,0 +1,42 @@ +//// [computedPropertyNames37.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: number]: Foo2; + + // Computed properties + get ["get1"]() { return new Foo } + set ["set1"](p: Foo2) { } +} + +//// [computedPropertyNames37.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "get1", { + // Computed properties + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "set1", { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames37.types b/tests/baselines/reference/computedPropertyNames37.types new file mode 100644 index 00000000000..b50e0590b79 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames37.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames37.ts === +class Foo { x } +>Foo : Foo +>x : any + +class Foo2 { x; y } +>Foo2 : Foo2 +>x : any +>y : any + +class C { +>C : C + + [s: number]: Foo2; +>s : number +>Foo2 : Foo2 + + // Computed properties + get ["get1"]() { return new Foo } +>new Foo : Foo +>Foo : typeof Foo + + set ["set1"](p: Foo2) { } +>p : Foo2 +>Foo2 : Foo2 +} diff --git a/tests/baselines/reference/computedPropertyNames38.errors.txt b/tests/baselines/reference/computedPropertyNames38.errors.txt new file mode 100644 index 00000000000..fc5f31f1329 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames38.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames38.ts(8,5): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to string index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames38.ts (1 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: string]: Foo2; + + // Computed properties + get [1 << 6]() { return new Foo } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to string index type 'Foo2'. + set [1 << 6](p: Foo2) { } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames38.js b/tests/baselines/reference/computedPropertyNames38.js new file mode 100644 index 00000000000..922244bfecf --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames38.js @@ -0,0 +1,42 @@ +//// [computedPropertyNames38.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + + // Computed properties + get [1 << 6]() { return new Foo } + set [1 << 6](p: Foo2) { } +} + +//// [computedPropertyNames38.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, 1 << 6, { + // Computed properties + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, 1 << 6, { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames39.errors.txt b/tests/baselines/reference/computedPropertyNames39.errors.txt new file mode 100644 index 00000000000..573ef726241 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames39.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames39.ts(8,5): error TS2412: Property '[1 << 6]' of type 'Foo' is not assignable to numeric index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames39.ts (1 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: number]: Foo2; + + // Computed properties + get [1 << 6]() { return new Foo } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '[1 << 6]' of type 'Foo' is not assignable to numeric index type 'Foo2'. + set [1 << 6](p: Foo2) { } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames39.js b/tests/baselines/reference/computedPropertyNames39.js new file mode 100644 index 00000000000..62621f4e754 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames39.js @@ -0,0 +1,42 @@ +//// [computedPropertyNames39.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: number]: Foo2; + + // Computed properties + get [1 << 6]() { return new Foo } + set [1 << 6](p: Foo2) { } +} + +//// [computedPropertyNames39.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, 1 << 6, { + // Computed properties + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, 1 << 6, { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames40.errors.txt b/tests/baselines/reference/computedPropertyNames40.errors.txt new file mode 100644 index 00000000000..c5bda4ed999 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames40.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames40.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames40.ts (1 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: string]: () => Foo2; + + // Computed properties + [""]() { return new Foo } + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'. + [""]() { return new Foo2 } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames40.js b/tests/baselines/reference/computedPropertyNames40.js new file mode 100644 index 00000000000..1c9b5d3bfa8 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames40.js @@ -0,0 +1,35 @@ +//// [computedPropertyNames40.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: () => Foo2; + + // Computed properties + [""]() { return new Foo } + [""]() { return new Foo2 } +} + +//// [computedPropertyNames40.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + // Computed properties + C.prototype[""] = function () { + return new Foo; + }; + C.prototype[""] = function () { + return new Foo2; + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames41.js b/tests/baselines/reference/computedPropertyNames41.js new file mode 100644 index 00000000000..34fe2d33df7 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames41.js @@ -0,0 +1,31 @@ +//// [computedPropertyNames41.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: () => Foo2; + + // Computed properties + static [""]() { return new Foo } +} + +//// [computedPropertyNames41.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + // Computed properties + C[""] = function () { + return new Foo; + }; + return C; +})(); diff --git a/tests/baselines/reference/computedPropertyNames41.types b/tests/baselines/reference/computedPropertyNames41.types new file mode 100644 index 00000000000..1fb0af282ca --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames41.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames41.ts === +class Foo { x } +>Foo : Foo +>x : any + +class Foo2 { x; y } +>Foo2 : Foo2 +>x : any +>y : any + +class C { +>C : C + + [s: string]: () => Foo2; +>s : string +>Foo2 : Foo2 + + // Computed properties + static [""]() { return new Foo } +>new Foo : Foo +>Foo : typeof Foo +} diff --git a/tests/baselines/reference/computedPropertyNames42.errors.txt b/tests/baselines/reference/computedPropertyNames42.errors.txt new file mode 100644 index 00000000000..059b3117a43 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames42.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts(8,5): error TS1166: Computed property names are not allowed in class property declarations. +tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts (2 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: string]: Foo2; + + // Computed properties + [""]: Foo; + ~~~~ +!!! error TS1166: Computed property names are not allowed in class property declarations. + ~~~~~~~~~~ +!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames43.errors.txt b/tests/baselines/reference/computedPropertyNames43.errors.txt new file mode 100644 index 00000000000..d38dcca9216 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames43.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames43.ts(10,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames43.ts (1 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: string]: Foo2; + } + + class D extends C { + // Computed properties + get ["get1"]() { return new Foo } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + set ["set1"](p: Foo2) { } + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames43.js b/tests/baselines/reference/computedPropertyNames43.js new file mode 100644 index 00000000000..22ac7774439 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames43.js @@ -0,0 +1,57 @@ +//// [computedPropertyNames43.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; +} + +class D extends C { + // Computed properties + get ["get1"]() { return new Foo } + set ["set1"](p: Foo2) { } +} + +//// [computedPropertyNames43.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + return C; +})(); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.apply(this, arguments); + } + Object.defineProperty(D.prototype, "get1", { + // Computed properties + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(D.prototype, "set1", { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return D; +})(C); diff --git a/tests/baselines/reference/computedPropertyNames44.errors.txt b/tests/baselines/reference/computedPropertyNames44.errors.txt new file mode 100644 index 00000000000..bf1de6687e1 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames44.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts(6,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts(10,5): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts (2 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + [s: string]: Foo2; + get ["get1"]() { return new Foo } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + } + + class D extends C { + set ["set1"](p: Foo) { } + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames44.js b/tests/baselines/reference/computedPropertyNames44.js new file mode 100644 index 00000000000..c91a52e8199 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames44.js @@ -0,0 +1,55 @@ +//// [computedPropertyNames44.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + get ["get1"]() { return new Foo } +} + +class D extends C { + set ["set1"](p: Foo) { } +} + +//// [computedPropertyNames44.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "get1", { + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.apply(this, arguments); + } + Object.defineProperty(D.prototype, "set1", { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return D; +})(C); diff --git a/tests/baselines/reference/computedPropertyNames45.errors.txt b/tests/baselines/reference/computedPropertyNames45.errors.txt new file mode 100644 index 00000000000..7ad29340b25 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames45.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNames45.ts(11,5): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45.ts (1 errors) ==== + class Foo { x } + class Foo2 { x; y } + + class C { + get ["get1"]() { return new Foo } + } + + class D extends C { + // No error when the indexer is in a class more derived than the computed property + [s: string]: Foo2; + set ["set1"](p: Foo) { } + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames45.js b/tests/baselines/reference/computedPropertyNames45.js new file mode 100644 index 00000000000..7ec3c165e12 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames45.js @@ -0,0 +1,56 @@ +//// [computedPropertyNames45.ts] +class Foo { x } +class Foo2 { x; y } + +class C { + get ["get1"]() { return new Foo } +} + +class D extends C { + // No error when the indexer is in a class more derived than the computed property + [s: string]: Foo2; + set ["set1"](p: Foo) { } +} + +//// [computedPropertyNames45.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Foo2 = (function () { + function Foo2() { + } + return Foo2; +})(); +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "get1", { + get: function () { + return new Foo; + }, + enumerable: true, + configurable: true + }); + return C; +})(); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.apply(this, arguments); + } + Object.defineProperty(D.prototype, "set1", { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + return D; +})(C); diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts new file mode 100644 index 00000000000..36c4e91be48 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + + // Computed properties + get ["get1"]() { return new Foo } + set ["set1"](p: Foo2) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames37.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames37.ts new file mode 100644 index 00000000000..09fe6235a1c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames37.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: number]: Foo2; + + // Computed properties + get ["get1"]() { return new Foo } + set ["set1"](p: Foo2) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames38.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames38.ts new file mode 100644 index 00000000000..9054979dbd8 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames38.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + + // Computed properties + get [1 << 6]() { return new Foo } + set [1 << 6](p: Foo2) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames39.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames39.ts new file mode 100644 index 00000000000..f8d4d2a0107 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames39.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: number]: Foo2; + + // Computed properties + get [1 << 6]() { return new Foo } + set [1 << 6](p: Foo2) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames40.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames40.ts new file mode 100644 index 00000000000..94d473193d9 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames40.ts @@ -0,0 +1,11 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: () => Foo2; + + // Computed properties + [""]() { return new Foo } + [""]() { return new Foo2 } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames41.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames41.ts new file mode 100644 index 00000000000..a376debec56 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames41.ts @@ -0,0 +1,10 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: () => Foo2; + + // Computed properties + static [""]() { return new Foo } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts new file mode 100644 index 00000000000..ded6cb28ce7 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames42.ts @@ -0,0 +1,10 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + + // Computed properties + [""]: Foo; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames43.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames43.ts new file mode 100644 index 00000000000..25028273997 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames43.ts @@ -0,0 +1,13 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; +} + +class D extends C { + // Computed properties + get ["get1"]() { return new Foo } + set ["set1"](p: Foo2) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts new file mode 100644 index 00000000000..04c4ad5ed5c --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames44.ts @@ -0,0 +1,12 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + [s: string]: Foo2; + get ["get1"]() { return new Foo } +} + +class D extends C { + set ["set1"](p: Foo) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames45.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames45.ts new file mode 100644 index 00000000000..e6e058f24ab --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames45.ts @@ -0,0 +1,13 @@ +// @target: es6 +class Foo { x } +class Foo2 { x; y } + +class C { + get ["get1"]() { return new Foo } +} + +class D extends C { + // No error when the indexer is in a class more derived than the computed property + [s: string]: Foo2; + set ["set1"](p: Foo) { } +} \ No newline at end of file From 26da3782b55c442eeecc6c69759b73248d410d0e Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 20 Jan 2015 17:08:55 -0800 Subject: [PATCH 27/71] Move subroutine function to the bottom of checkIndexConstraints --- src/compiler/checker.ts | 86 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 35b2fb244e5..1500d82db8b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8468,49 +8468,6 @@ module ts { } function checkIndexConstraints(type: Type) { - function checkIndexConstraintForProperty( - prop: Symbol, - propertyType: Type, - containingType: Type, - indexDeclaration: Declaration, - indexType: Type, - indexKind: IndexKind): void { - - if (!indexType) { - return; - } - - // index is numeric and property name is not valid numeric literal - if (indexKind === IndexKind.Number && !isNumericName(prop.valueDeclaration.name)) { - return; - } - - // perform property check if property or indexer is declared in 'type' - // this allows to rule out cases when both property and indexer are inherited from the base class - var errorNode: Node; - if (prop.valueDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol) { - errorNode = prop.valueDeclaration; - } - else if (indexDeclaration) { - errorNode = indexDeclaration; - } - else if (containingType.flags & TypeFlags.Interface) { - // for interfaces property and indexer might be inherited from different bases - // check if any base class already has both property and indexer. - // check should be performed only if 'type' is the first type that brings property\indexer together - var someBaseClassHasBothPropertyAndIndexer = forEach((containingType).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind)); - errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; - } - - if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - var errorMessage = - indexKind === IndexKind.String - ? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 - : Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; - error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); - } - } - var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.Number); var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.String); @@ -8554,6 +8511,49 @@ module ts { error(errorNode, Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType)); } + + function checkIndexConstraintForProperty( + prop: Symbol, + propertyType: Type, + containingType: Type, + indexDeclaration: Declaration, + indexType: Type, + indexKind: IndexKind): void { + + if (!indexType) { + return; + } + + // index is numeric and property name is not valid numeric literal + if (indexKind === IndexKind.Number && !isNumericName(prop.valueDeclaration.name)) { + return; + } + + // perform property check if property or indexer is declared in 'type' + // this allows to rule out cases when both property and indexer are inherited from the base class + var errorNode: Node; + if (prop.valueDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol) { + errorNode = prop.valueDeclaration; + } + else if (indexDeclaration) { + errorNode = indexDeclaration; + } + else if (containingType.flags & TypeFlags.Interface) { + // for interfaces property and indexer might be inherited from different bases + // check if any base class already has both property and indexer. + // check should be performed only if 'type' is the first type that brings property\indexer together + var someBaseClassHasBothPropertyAndIndexer = forEach((containingType).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind)); + errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; + } + + if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { + var errorMessage = + indexKind === IndexKind.String + ? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 + : Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; + error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); + } + } } function checkTypeNameIsReserved(name: DeclarationName, message: DiagnosticMessage): void { From eb7798fbb2989795abd33b4c9843c9b9b0f1b95c Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Tue, 20 Jan 2015 18:29:04 -0800 Subject: [PATCH 28/71] Skip computed properties on declaration emit --- src/compiler/emitter.ts | 16 ++++++++- .../computedPropertyNamesDeclarationEmit1.js | 33 +++++++++++++++++++ ...omputedPropertyNamesDeclarationEmit1.types | 14 ++++++++ .../computedPropertyNamesDeclarationEmit2.js | 33 +++++++++++++++++++ ...omputedPropertyNamesDeclarationEmit2.types | 14 ++++++++ ...edPropertyNamesDeclarationEmit3.errors.txt | 9 +++++ ...edPropertyNamesDeclarationEmit4.errors.txt | 9 +++++ .../computedPropertyNamesDeclarationEmit5.js | 23 +++++++++++++ ...omputedPropertyNamesDeclarationEmit5.types | 18 ++++++++++ .../computedPropertyNamesDeclarationEmit1.ts | 7 ++++ .../computedPropertyNamesDeclarationEmit2.ts | 7 ++++ .../computedPropertyNamesDeclarationEmit3.ts | 5 +++ .../computedPropertyNamesDeclarationEmit4.ts | 5 +++ .../computedPropertyNamesDeclarationEmit5.ts | 8 +++++ 14 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit1.js create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit1.types create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit2.js create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit2.types create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit3.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit4.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit5.js create mode 100644 tests/baselines/reference/computedPropertyNamesDeclarationEmit5.types create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit1.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit2.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit3.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit4.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d82e577971d..7c457126f19 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -930,6 +930,10 @@ module ts { } function emitPropertyDeclaration(node: Declaration) { + if (hasComputedNameButNotSymbol(node)) { + return; + } + emitJsDocComments(node); emitClassMemberDeclarationFlags(node); emitVariableDeclaration(node); @@ -937,11 +941,13 @@ module ts { writeLine(); } - // TODO(jfreeman): Factor out common part of property definition, but treat name differently function emitVariableDeclaration(node: VariableDeclaration) { // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted // so there is no check needed to see if declaration is visible if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. writeTextOfNode(currentSourceFile, node.name); // If optional property emit ? if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { @@ -1028,6 +1034,10 @@ module ts { } function emitAccessorDeclaration(node: AccessorDeclaration) { + if (hasComputedNameButNotSymbol(node)) { + return; + } + var accessors = getAllAccessorDeclarations(node.parent, node); if (node === accessors.firstAccessor) { emitJsDocComments(accessors.getAccessor); @@ -1105,6 +1115,10 @@ module ts { } function emitFunctionDeclaration(node: FunctionLikeDeclaration) { + if (hasComputedNameButNotSymbol(node)) { + return; + } + // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting // so no need to verify if the declaration is visible if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) && diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1.js new file mode 100644 index 00000000000..bc8b5d0e910 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1.js @@ -0,0 +1,33 @@ +//// [computedPropertyNamesDeclarationEmit1.ts] +class C { + ["" + ""]() { } + get ["" + ""]() { return 0; } + set ["" + ""](x) { } +} + +//// [computedPropertyNamesDeclarationEmit1.js] +var C = (function () { + function C() { + } + C.prototype["" + ""] = function () { + }; + Object.defineProperty(C.prototype, "" + "", { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "" + "", { + set: function (x) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); + + +//// [computedPropertyNamesDeclarationEmit1.d.ts] +declare class C { +} diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1.types b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1.types new file mode 100644 index 00000000000..e8e184a652e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit1.ts === +class C { +>C : C + + ["" + ""]() { } +>"" + "" : string + + get ["" + ""]() { return 0; } +>"" + "" : string + + set ["" + ""](x) { } +>"" + "" : string +>x : any +} diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2.js new file mode 100644 index 00000000000..647f3fab135 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2.js @@ -0,0 +1,33 @@ +//// [computedPropertyNamesDeclarationEmit2.ts] +class C { + static ["" + ""]() { } + static get ["" + ""]() { return 0; } + static set ["" + ""](x) { } +} + +//// [computedPropertyNamesDeclarationEmit2.js] +var C = (function () { + function C() { + } + C["" + ""] = function () { + }; + Object.defineProperty(C, "" + "", { + get: function () { + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "" + "", { + set: function (x) { + }, + enumerable: true, + configurable: true + }); + return C; +})(); + + +//// [computedPropertyNamesDeclarationEmit2.d.ts] +declare class C { +} diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2.types b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2.types new file mode 100644 index 00000000000..df1da17abea --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit2.ts === +class C { +>C : C + + static ["" + ""]() { } +>"" + "" : string + + static get ["" + ""]() { return 0; } +>"" + "" : string + + static set ["" + ""](x) { } +>"" + "" : string +>x : any +} diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.errors.txt b/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.errors.txt new file mode 100644 index 00000000000..69ff2b9e452 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit3.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit3.ts(2,5): error TS1169: Computed property names are not allowed in interfaces. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit3.ts (1 errors) ==== + interface I { + ["" + ""](): void; + ~~~~~~~~~ +!!! error TS1169: Computed property names are not allowed in interfaces. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.errors.txt b/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.errors.txt new file mode 100644 index 00000000000..53eb057f8a1 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit4.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit4.ts(2,5): error TS1170: Computed property names are not allowed in type literals. + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit4.ts (1 errors) ==== + var v: { + ["" + ""](): void; + ~~~~~~~~~ +!!! error TS1170: Computed property names are not allowed in type literals. + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5.js new file mode 100644 index 00000000000..d7ac3319eca --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5.js @@ -0,0 +1,23 @@ +//// [computedPropertyNamesDeclarationEmit5.ts] +var v = { + ["" + ""]: 0, + ["" + ""]() { }, + get ["" + ""]() { return 0; }, + set ["" + ""](x) { } +} + +//// [computedPropertyNamesDeclarationEmit5.js] +var v = { + ["" + ""]: 0, + ["" + ""]() { + }, + get ["" + ""]() { + return 0; + }, + set ["" + ""](x) { + } +}; + + +//// [computedPropertyNamesDeclarationEmit5.d.ts] +declare var v: {}; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5.types b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5.types new file mode 100644 index 00000000000..c63d6d0d5c3 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5.ts === +var v = { +>v : {} +>{ ["" + ""]: 0, ["" + ""]() { }, get ["" + ""]() { return 0; }, set ["" + ""](x) { }} : {} + + ["" + ""]: 0, +>"" + "" : string + + ["" + ""]() { }, +>"" + "" : string + + get ["" + ""]() { return 0; }, +>"" + "" : string + + set ["" + ""](x) { } +>"" + "" : string +>x : any +} diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit1.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit1.ts new file mode 100644 index 00000000000..100c68653c3 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit1.ts @@ -0,0 +1,7 @@ +// @target: es6 +// @declaration: true +class C { + ["" + ""]() { } + get ["" + ""]() { return 0; } + set ["" + ""](x) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit2.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit2.ts new file mode 100644 index 00000000000..2f353b854cd --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit2.ts @@ -0,0 +1,7 @@ +// @target: es6 +// @declaration: true +class C { + static ["" + ""]() { } + static get ["" + ""]() { return 0; } + static set ["" + ""](x) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit3.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit3.ts new file mode 100644 index 00000000000..041a2f153e7 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit3.ts @@ -0,0 +1,5 @@ +// @target: es6 +// @declaration: true +interface I { + ["" + ""](): void; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit4.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit4.ts new file mode 100644 index 00000000000..59a5fe71267 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit4.ts @@ -0,0 +1,5 @@ +// @target: es6 +// @declaration: true +var v: { + ["" + ""](): void; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5.ts new file mode 100644 index 00000000000..3f24075abbf --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesDeclarationEmit5.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @declaration: true +var v = { + ["" + ""]: 0, + ["" + ""]() { }, + get ["" + ""]() { return 0; }, + set ["" + ""](x) { } +} \ No newline at end of file From 96f8d6273e090846bace7e9d5eb6fe822882d7d3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 21 Jan 2015 10:06:13 -0800 Subject: [PATCH 29/71] Missed a file --- tests/baselines/reference/elaboratedErrors.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/baselines/reference/elaboratedErrors.js diff --git a/tests/baselines/reference/elaboratedErrors.js b/tests/baselines/reference/elaboratedErrors.js new file mode 100644 index 00000000000..c245c1a8562 --- /dev/null +++ b/tests/baselines/reference/elaboratedErrors.js @@ -0,0 +1,45 @@ +//// [elaboratedErrors.ts] +interface FileSystem { + read: number; +} + +function fn(s: WorkerFS): void; +function fn(s: FileSystem): void; +function fn(s: FileSystem|WorkerFS) { } + +// This should issue a large error, not a small one +class WorkerFS implements FileSystem { + read: string; +} + +interface Alpha { x: string; } +interface Beta { y: number; } +var x: Alpha; +var y: Beta; + +// Only one of these errors should be large +x = y; +x = y; + +// Only one of these errors should be large +y = x; +y = x; + + +//// [elaboratedErrors.js] +function fn(s) { +} +// This should issue a large error, not a small one +var WorkerFS = (function () { + function WorkerFS() { + } + return WorkerFS; +})(); +var x; +var y; +// Only one of these errors should be large +x = y; +x = y; +// Only one of these errors should be large +y = x; +y = x; From de5aa6c0d2e8f4fe5920d8559f797e6d6d706e7f Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 21 Jan 2015 11:01:05 -0800 Subject: [PATCH 30/71] Fix source map scope name for computed properties --- src/compiler/emitter.ts | 16 ++- .../computedPropertyNamesSourceMap1.js | 17 +++ .../computedPropertyNamesSourceMap1.js.map | 2 + ...putedPropertyNamesSourceMap1.sourcemap.txt | 114 ++++++++++++++++++ .../computedPropertyNamesSourceMap1.types | 8 ++ .../computedPropertyNamesSourceMap2.js | 14 +++ .../computedPropertyNamesSourceMap2.js.map | 2 + ...putedPropertyNamesSourceMap2.sourcemap.txt | 73 +++++++++++ .../computedPropertyNamesSourceMap2.types | 9 ++ .../computedPropertyNamesSourceMap1.ts | 7 ++ .../computedPropertyNamesSourceMap2.ts | 7 ++ 11 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap1.js create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap1.js.map create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap1.sourcemap.txt create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap1.types create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap2.js create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap2.js.map create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap2.sourcemap.txt create mode 100644 tests/baselines/reference/computedPropertyNamesSourceMap2.types create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7c457126f19..348f3037324 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1734,7 +1734,14 @@ module ts { if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; + // Child scopes are always shown with a dot (even if they have no name), + // unless it is a computed property. Then it is shown with brackets, + // but the brackets are included in the name. + var name = (node).name; + if (!name || name.kind !== SyntaxKind.ComputedPropertyName) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; } scopeNameIndex = getProperty(sourceMapNameIndexMap, scopeName); @@ -1762,8 +1769,11 @@ module ts { node.kind === SyntaxKind.EnumDeclaration) { // Declaration and has associated name use it if ((node).name) { - // TODO(jfreeman): Ask shkamat about what this name should be for source maps - scopeName = ((node).name).text; + var name = (node).name; + // For computed property names, the text will include the brackets + scopeName = name.kind === SyntaxKind.ComputedPropertyName + ? getTextOfNode(name) + : ((node).name).text; } recordScopeNameStart(scopeName); } diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1.js b/tests/baselines/reference/computedPropertyNamesSourceMap1.js new file mode 100644 index 00000000000..b65e3f0ce5b --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1.js @@ -0,0 +1,17 @@ +//// [computedPropertyNamesSourceMap1.ts] +class C { + ["hello"]() { + debugger; + } +} + +//// [computedPropertyNamesSourceMap1.js] +var C = (function () { + function C() { + } + C.prototype["hello"] = function () { + debugger; + }; + return C; +})(); +//# sourceMappingURL=computedPropertyNamesSourceMap1.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1.js.map new file mode 100644 index 00000000000..5833df72f7f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1.js.map @@ -0,0 +1,2 @@ +//// [computedPropertyNamesSourceMap1.js.map] +{"version":3,"file":"computedPropertyNamesSourceMap1.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAIPC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1.sourcemap.txt new file mode 100644 index 00000000000..e806eee1aa7 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1.sourcemap.txt @@ -0,0 +1,114 @@ +=================================================================== +JsFile: computedPropertyNamesSourceMap1.js +mapUrl: computedPropertyNamesSourceMap1.js.map +sourceRoot: +sources: computedPropertyNamesSourceMap1.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.js +sourceFile:computedPropertyNamesSourceMap1.ts +------------------------------------------------------------------- +>>>var C = (function () { +1 > +2 >^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^-> +1 > +2 >class +3 > C +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(1, 7) + SourceIndex(0) +3 >Emitted(1, 6) Source(1, 8) + SourceIndex(0) +--- +>>> function C() { +1->^^^^ +2 > ^^^^^^^^^ +3 > ^ +1-> +2 > class +3 > C +1->Emitted(2, 5) Source(1, 1) + SourceIndex(0) name (C) +2 >Emitted(2, 14) Source(1, 7) + SourceIndex(0) name (C) +3 >Emitted(2, 15) Source(1, 8) + SourceIndex(0) name (C) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > { + > ["hello"]() { + > debugger; + > } + > +2 > } +1 >Emitted(3, 5) Source(5, 1) + SourceIndex(0) name (C.constructor) +2 >Emitted(3, 6) Source(5, 2) + SourceIndex(0) name (C.constructor) +--- +>>> C.prototype["hello"] = function () { +1->^^^^ +2 > ^^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^ +5 > ^^^ +1-> +2 > [ +3 > "hello" +4 > ] +5 > +1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) +2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) +3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) +4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) +5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) +--- +>>> debugger; +1 >^^^^^^^^ +2 > ^^^^^^^^ +3 > ^ +1 >["hello"]() { + > +2 > debugger +3 > ; +1 >Emitted(5, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) +2 >Emitted(5, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) +3 >Emitted(5, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) +2 >Emitted(6, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) +--- +>>> return C; +1->^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(7, 5) Source(5, 1) + SourceIndex(0) name (C) +2 >Emitted(7, 13) Source(5, 2) + SourceIndex(0) name (C) +--- +>>>})(); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class C { + > ["hello"]() { + > debugger; + > } + > } +1 >Emitted(8, 1) Source(5, 1) + SourceIndex(0) name (C) +2 >Emitted(8, 2) Source(5, 2) + SourceIndex(0) name (C) +3 >Emitted(8, 2) Source(1, 1) + SourceIndex(0) +4 >Emitted(8, 6) Source(5, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=computedPropertyNamesSourceMap1.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1.types b/tests/baselines/reference/computedPropertyNamesSourceMap1.types new file mode 100644 index 00000000000..54a2a9f19d0 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.ts === +class C { +>C : C + + ["hello"]() { + debugger; + } +} diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2.js b/tests/baselines/reference/computedPropertyNamesSourceMap2.js new file mode 100644 index 00000000000..d967cb0d468 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2.js @@ -0,0 +1,14 @@ +//// [computedPropertyNamesSourceMap2.ts] +var v = { + ["hello"]() { + debugger; + } +} + +//// [computedPropertyNamesSourceMap2.js] +var v = { + ["hello"]() { + debugger; + } +}; +//# sourceMappingURL=computedPropertyNamesSourceMap2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap2.js.map new file mode 100644 index 00000000000..6c485c24f6f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2.js.map @@ -0,0 +1,2 @@ +//// [computedPropertyNamesSourceMap2.js.map] +{"version":3,"file":"computedPropertyNamesSourceMap2.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2.ts"],"names":["[\"hello\"]"],"mappings":"AAAA,IAAI,CAAC,GAAG;IACJ,CAAC,OAAO,CAAC;QACLA,QAAQA,CAACA;IACbA,CAACA;CACJ,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap2.sourcemap.txt new file mode 100644 index 00000000000..29f11b95e1f --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2.sourcemap.txt @@ -0,0 +1,73 @@ +=================================================================== +JsFile: computedPropertyNamesSourceMap2.js +mapUrl: computedPropertyNamesSourceMap2.js.map +sourceRoot: +sources: computedPropertyNamesSourceMap2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.js +sourceFile:computedPropertyNamesSourceMap2.ts +------------------------------------------------------------------- +>>>var v = { +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^^^^^^^^^^-> +1 > +2 >var +3 > v +4 > = +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) +3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) +4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0) +--- +>>> ["hello"]() { +1->^^^^ +2 > ^ +3 > ^^^^^^^ +4 > ^ +5 > ^^^^^-> +1->{ + > +2 > [ +3 > "hello" +4 > ] +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) +--- +>>> debugger; +1->^^^^^^^^ +2 > ^^^^^^^^ +3 > ^ +1->() { + > +2 > debugger +3 > ; +1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) name (["hello"]) +2 >Emitted(3, 17) Source(3, 17) + SourceIndex(0) name (["hello"]) +3 >Emitted(3, 18) Source(3, 18) + SourceIndex(0) name (["hello"]) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (["hello"]) +2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) name (["hello"]) +--- +>>>}; +1 >^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +2 > +1 >Emitted(5, 2) Source(5, 2) + SourceIndex(0) +2 >Emitted(5, 3) Source(5, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=computedPropertyNamesSourceMap2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2.types b/tests/baselines/reference/computedPropertyNamesSourceMap2.types new file mode 100644 index 00000000000..972259eb3e2 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.ts === +var v = { +>v : {} +>{ ["hello"]() { debugger; }} : {} + + ["hello"]() { + debugger; + } +} diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.ts new file mode 100644 index 00000000000..73d9dc215d9 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.ts @@ -0,0 +1,7 @@ +// @target: es6 +// @sourceMap: true +class C { + ["hello"]() { + debugger; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.ts new file mode 100644 index 00000000000..fc7f4fcb39d --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.ts @@ -0,0 +1,7 @@ +// @target: es6 +// @sourceMap: true +var v = { + ["hello"]() { + debugger; + } +} \ No newline at end of file From 768d818d27d06cc62214cac54b74d110053fde2e Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 21 Jan 2015 15:05:19 -0800 Subject: [PATCH 31/71] Fix error message wording --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- tests/baselines/reference/computedPropertyNames32.errors.txt | 4 ++-- tests/baselines/reference/computedPropertyNames35.errors.txt | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fb4a02cb563..3c8696d31e7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -342,7 +342,7 @@ module ts { if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) { - error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_contained_type); + error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 036d1840cdc..f333520733e 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -302,7 +302,7 @@ module ts { A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', or 'any'." }, this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." }, super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." }, - A_computed_property_name_cannot_reference_a_type_parameter_from_its_contained_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its contained type." }, + A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 94a448e7860..49ee8eebcd9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1302,7 +1302,7 @@ "category": "Error", "code": 2466 }, - "A computed property name cannot reference a type parameter from its contained type.": { + "A computed property name cannot reference a type parameter from its containing type.": { "category": "Error", "code": 2466 }, diff --git a/tests/baselines/reference/computedPropertyNames32.errors.txt b/tests/baselines/reference/computedPropertyNames32.errors.txt index 8a7b0995153..e2f08c79fc9 100644 --- a/tests/baselines/reference/computedPropertyNames32.errors.txt +++ b/tests/baselines/reference/computedPropertyNames32.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts(6,10): error TS2466: A computed property name cannot reference a type parameter from its contained type. +tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts(6,10): error TS2466: A computed property name cannot reference a type parameter from its containing type. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts(6,10): } [foo()]() { } ~ -!!! error TS2466: A computed property name cannot reference a type parameter from its contained type. +!!! error TS2466: A computed property name cannot reference a type parameter from its containing type. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames35.errors.txt b/tests/baselines/reference/computedPropertyNames35.errors.txt index 665831d6382..01c4614e84a 100644 --- a/tests/baselines/reference/computedPropertyNames35.errors.txt +++ b/tests/baselines/reference/computedPropertyNames35.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,5): error TS1169: Computed property names are not allowed in interfaces. -tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,10): error TS2466: A computed property name cannot reference a type parameter from its contained type. +tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,10): error TS2466: A computed property name cannot reference a type parameter from its containing type. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts (2 errors) ==== @@ -10,5 +10,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,10): ~~~~~~~~~~ !!! error TS1169: Computed property names are not allowed in interfaces. ~ -!!! error TS2466: A computed property name cannot reference a type parameter from its contained type. +!!! error TS2466: A computed property name cannot reference a type parameter from its containing type. } \ No newline at end of file From f7a8ba28ff3428deec837e81e0ac6667694961ce Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 21 Jan 2015 17:01:42 -0800 Subject: [PATCH 32/71] Use isTypeOfKind in computed property checks --- src/compiler/checker.ts | 6 ++- .../computedPropertyNames15.errors.txt | 5 +- .../reference/computedPropertyNames46.js | 9 ++++ .../reference/computedPropertyNames46.types | 9 ++++ .../reference/computedPropertyNames47.js | 19 ++++++++ .../reference/computedPropertyNames47.types | 23 +++++++++ .../reference/computedPropertyNames48.js | 34 ++++++++++++++ .../reference/computedPropertyNames48.types | 47 +++++++++++++++++++ .../computedPropertyNames6.errors.txt | 5 +- .../computedPropertyNames7.errors.txt | 12 ----- .../reference/computedPropertyNames7.types | 16 +++++++ .../computedPropertyNames46.ts | 4 ++ .../computedPropertyNames47.ts | 6 +++ .../computedPropertyNames48.ts | 18 +++++++ 14 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 tests/baselines/reference/computedPropertyNames46.js create mode 100644 tests/baselines/reference/computedPropertyNames46.types create mode 100644 tests/baselines/reference/computedPropertyNames47.js create mode 100644 tests/baselines/reference/computedPropertyNames47.types create mode 100644 tests/baselines/reference/computedPropertyNames48.js create mode 100644 tests/baselines/reference/computedPropertyNames48.types delete mode 100644 tests/baselines/reference/computedPropertyNames7.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames7.types create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames46.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames47.ts create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNames48.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 205c280ee95..d50d8eb89d1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5383,7 +5383,9 @@ module ts { } function isNumericComputedName(name: ComputedPropertyName): boolean { - return !!(checkExpression(name.expression).flags & TypeFlags.Number); + // It seems odd to consider an expression of type Any to result in a numeric name, + // but this behavior is consistent with checkIndexedAccess + return isTypeOfKind(checkExpression(name.expression), TypeFlags.Any | TypeFlags.NumberLike); } function isNumericLiteralName(name: string) { @@ -5419,7 +5421,7 @@ module ts { // This will only allow types number, string, or any. Any types more complex will // be disallowed, even union types like string | number. In the future, we might consider // allowing types like that. - if ((links.resolvedType.flags & (TypeFlags.Number | TypeFlags.String | TypeFlags.Any)) === 0) { + if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); } } diff --git a/tests/baselines/reference/computedPropertyNames15.errors.txt b/tests/baselines/reference/computedPropertyNames15.errors.txt index 69d997d7737..0e759668a95 100644 --- a/tests/baselines/reference/computedPropertyNames15.errors.txt +++ b/tests/baselines/reference/computedPropertyNames15.errors.txt @@ -1,16 +1,13 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(6,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts (3 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts (2 errors) ==== var p1: number | string; var p2: number | number[]; var p3: string | boolean; class C { [p1]() { } - ~~~~ -!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [p2]() { } ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. diff --git a/tests/baselines/reference/computedPropertyNames46.js b/tests/baselines/reference/computedPropertyNames46.js new file mode 100644 index 00000000000..e2ef2b2e729 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames46.js @@ -0,0 +1,9 @@ +//// [computedPropertyNames46.ts] +var o = { + ["" || 0]: 0 +}; + +//// [computedPropertyNames46.js] +var o = { + ["" || 0]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNames46.types b/tests/baselines/reference/computedPropertyNames46.types new file mode 100644 index 00000000000..cf8585828f4 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames46.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames46.ts === +var o = { +>o : {} +>{ ["" || 0]: 0} : {} + + ["" || 0]: 0 +>"" || 0 : string | number + +}; diff --git a/tests/baselines/reference/computedPropertyNames47.js b/tests/baselines/reference/computedPropertyNames47.js new file mode 100644 index 00000000000..88e28e54239 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames47.js @@ -0,0 +1,19 @@ +//// [computedPropertyNames47.ts] +enum E1 { x } +enum E2 { x } +var o = { + [E1.x || E2.x]: 0 +}; + +//// [computedPropertyNames47.js] +var E1; +(function (E1) { + E1[E1["x"] = 0] = "x"; +})(E1 || (E1 = {})); +var E2; +(function (E2) { + E2[E2["x"] = 0] = "x"; +})(E2 || (E2 = {})); +var o = { + [0 /* x */ || 0 /* x */]: 0 +}; diff --git a/tests/baselines/reference/computedPropertyNames47.types b/tests/baselines/reference/computedPropertyNames47.types new file mode 100644 index 00000000000..20d7ab1d31e --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames47.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames47.ts === +enum E1 { x } +>E1 : E1 +>x : E1 + +enum E2 { x } +>E2 : E2 +>x : E2 + +var o = { +>o : {} +>{ [E1.x || E2.x]: 0} : {} + + [E1.x || E2.x]: 0 +>E1.x || E2.x : E1 | E2 +>E1.x : E1 +>E1 : typeof E1 +>x : E1 +>E2.x : E2 +>E2 : typeof E2 +>x : E2 + +}; diff --git a/tests/baselines/reference/computedPropertyNames48.js b/tests/baselines/reference/computedPropertyNames48.js new file mode 100644 index 00000000000..9f8e0442ebe --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames48.js @@ -0,0 +1,34 @@ +//// [computedPropertyNames48.ts] +declare function extractIndexer(p: { [n: number]: T }): T; + +enum E { x } + +var a: any; + +extractIndexer({ + [a]: "" +}); // Should return string + +extractIndexer({ + [E.x]: "" +}); // Should return string + +extractIndexer({ + ["" || 0]: "" +}); // Should return any (widened form of undefined) + +//// [computedPropertyNames48.js] +var E; +(function (E) { + E[E["x"] = 0] = "x"; +})(E || (E = {})); +var a; +extractIndexer({ + [a]: "" +}); // Should return string +extractIndexer({ + [0 /* x */]: "" +}); // Should return string +extractIndexer({ + ["" || 0]: "" +}); // Should return any (widened form of undefined) diff --git a/tests/baselines/reference/computedPropertyNames48.types b/tests/baselines/reference/computedPropertyNames48.types new file mode 100644 index 00000000000..78755d5d5d7 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames48.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames48.ts === +declare function extractIndexer(p: { [n: number]: T }): T; +>extractIndexer : (p: { [n: number]: T; }) => T +>T : T +>p : { [n: number]: T; } +>n : number +>T : T +>T : T + +enum E { x } +>E : E +>x : E + +var a: any; +>a : any + +extractIndexer({ +>extractIndexer({ [a]: ""}) : string +>extractIndexer : (p: { [n: number]: T; }) => T +>{ [a]: ""} : { [x: number]: string; } + + [a]: "" +>a : any + +}); // Should return string + +extractIndexer({ +>extractIndexer({ [E.x]: ""}) : string +>extractIndexer : (p: { [n: number]: T; }) => T +>{ [E.x]: ""} : { [x: number]: string; } + + [E.x]: "" +>E.x : E +>E : typeof E +>x : E + +}); // Should return string + +extractIndexer({ +>extractIndexer({ ["" || 0]: ""}) : any +>extractIndexer : (p: { [n: number]: T; }) => T +>{ ["" || 0]: ""} : { [x: number]: undefined; } + + ["" || 0]: "" +>"" || 0 : string | number + +}); // Should return any (widened form of undefined) diff --git a/tests/baselines/reference/computedPropertyNames6.errors.txt b/tests/baselines/reference/computedPropertyNames6.errors.txt index 100afc85992..57798e9f6b6 100644 --- a/tests/baselines/reference/computedPropertyNames6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames6.errors.txt @@ -1,16 +1,13 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(6,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts (3 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts (2 errors) ==== var p1: number | string; var p2: number | number[]; var p3: string | boolean; var v = { [p1]: 0, - ~~~~ -!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. [p2]: 1, ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. diff --git a/tests/baselines/reference/computedPropertyNames7.errors.txt b/tests/baselines/reference/computedPropertyNames7.errors.txt deleted file mode 100644 index e98be616a3a..00000000000 --- a/tests/baselines/reference/computedPropertyNames7.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'. - - -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts (1 errors) ==== - enum E { - member - } - var v = { - [E.member]: 0 - ~~~~~~~~~~ -!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'. - } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames7.types b/tests/baselines/reference/computedPropertyNames7.types new file mode 100644 index 00000000000..0b5f26614fc --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames7.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts === +enum E { +>E : E + + member +>member : E +} +var v = { +>v : {} +>{ [E.member]: 0} : {} + + [E.member]: 0 +>E.member : E +>E : typeof E +>member : E +} diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames46.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames46.ts new file mode 100644 index 00000000000..219324dc153 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames46.ts @@ -0,0 +1,4 @@ +// @target: es6 +var o = { + ["" || 0]: 0 +}; \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames47.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames47.ts new file mode 100644 index 00000000000..724536c90e8 --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames47.ts @@ -0,0 +1,6 @@ +// @target: es6 +enum E1 { x } +enum E2 { x } +var o = { + [E1.x || E2.x]: 0 +}; \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames48.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames48.ts new file mode 100644 index 00000000000..3a156aa480e --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames48.ts @@ -0,0 +1,18 @@ +// @target: es6 +declare function extractIndexer(p: { [n: number]: T }): T; + +enum E { x } + +var a: any; + +extractIndexer({ + [a]: "" +}); // Should return string + +extractIndexer({ + [E.x]: "" +}); // Should return string + +extractIndexer({ + ["" || 0]: "" +}); // Should return any (widened form of undefined) \ No newline at end of file From 12fc41843b7d77c2d56ebdb5c3053a375cc8571a Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 21 Jan 2015 17:05:32 -0800 Subject: [PATCH 33/71] Make isNumericComputedName call checkComputedPropertyName --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d50d8eb89d1..feaeff75e8f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5385,7 +5385,7 @@ module ts { function isNumericComputedName(name: ComputedPropertyName): boolean { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return isTypeOfKind(checkExpression(name.expression), TypeFlags.Any | TypeFlags.NumberLike); + return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike); } function isNumericLiteralName(name: string) { From 883385f5cb321fc8008e5d4f3727412fee41d0dc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 22 Jan 2015 11:03:15 -0800 Subject: [PATCH 34/71] Include missing optional properties in contextually typed object literal --- src/compiler/checker.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1e84c78fce1..a3ea14dcb09 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5455,6 +5455,16 @@ module ts { } } + // If object literal is contextually typed, add missing optional properties from the contextual type + // such that the resulting type becomes a subtype in cases where only optional properties were omitted + if (contextualType) { + forEach(getPropertiesOfObjectType(contextualType), p => { + if (p.flags & SymbolFlags.Optional && !hasProperty(properties, p.name)) { + properties[p.name] = p; + } + }); + } + var stringIndexType = getIndexType(IndexKind.String); var numberIndexType = getIndexType(IndexKind.Number); var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); From 21e6784038c10cc72d77db2add8a733bc304e82d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 22 Jan 2015 11:04:09 -0800 Subject: [PATCH 35/71] Accepting new baselines --- .../reference/assignmentCompatBug2.errors.txt | 16 ++++++++-------- .../assignmentCompatWithObjectMembers3.types | 4 ++-- .../reference/assignmentCompatability1.types | 2 +- .../reference/assignmentCompatability2.types | 2 +- .../reference/assignmentCompatability3.types | 2 +- .../reference/assignmentCompatability4.types | 2 +- .../reference/assignmentCompatability5.types | 2 +- .../reference/assignmentCompatability6.types | 4 ++-- .../reference/assignmentCompatability7.types | 4 ++-- .../reference/assignmentCompatability8.types | 2 +- .../reference/assignmentCompatability9.types | 2 +- .../reference/getterSetterNonAccessor.types | 4 ++-- .../baselines/reference/intTypeCheck.errors.txt | 8 ++++---- .../reference/interfaceContextualType.types | 12 ++++++------ .../reference/objectLitGetterSetter.types | 4 ++-- .../optionalAccessorsInInterface1.types | 4 ++-- .../reference/optionalPropertiesTest.errors.txt | 8 ++++---- ...rloadBindingAcrossDeclarationBoundaries.types | 6 +++--- ...loadBindingAcrossDeclarationBoundaries2.types | 6 +++--- ...eAnnotationBestCommonTypeInArrayLiteral.types | 6 +++--- tests/baselines/reference/underscoreTest1.types | 6 +++--- 21 files changed, 53 insertions(+), 53 deletions(-) diff --git a/tests/baselines/reference/assignmentCompatBug2.errors.txt b/tests/baselines/reference/assignmentCompatBug2.errors.txt index 15bf1111391..b90c470d771 100644 --- a/tests/baselines/reference/assignmentCompatBug2.errors.txt +++ b/tests/baselines/reference/assignmentCompatBug2.errors.txt @@ -2,10 +2,10 @@ tests/cases/compiler/assignmentCompatBug2.ts(1,5): error TS2322: Type '{ a: numb Property 'b' is missing in type '{ a: number; }'. tests/cases/compiler/assignmentCompatBug2.ts(3,1): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'. Property 'b' is missing in type '{ a: number; }'. -tests/cases/compiler/assignmentCompatBug2.ts(15,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. - Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; }'. -tests/cases/compiler/assignmentCompatBug2.ts(20,1): error TS2322: Type '{ f: (n: number) => number; m: number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. - Property 'g' is missing in type '{ f: (n: number) => number; m: number; }'. +tests/cases/compiler/assignmentCompatBug2.ts(15,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. + Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }'. +tests/cases/compiler/assignmentCompatBug2.ts(20,1): error TS2322: Type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. + Property 'g' is missing in type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }'. tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; n: number; k: (a: any) => any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n: number; k: (a: any) => any; }'. @@ -33,16 +33,16 @@ tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2322: Type '{ f: (n: b3 = { ~~ -!!! error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. -!!! error TS2322: Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; }'. +!!! error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. +!!! error TS2322: Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }'. f: (n) => { return 0; }, g: (s) => { return 0; }, }; // error b3 = { ~~ -!!! error TS2322: Type '{ f: (n: number) => number; m: number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. -!!! error TS2322: Property 'g' is missing in type '{ f: (n: number) => number; m: number; }'. +!!! error TS2322: Type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. +!!! error TS2322: Property 'g' is missing in type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }'. f: (n) => { return 0; }, m: 0, }; // error diff --git a/tests/baselines/reference/assignmentCompatWithObjectMembers3.types b/tests/baselines/reference/assignmentCompatWithObjectMembers3.types index 85a7e59ffbc..ff7ef23307d 100644 --- a/tests/baselines/reference/assignmentCompatWithObjectMembers3.types +++ b/tests/baselines/reference/assignmentCompatWithObjectMembers3.types @@ -51,13 +51,13 @@ var b: { foo: string; baz?: string } var a2: S2 = { foo: '' }; >a2 : S2 >S2 : S2 ->{ foo: '' } : { foo: string; } +>{ foo: '' } : { foo: string; bar?: string; } >foo : string var b2: T2 = { foo: '' }; >b2 : T2 >T2 : T2 ->{ foo: '' } : { foo: string; } +>{ foo: '' } : { foo: string; baz?: string; } >foo : string s = t; diff --git a/tests/baselines/reference/assignmentCompatability1.types b/tests/baselines/reference/assignmentCompatability1.types index 9949fc14bf5..8bb4301b201 100644 --- a/tests/baselines/reference/assignmentCompatability1.types +++ b/tests/baselines/reference/assignmentCompatability1.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability2.types b/tests/baselines/reference/assignmentCompatability2.types index 16da45c7e35..69a20b34dd7 100644 --- a/tests/baselines/reference/assignmentCompatability2.types +++ b/tests/baselines/reference/assignmentCompatability2.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability3.types b/tests/baselines/reference/assignmentCompatability3.types index 61279b9c7fa..4b598fba84c 100644 --- a/tests/baselines/reference/assignmentCompatability3.types +++ b/tests/baselines/reference/assignmentCompatability3.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability4.types b/tests/baselines/reference/assignmentCompatability4.types index f7e5801e9b3..3d8e776ff72 100644 --- a/tests/baselines/reference/assignmentCompatability4.types +++ b/tests/baselines/reference/assignmentCompatability4.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability5.types b/tests/baselines/reference/assignmentCompatability5.types index 80eda3e510b..970c913955d 100644 --- a/tests/baselines/reference/assignmentCompatability5.types +++ b/tests/baselines/reference/assignmentCompatability5.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability6.types b/tests/baselines/reference/assignmentCompatability6.types index 5e9ae8c6a2f..cf131600c41 100644 --- a/tests/baselines/reference/assignmentCompatability6.types +++ b/tests/baselines/reference/assignmentCompatability6.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; @@ -29,7 +29,7 @@ module __test2__ { >T : T >obj3 : interfaceWithOptional >interfaceWithOptional : interfaceWithOptional ->{ } : {} +>{ } : { one?: number; } export var __val__obj3 = obj3; >__val__obj3 : interfaceWithOptional diff --git a/tests/baselines/reference/assignmentCompatability7.types b/tests/baselines/reference/assignmentCompatability7.types index b7b2ab70566..5bb46428314 100644 --- a/tests/baselines/reference/assignmentCompatability7.types +++ b/tests/baselines/reference/assignmentCompatability7.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; @@ -32,7 +32,7 @@ module __test2__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability8.types b/tests/baselines/reference/assignmentCompatability8.types index 1c009eea482..21fa300a37d 100644 --- a/tests/baselines/reference/assignmentCompatability8.types +++ b/tests/baselines/reference/assignmentCompatability8.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability9.types b/tests/baselines/reference/assignmentCompatability9.types index a8235220bec..cc8df0387e7 100644 --- a/tests/baselines/reference/assignmentCompatability9.types +++ b/tests/baselines/reference/assignmentCompatability9.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; } +>{ one: 1 } : { one: number; two?: string; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/getterSetterNonAccessor.types b/tests/baselines/reference/getterSetterNonAccessor.types index f3e5d549cff..0c1be481b3a 100644 --- a/tests/baselines/reference/getterSetterNonAccessor.types +++ b/tests/baselines/reference/getterSetterNonAccessor.types @@ -14,8 +14,8 @@ Object.defineProperty({}, "0", ({ >{} : {} >({ get: getFunc, set: setFunc, configurable: true }) : PropertyDescriptor >PropertyDescriptor : PropertyDescriptor ->({ get: getFunc, set: setFunc, configurable: true }) : { get: () => any; set: (v: any) => void; configurable: boolean; } ->{ get: getFunc, set: setFunc, configurable: true } : { get: () => any; set: (v: any) => void; configurable: boolean; } +>({ get: getFunc, set: setFunc, configurable: true }) : { get: () => any; set: (v: any) => void; configurable: boolean; enumerable?: boolean; value?: any; writable?: boolean; } +>{ get: getFunc, set: setFunc, configurable: true } : { get: () => any; set: (v: any) => void; configurable: boolean; enumerable?: boolean; value?: any; writable?: boolean; } get: getFunc, >get : () => any diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 5f7c213a916..237a4b8e7f2 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -39,8 +39,8 @@ tests/cases/compiler/intTypeCheck.ts(146,5): error TS2322: Type 'boolean' is not tests/cases/compiler/intTypeCheck.ts(146,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(146,22): error TS2304: Cannot find name 'i4'. tests/cases/compiler/intTypeCheck.ts(147,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(152,5): error TS2322: Type '{}' is not assignable to type 'i5'. - Property 'p' is missing in type '{}'. +tests/cases/compiler/intTypeCheck.ts(152,5): error TS2322: Type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }' is not assignable to type 'i5'. + Property 'p' is missing in type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }'. tests/cases/compiler/intTypeCheck.ts(153,5): error TS2322: Type 'Object' is not assignable to type 'i5'. Property 'p' is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(154,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -313,8 +313,8 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit var obj44: i5; var obj45: i5 = {}; ~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'i5'. -!!! error TS2322: Property 'p' is missing in type '{}'. +!!! error TS2322: Type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }' is not assignable to type 'i5'. +!!! error TS2322: Property 'p' is missing in type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }'. var obj46: i5 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i5'. diff --git a/tests/baselines/reference/interfaceContextualType.types b/tests/baselines/reference/interfaceContextualType.types index 3078ecfdfa4..412a48cfbda 100644 --- a/tests/baselines/reference/interfaceContextualType.types +++ b/tests/baselines/reference/interfaceContextualType.types @@ -34,27 +34,27 @@ class Bug { >{} : { [x: string]: undefined; } this.values['comments'] = { italic: true }; ->this.values['comments'] = { italic: true } : { italic: boolean; } +>this.values['comments'] = { italic: true } : { italic: boolean; bold?: boolean; } >this.values['comments'] : IOptions >this.values : IMap >this : Bug >values : IMap ->{ italic: true } : { italic: boolean; } +>{ italic: true } : { italic: boolean; bold?: boolean; } >italic : boolean } shouldBeOK() { >shouldBeOK : () => void this.values = { ->this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } +>this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; bold?: boolean; }; comments: { italic: boolean; bold?: boolean; }; } >this.values : IMap >this : Bug >values : IMap ->{ comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } +>{ comments: { italic: true } } : { [x: string]: { italic: boolean; bold?: boolean; }; comments: { italic: boolean; bold?: boolean; }; } comments: { italic: true } ->comments : { italic: boolean; } ->{ italic: true } : { italic: boolean; } +>comments : { italic: boolean; bold?: boolean; } +>{ italic: true } : { italic: boolean; bold?: boolean; } >italic : boolean }; diff --git a/tests/baselines/reference/objectLitGetterSetter.types b/tests/baselines/reference/objectLitGetterSetter.types index 92decfd4068..bbb7ee10140 100644 --- a/tests/baselines/reference/objectLitGetterSetter.types +++ b/tests/baselines/reference/objectLitGetterSetter.types @@ -11,8 +11,8 @@ >obj : {} >({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : PropertyDescriptor >PropertyDescriptor : PropertyDescriptor ->({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : { get: () => number; set: (v: any) => void; } ->{ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } } : { get: () => number; set: (v: any) => void; } +>({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : { get: () => number; set: (v: any) => void; configurable?: boolean; enumerable?: boolean; value?: any; writable?: boolean; } +>{ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } } : { get: () => number; set: (v: any) => void; configurable?: boolean; enumerable?: boolean; value?: any; writable?: boolean; } get: function () { >get : () => number diff --git a/tests/baselines/reference/optionalAccessorsInInterface1.types b/tests/baselines/reference/optionalAccessorsInInterface1.types index c426cdba178..f1dcd854f75 100644 --- a/tests/baselines/reference/optionalAccessorsInInterface1.types +++ b/tests/baselines/reference/optionalAccessorsInInterface1.types @@ -21,7 +21,7 @@ defineMyProperty({}, "name", { get: function () { return 5; } }); >defineMyProperty({}, "name", { get: function () { return 5; } }) : any >defineMyProperty : (o: any, p: string, attributes: MyPropertyDescriptor) => any >{} : {} ->{ get: function () { return 5; } } : { get: () => number; } +>{ get: function () { return 5; } } : { get: () => number; set?(v: any): void; } >get : () => number >function () { return 5; } : () => number @@ -47,7 +47,7 @@ defineMyProperty2({}, "name", { get: function () { return 5; } }); >defineMyProperty2({}, "name", { get: function () { return 5; } }) : any >defineMyProperty2 : (o: any, p: string, attributes: MyPropertyDescriptor2) => any >{} : {} ->{ get: function () { return 5; } } : { get: () => number; } +>{ get: function () { return 5; } } : { get: () => number; set?: (v: any) => void; } >get : () => number >function () { return 5; } : () => number diff --git a/tests/baselines/reference/optionalPropertiesTest.errors.txt b/tests/baselines/reference/optionalPropertiesTest.errors.txt index a4b721e92ef..a904911e232 100644 --- a/tests/baselines/reference/optionalPropertiesTest.errors.txt +++ b/tests/baselines/reference/optionalPropertiesTest.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/optionalPropertiesTest.ts(14,1): error TS2322: Type '{ name: string; }' is not assignable to type 'IFoo'. - Property 'id' is missing in type '{ name: string; }'. +tests/cases/compiler/optionalPropertiesTest.ts(14,1): error TS2322: Type '{ name: string; print?(): void; }' is not assignable to type 'IFoo'. + Property 'id' is missing in type '{ name: string; print?(): void; }'. tests/cases/compiler/optionalPropertiesTest.ts(25,5): error TS2322: Type '{}' is not assignable to type 'i1'. Property 'M' is missing in type '{}'. tests/cases/compiler/optionalPropertiesTest.ts(26,5): error TS2322: Type '{}' is not assignable to type 'i3'. @@ -24,8 +24,8 @@ tests/cases/compiler/optionalPropertiesTest.ts(40,1): error TS2322: Type 'i2' is foo = { id: 1234, name: "test" }; // Ok foo = { name: "test" }; // Error, id missing ~~~ -!!! error TS2322: Type '{ name: string; }' is not assignable to type 'IFoo'. -!!! error TS2322: Property 'id' is missing in type '{ name: string; }'. +!!! error TS2322: Type '{ name: string; print?(): void; }' is not assignable to type 'IFoo'. +!!! error TS2322: Property 'id' is missing in type '{ name: string; print?(): void; }'. foo = {id: 1234, print:()=>{}} // Ok var s = foo.name || "default"; diff --git a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types index 311cf971b61..f597c93bdda 100644 --- a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types +++ b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types @@ -105,17 +105,17 @@ var a1 = a.a({}); >a.a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } >a : A >a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } ->{} : {} +>{} : { r?: any; } var a1 = a({}); >a1 : Opt3 >a({}) : Opt3 >a : A ->{} : {} +>{} : { r?: any; } var a1 = new a({}); >a1 : Opt3 >new a({}) : Opt3 >a : A ->{} : {} +>{} : { r?: any; } diff --git a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types index e67ff2f8de6..a854c159e0c 100644 --- a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types +++ b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types @@ -108,17 +108,17 @@ var a1 = a.a({}); >a.a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } >a : A >a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } ->{} : {} +>{} : { r?: any; } var a1 = a({}); >a1 : Opt3 >a({}) : Opt3 >a : A ->{} : {} +>{} : { r?: any; } var a1 = new a({}); >a1 : Opt3 >new a({}) : Opt3 >a : A ->{} : {} +>{} : { r?: any; } diff --git a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types index 27fcd05bb28..661aa3c3cbb 100644 --- a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types +++ b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types @@ -23,16 +23,16 @@ interface IMenuItem { var menuData: IMenuItem[] = [ >menuData : IMenuItem[] >IMenuItem : IMenuItem ->[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : ({ "id": string; "type": string; "link": string; "icon": string; } | { "id": string; "type": string; "link": string; "text": string; })[] +>[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : ({ "id": string; "type": string; "link": string; "icon": string; classes?: string; text?: string; } | { "id": string; "type": string; "link": string; "text": string; classes?: string; icon?: string; })[] { ->{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; } +>{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; classes?: string; text?: string; } "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { ->{ "id": "productName", "type": "default", "link": "", "text": "Product Name" } : { "id": string; "type": string; "link": string; "text": string; } +>{ "id": "productName", "type": "default", "link": "", "text": "Product Name" } : { "id": string; "type": string; "link": string; "text": string; classes?: string; icon?: string; } "id": "productName", "type": "default", diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index a3347457b8a..9e4f5ea1d1b 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -1317,11 +1317,11 @@ compiled2({ epithet: "stooge" }); >epithet : string _.templateSettings = { ->_.templateSettings = { interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; } +>_.templateSettings = { interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; evaluate?: RegExp; escape?: RegExp; } >_.templateSettings : Underscore.TemplateSettings >_ : Underscore.Static >templateSettings : Underscore.TemplateSettings ->{ interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; } +>{ interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; evaluate?: RegExp; escape?: RegExp; } interpolate: /\{\{(.+?)\}\}/g >interpolate : RegExp @@ -1347,7 +1347,7 @@ _.template("Using 'with': <%= data.answer %>", { answer: 'no' }, { variable: 'da >template : { (templateString: string): (data: any) => string; (templateString: string, data: any, settings?: Underscore.TemplateSettings): string; } >{ answer: 'no' } : { answer: string; } >answer : string ->{ variable: 'data' } : { variable: string; } +>{ variable: 'data' } : { variable: string; evaluate?: RegExp; interpolate?: RegExp; escape?: RegExp; } >variable : string === tests/cases/compiler/underscoreTest1_underscore.ts === From d2e96c17791fab2dc7e6ee5c266e32ba64392410 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jan 2015 14:45:55 -0800 Subject: [PATCH 36/71] Simplify enum emit. --- src/compiler/emitter.ts | 48 +++++++++---------- .../reference/sourceMapValidationEnums.js.map | 2 +- .../sourceMapValidationEnums.sourcemap.txt | 31 ++++++++++-- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index dafd03717a6..47f75dcf8ad 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3656,7 +3656,7 @@ module ts { write(") {"); increaseIndent(); scopeEmitStart(node); - emitEnumMemberDeclarations(isConstEnum); + emitLines(node.members); decreaseIndent(); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end); @@ -3678,31 +3678,29 @@ module ts { write(";"); } emitTrailingComments(node); + } - function emitEnumMemberDeclarations(isConstEnum: boolean) { - forEach(node.members, member => { - writeLine(); - emitLeadingComments(member); - emitStart(member); - write(resolver.getLocalNameOfContainer(node)); - write("["); - write(resolver.getLocalNameOfContainer(node)); - write("["); - emitExpressionForPropertyName(member.name); - write("] = "); - if (member.initializer && !isConstEnum) { - emit(member.initializer); - } - else { - write(resolver.getEnumMemberValue(member).toString()); - } - write("] = "); - emitExpressionForPropertyName(member.name); - emitEnd(member); - write(";"); - emitTrailingComments(member); - }); + function emitEnumMember(node: EnumMember) { + var enumParent = node.parent; + emitLeadingComments(node); + emitStart(node); + write(resolver.getLocalNameOfContainer(enumParent)); + write("["); + write(resolver.getLocalNameOfContainer(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + if (node.initializer && !isConst(enumParent)) { + emit(node.initializer); } + else { + write(resolver.getEnumMemberValue(node).toString()); + } + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); + emitTrailingComments(node); } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration { @@ -4099,6 +4097,8 @@ module ts { return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: return emitEnumDeclaration(node); + case SyntaxKind.EnumMember: + return emitEnumMember(node); case SyntaxKind.ModuleDeclaration: return emitModuleDeclaration(node); case SyntaxKind.ImportDeclaration: diff --git a/tests/baselines/reference/sourceMapValidationEnums.js.map b/tests/baselines/reference/sourceMapValidationEnums.js.map index 721e0a3b48b..1627788c6b6 100644 --- a/tests/baselines/reference/sourceMapValidationEnums.js.map +++ b/tests/baselines/reference/sourceMapValidationEnums.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationEnums.js.map] -{"version":3,"file":"sourceMapValidationEnums.js","sourceRoot":"","sources":["sourceMapValidationEnums.ts"],"names":["e","e2","e3"],"mappings":"AAAA,IAAK,CAIJ;AAJD,WAAK,CAAC;IACFA,mBAACA;IACDA,mBAACA;IACDA,mBAACA;AACLA,CAACA,EAJI,CAAC,KAAD,CAAC,QAIL;AACD,IAAK,EAKJ;AALD,WAAK,EAAE;IACHC,aAAIA,EAAEA,OAAAA;IACNA,aAAIA,EAAEA,OAAAA;IACNA,sBAACA;IACDA,wBAAEA;AACNA,CAACA,EALI,EAAE,KAAF,EAAE,QAKN;AACD,IAAK,EACJ;AADD,WAAK,EAAE;AACPC,CAACA,EADI,EAAE,KAAF,EAAE,QACN"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationEnums.js","sourceRoot":"","sources":["sourceMapValidationEnums.ts"],"names":["e","e2","e3"],"mappings":"AAAA,IAAK,CAIJ;AAJD,WAAK,CAAC;IACFA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;AACLA,CAACA,EAJI,CAAC,KAAD,CAAC,QAIL;AACD,IAAK,EAKJ;AALD,WAAK,EAAE;IACHC,aAAIA,EAAEA,OAAAA,CAAAA;IACNA,aAAIA,EAAEA,OAAAA,CAAAA;IACNA,sBAACA,CAAAA;IACDA,wBAAEA,CAAAA;AACNA,CAACA,EALI,EAAE,KAAF,EAAE,QAKN;AACD,IAAK,EACJ;AADD,WAAK,EAAE;AACPC,CAACA,EADI,EAAE,KAAF,EAAE,QACN"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt b/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt index 18148fc281b..337aa0989d3 100644 --- a/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt @@ -39,31 +39,40 @@ sourceFile:sourceMapValidationEnums.ts >>> e[e["x"] = 0] = "x"; 1->^^^^ 2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^^-> +3 > ^ +4 > ^-> 1-> { > 2 > x +3 > 1->Emitted(3, 5) Source(2, 5) + SourceIndex(0) name (e) 2 >Emitted(3, 24) Source(2, 6) + SourceIndex(0) name (e) +3 >Emitted(3, 25) Source(2, 6) + SourceIndex(0) name (e) --- >>> e[e["y"] = 1] = "y"; 1->^^^^ 2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^^-> +3 > ^ +4 > ^-> 1->, > 2 > y +3 > 1->Emitted(4, 5) Source(3, 5) + SourceIndex(0) name (e) 2 >Emitted(4, 24) Source(3, 6) + SourceIndex(0) name (e) +3 >Emitted(4, 25) Source(3, 6) + SourceIndex(0) name (e) --- >>> e[e["x"] = 2] = "x"; 1->^^^^ 2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ 1->, > 2 > x +3 > 1->Emitted(5, 5) Source(4, 5) + SourceIndex(0) name (e) 2 >Emitted(5, 24) Source(4, 6) + SourceIndex(0) name (e) +3 >Emitted(5, 25) Source(4, 6) + SourceIndex(0) name (e) --- >>>})(e || (e = {})); 1 > @@ -128,51 +137,63 @@ sourceFile:sourceMapValidationEnums.ts 2 > ^^^^^^^^^^^^^ 3 > ^^ 4 > ^^^^^^^ -5 > ^^-> +5 > ^ +6 > ^-> 1-> { > 2 > x = 3 > 10 4 > +5 > 1->Emitted(9, 5) Source(7, 5) + SourceIndex(0) name (e2) 2 >Emitted(9, 18) Source(7, 9) + SourceIndex(0) name (e2) 3 >Emitted(9, 20) Source(7, 11) + SourceIndex(0) name (e2) 4 >Emitted(9, 27) Source(7, 11) + SourceIndex(0) name (e2) +5 >Emitted(9, 28) Source(7, 11) + SourceIndex(0) name (e2) --- >>> e2[e2["y"] = 10] = "y"; 1->^^^^ 2 > ^^^^^^^^^^^^^ 3 > ^^ 4 > ^^^^^^^ -5 > ^^-> +5 > ^ +6 > ^-> 1->, > 2 > y = 3 > 10 4 > +5 > 1->Emitted(10, 5) Source(8, 5) + SourceIndex(0) name (e2) 2 >Emitted(10, 18) Source(8, 9) + SourceIndex(0) name (e2) 3 >Emitted(10, 20) Source(8, 11) + SourceIndex(0) name (e2) 4 >Emitted(10, 27) Source(8, 11) + SourceIndex(0) name (e2) +5 >Emitted(10, 28) Source(8, 11) + SourceIndex(0) name (e2) --- >>> e2[e2["z"] = 11] = "z"; 1->^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^ -3 > ^^^^-> +3 > ^ +4 > ^^^-> 1->, > 2 > z +3 > 1->Emitted(11, 5) Source(9, 5) + SourceIndex(0) name (e2) 2 >Emitted(11, 27) Source(9, 6) + SourceIndex(0) name (e2) +3 >Emitted(11, 28) Source(9, 6) + SourceIndex(0) name (e2) --- >>> e2[e2["x2"] = 12] = "x2"; 1->^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^ 1->, > 2 > x2 +3 > 1->Emitted(12, 5) Source(10, 5) + SourceIndex(0) name (e2) 2 >Emitted(12, 29) Source(10, 7) + SourceIndex(0) name (e2) +3 >Emitted(12, 30) Source(10, 7) + SourceIndex(0) name (e2) --- >>>})(e2 || (e2 = {})); 1 > From f661508bb6da32f157008f0414d796f0ddf0ff8d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 22 Jan 2015 14:51:37 -0800 Subject: [PATCH 37/71] Add missing optional properties only when not inferentially typing --- src/compiler/checker.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3ea14dcb09..7233c2e85d5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5455,9 +5455,10 @@ module ts { } } - // If object literal is contextually typed, add missing optional properties from the contextual type - // such that the resulting type becomes a subtype in cases where only optional properties were omitted - if (contextualType) { + // If object literal is contextually (but not inferentially) typed, copy missing optional properties from + // the contextual type such that the resulting type becomes a subtype in cases where only optional properties + // were omitted. There is no need to create new property objects as nothing in them needs to change. + if (contextualType && !isInferentialContext(contextualMapper)) { forEach(getPropertiesOfObjectType(contextualType), p => { if (p.flags & SymbolFlags.Optional && !hasProperty(properties, p.name)) { properties[p.name] = p; From 963de957cb905e669f7be1d280fa7ee381c0299f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 22 Jan 2015 14:52:15 -0800 Subject: [PATCH 38/71] Adding regression test --- .../objectLiteralContextualTyping.js | 29 ++++++++++ .../objectLiteralContextualTyping.types | 53 +++++++++++++++++++ .../objectLiteralContextualTyping.ts | 18 +++++++ 3 files changed, 100 insertions(+) create mode 100644 tests/baselines/reference/objectLiteralContextualTyping.js create mode 100644 tests/baselines/reference/objectLiteralContextualTyping.types create mode 100644 tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts diff --git a/tests/baselines/reference/objectLiteralContextualTyping.js b/tests/baselines/reference/objectLiteralContextualTyping.js new file mode 100644 index 00000000000..ebe10686516 --- /dev/null +++ b/tests/baselines/reference/objectLiteralContextualTyping.js @@ -0,0 +1,29 @@ +//// [objectLiteralContextualTyping.ts] +// Test related to #1774 + +interface Item { + name: string; + description?: string; +} + +declare function foo(item: Item): string; +declare function foo(item: any): number; + +var x = foo({ name: "Sprocket" }); +var x: string; + +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +var y: string; + +var z = foo({ a: 10 }); +var z: number; + + +//// [objectLiteralContextualTyping.js] +// Test related to #1774 +var x = foo({ name: "Sprocket" }); +var x; +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +var y; +var z = foo({ a: 10 }); +var z; diff --git a/tests/baselines/reference/objectLiteralContextualTyping.types b/tests/baselines/reference/objectLiteralContextualTyping.types new file mode 100644 index 00000000000..ff571ee541f --- /dev/null +++ b/tests/baselines/reference/objectLiteralContextualTyping.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts === +// Test related to #1774 + +interface Item { +>Item : Item + + name: string; +>name : string + + description?: string; +>description : string +} + +declare function foo(item: Item): string; +>foo : { (item: Item): string; (item: any): number; } +>item : Item +>Item : Item + +declare function foo(item: any): number; +>foo : { (item: Item): string; (item: any): number; } +>item : any + +var x = foo({ name: "Sprocket" }); +>x : string +>foo({ name: "Sprocket" }) : string +>foo : { (item: Item): string; (item: any): number; } +>{ name: "Sprocket" } : { name: string; description?: string; } +>name : string + +var x: string; +>x : string + +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +>y : string +>foo({ name: "Sprocket", description: "Bumpy wheel" }) : string +>foo : { (item: Item): string; (item: any): number; } +>{ name: "Sprocket", description: "Bumpy wheel" } : { name: string; description: string; } +>name : string +>description : string + +var y: string; +>y : string + +var z = foo({ a: 10 }); +>z : number +>foo({ a: 10 }) : number +>foo : { (item: Item): string; (item: any): number; } +>{ a: 10 } : { a: number; } +>a : number + +var z: number; +>z : number + diff --git a/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts new file mode 100644 index 00000000000..5920066aaa6 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts @@ -0,0 +1,18 @@ +// Test related to #1774 + +interface Item { + name: string; + description?: string; +} + +declare function foo(item: Item): string; +declare function foo(item: any): number; + +var x = foo({ name: "Sprocket" }); +var x: string; + +var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); +var y: string; + +var z = foo({ a: 10 }); +var z: number; From ccffc9f25f0a92fc0e59c456f8a893fa8ae73021 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 22 Jan 2015 15:12:55 -0800 Subject: [PATCH 39/71] Adding more tests --- .../objectLiteralContextualTyping.js | 20 ++++++++--- .../objectLiteralContextualTyping.types | 36 ++++++++++++++++--- .../objectLiteralContextualTyping.ts | 12 +++++-- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/objectLiteralContextualTyping.js b/tests/baselines/reference/objectLiteralContextualTyping.js index ebe10686516..48686042754 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.js +++ b/tests/baselines/reference/objectLiteralContextualTyping.js @@ -1,5 +1,5 @@ //// [objectLiteralContextualTyping.ts] -// Test related to #1774 +// Tests related to #1774 interface Item { name: string; @@ -15,15 +15,27 @@ var x: string; var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); var y: string; -var z = foo({ a: 10 }); +var z = foo({ name: "Sprocket", description: false }); var z: number; + +var w = foo({ a: 10 }); +var w: number; + +declare function bar(param: { x?: T }): T; + +var b = bar({}); +var b: {}; //// [objectLiteralContextualTyping.js] -// Test related to #1774 +// Tests related to #1774 var x = foo({ name: "Sprocket" }); var x; var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); var y; -var z = foo({ a: 10 }); +var z = foo({ name: "Sprocket", description: false }); var z; +var w = foo({ a: 10 }); +var w; +var b = bar({}); +var b; diff --git a/tests/baselines/reference/objectLiteralContextualTyping.types b/tests/baselines/reference/objectLiteralContextualTyping.types index ff571ee541f..495e8df1438 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.types +++ b/tests/baselines/reference/objectLiteralContextualTyping.types @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts === -// Test related to #1774 +// Tests related to #1774 interface Item { >Item : Item @@ -41,13 +41,41 @@ var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); var y: string; >y : string -var z = foo({ a: 10 }); +var z = foo({ name: "Sprocket", description: false }); >z : number +>foo({ name: "Sprocket", description: false }) : number +>foo : { (item: Item): string; (item: any): number; } +>{ name: "Sprocket", description: false } : { name: string; description: boolean; } +>name : string +>description : boolean + +var z: number; +>z : number + +var w = foo({ a: 10 }); +>w : number >foo({ a: 10 }) : number >foo : { (item: Item): string; (item: any): number; } >{ a: 10 } : { a: number; } >a : number -var z: number; ->z : number +var w: number; +>w : number + +declare function bar(param: { x?: T }): T; +>bar : (param: { x?: T; }) => T +>T : T +>param : { x?: T; } +>x : T +>T : T +>T : T + +var b = bar({}); +>b : {} +>bar({}) : {} +>bar : (param: { x?: T; }) => T +>{} : { x?: {}; } + +var b: {}; +>b : {} diff --git a/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts index 5920066aaa6..cb2fe8ee8d4 100644 --- a/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts +++ b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts @@ -1,4 +1,4 @@ -// Test related to #1774 +// Tests related to #1774 interface Item { name: string; @@ -14,5 +14,13 @@ var x: string; var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); var y: string; -var z = foo({ a: 10 }); +var z = foo({ name: "Sprocket", description: false }); var z: number; + +var w = foo({ a: 10 }); +var w: number; + +declare function bar(param: { x?: T }): T; + +var b = bar({}); +var b: {}; From a82289c8b452a156c8819bae56033c758b72fe0a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jan 2015 15:58:00 -0800 Subject: [PATCH 40/71] Emit comments in a lot more places. --- src/compiler/emitter.ts | 126 +++++++++------ .../reference/arrowFunctionContexts.js | 2 + .../reference/augmentedTypesEnum2.js | 2 +- .../reference/augmentedTypesInterface.js | 2 +- .../reference/augmentedTypesModules.js | 6 +- .../reference/augmentedTypesModules2.js | 8 +- .../commaOperatorOtherValidOperation.js | 1 + .../reference/commentsOnObjectLiteral1.js | 6 +- tests/baselines/reference/commentsVarDecl.js | 4 +- .../reference/constDeclarations-scopes.js | 3 + .../reference/constDeclarations-scopes2.js | 1 + .../constDeclarations-validContexts.js | 3 + .../baselines/reference/escapedIdentifiers.js | 9 +- .../forStatementsMultipleInvalidDecl.js | 1 + .../reference/genericChainedCalls.js | 3 +- ...icitAnyDeclareFunctionWithoutFormalType.js | 8 +- ...itAnyDeclareVariablesWithoutTypeAndInit.js | 2 +- .../baselines/reference/implicitAnyInCatch.js | 1 + .../reference/letDeclarations-scopes.js | 3 + .../letDeclarations-validContexts.js | 4 + .../overEagerReturnTypeSpecialization.js | 6 +- .../reference/parserSbp_7.9_A9_T3.js | 7 + tests/baselines/reference/promiseChaining.js | 2 +- tests/baselines/reference/promiseChaining1.js | 2 +- .../reference/recursiveInitializer.js | 4 +- .../reference/scopingInCatchBlocks.js | 4 +- .../reference/sourceMapValidationClasses.js | 5 +- .../sourceMapValidationClasses.js.map | 2 +- .../sourceMapValidationClasses.sourcemap.txt | 153 ++++++++++-------- .../reference/switchAssignmentCompat.js | 2 +- .../switchCasesExpressionTypeMismatch.js | 9 +- tests/baselines/reference/throwStatements.js | 1 + .../typeGuardsInConditionalExpression.js | 41 +++-- .../typeGuardsInFunctionAndModuleBlock.js | 18 ++- .../reference/typeGuardsInIfStatement.js | 14 +- ...ypeGuardsInRightOperandOfAndAndOperator.js | 21 ++- .../typeGuardsInRightOperandOfOrOrOperator.js | 21 ++- ...eclaratorResolvedDuringContextualTyping.js | 8 +- 38 files changed, 328 insertions(+), 187 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 47f75dcf8ad..e6a44148fe2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2403,28 +2403,20 @@ module ts { } function emitMethod(node: MethodDeclaration) { - if (!isObjectLiteralMethod(node)) { - return; - } - emitLeadingComments(node); emit(node.name); if (languageVersion < ScriptTarget.ES6) { write(": function "); } emitSignatureAndBody(node); - emitTrailingComments(node); } function emitPropertyAssignment(node: PropertyDeclaration) { - emitLeadingComments(node); emit(node.name); write(": "); emit(node.initializer); - emitTrailingComments(node); } function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { - emitLeadingComments(node); emit(node.name); // If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example: // module m { @@ -2441,7 +2433,6 @@ module ts { // Short-hand, { x }, is equivalent of normal form { x: x } emitExpressionIdentifier(node.name); } - emitTrailingComments(node); } function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean { @@ -2661,14 +2652,11 @@ module ts { } function emitExpressionStatement(node: ExpressionStatement) { - emitLeadingComments(node); emitParenthesized(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction); write(";"); - emitTrailingComments(node); } function emitIfStatement(node: IfStatement) { - emitLeadingComments(node); var endPos = emitToken(SyntaxKind.IfKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); @@ -2686,7 +2674,6 @@ module ts { emitEmbeddedStatement(node.elseStatement); } } - emitTrailingComments(node); } function emitDoStatement(node: DoStatement) { @@ -2774,11 +2761,9 @@ module ts { } function emitReturnStatement(node: ReturnStatement) { - emitLeadingComments(node); emitToken(SyntaxKind.ReturnKeyword, node.pos); emitOptional(" ", node.expression); write(";"); - emitTrailingComments(node); } function emitWithStatement(node: WhileStatement) { @@ -3102,7 +3087,6 @@ module ts { } function emitVariableDeclaration(node: VariableDeclaration) { - emitLeadingComments(node); if (isBindingPattern(node.name)) { if (languageVersion < ScriptTarget.ES6) { emitDestructuring(node); @@ -3116,11 +3100,9 @@ module ts { emitModuleMemberName(node); emitOptional(" = ", node.initializer); } - emitTrailingComments(node); } function emitVariableStatement(node: VariableStatement) { - emitLeadingComments(node); if (!(node.flags & NodeFlags.Export)) { if (isLet(node.declarationList)) { write("let "); @@ -3134,11 +3116,9 @@ module ts { } emitCommaList(node.declarationList.declarations); write(";"); - emitTrailingComments(node); } function emitParameter(node: ParameterDeclaration) { - emitLeadingComments(node); if (languageVersion < ScriptTarget.ES6) { if (isBindingPattern(node.name)) { var name = createTempVariable(node); @@ -3159,7 +3139,6 @@ module ts { emit(node.name); emitOptional(" = ", node.initializer); } - emitTrailingComments(node); } function emitDefaultValueAssignments(node: FunctionLikeDeclaration) { @@ -3232,11 +3211,9 @@ module ts { } function emitAccessor(node: AccessorDeclaration) { - emitLeadingComments(node); write(node.kind === SyntaxKind.GetAccessor ? "get " : "set "); emit(node.name); emitSignatureAndBody(node); - emitTrailingComments(node); } function emitFunctionDeclaration(node: FunctionLikeDeclaration) { @@ -3306,7 +3283,8 @@ module ts { write(" "); emitStart(node.body); write("return "); - emitNode(node.body); + // Don't emit comments on this body. We'll have already taken care of it above. + emitNode(node.body, /*disableComments:*/ true); emitEnd(node.body); write(";"); emitTempDeclarations(/*newLine*/ false); @@ -3323,7 +3301,7 @@ module ts { writeLine(); emitLeadingComments(node.body); write("return "); - emit(node.body); + emit(node.body, /*disableComments:*/ true); write(";"); emitTrailingComments(node.body); } @@ -3504,7 +3482,6 @@ module ts { } function emitClassDeclaration(node: ClassDeclaration) { - emitLeadingComments(node); write("var "); emit(node.name); write(" = (function ("); @@ -3554,7 +3531,6 @@ module ts { emitEnd(node); write(";"); } - emitTrailingComments(node); function emitConstructorOfClass() { var saveTempCount = tempCount; @@ -3633,13 +3609,17 @@ module ts { emitPinnedOrTripleSlashComments(node); } + function shouldEmitEnumDeclaration(node: EnumDeclaration) { + var isConstEnum = isConst(node); + return !isConstEnum || compilerOptions.preserveConstEnums; + } + function emitEnumDeclaration(node: EnumDeclaration) { // const enums are completely erased during compilation. - var isConstEnum = isConst(node); - if (isConstEnum && !compilerOptions.preserveConstEnums) { + if (!shouldEmitEnumDeclaration(node)) { return; } - emitLeadingComments(node); + if (!(node.flags & NodeFlags.Export)) { emitStart(node); write("var "); @@ -3677,12 +3657,10 @@ module ts { emitEnd(node); write(";"); } - emitTrailingComments(node); } function emitEnumMember(node: EnumMember) { var enumParent = node.parent; - emitLeadingComments(node); emitStart(node); write(resolver.getLocalNameOfContainer(enumParent)); write("["); @@ -3700,7 +3678,6 @@ module ts { emitExpressionForPropertyName(node.name); emitEnd(node); write(";"); - emitTrailingComments(node); } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration { @@ -3710,14 +3687,18 @@ module ts { } } + function shouldEnumModuleDeclaration(node: ModuleDeclaration) { + return isInstantiatedModule(node, compilerOptions.preserveConstEnums); + } + function emitModuleDeclaration(node: ModuleDeclaration) { // Emit only if this module is non-ambient. - var shouldEmit = isInstantiatedModule(node, compilerOptions.preserveConstEnums); + var shouldEmit = shouldEnumModuleDeclaration(node); if (!shouldEmit) { return emitPinnedOrTripleSlashComments(node); } - emitLeadingComments(node); + emitStart(node); write("var "); emit(node.name); @@ -3762,7 +3743,6 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - emitTrailingComments(node); } function emitImportDeclaration(node: ImportDeclaration) { @@ -3952,7 +3932,7 @@ module ts { emitLeadingComments(node.endOfFileToken); } - function emitNode(node: Node): void { + function emitNode(node: Node, disableComments?:boolean): void { if (!node) { return; } @@ -3960,6 +3940,46 @@ module ts { if (node.flags & NodeFlags.Ambient) { return emitPinnedOrTripleSlashComments(node); } + + var emitComments = !disableComments && shouldEmitLeadingAndTrailingComments(node); + if (emitComments) { + emitLeadingComments(node); + } + + emitJavaScriptWorker(node); + + if (emitComments) { + emitTrailingComments(node); + } + } + + function shouldEmitLeadingAndTrailingComments(node: Node) { + switch (node.kind) { + // All of thes entities are emitted in a specialized fashion. As such, we allow + // the specilized methods for each to handle the comments on the nodes. + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.ExportAssignment: + return false; + + case SyntaxKind.ModuleDeclaration: + // Only emit the leading/trailing comments for a module if we're actually + // emitting the module as well. + return shouldEnumModuleDeclaration(node); + + case SyntaxKind.EnumDeclaration: + // Only emit the leading/trailing comments for an enum if we're actually + // emitting the module as well. + return shouldEmitEnumDeclaration(node); + } + + // Emit comments for everything else. + return true; + } + + function emitJavaScriptWorker(node: Node) { // Check if the node can be emitted regardless of the ScriptTarget switch (node.kind) { case SyntaxKind.Identifier: @@ -4128,17 +4148,19 @@ module ts { function getLeadingCommentsToEmit(node: Node) { // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments - if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { - var leadingComments: CommentRange[]; - if (hasDetachedComments(node.pos)) { - // get comments without detached comments - leadingComments = getLeadingCommentsWithoutDetachedComments(); + if (node.parent) { + if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { + var leadingComments: CommentRange[]; + if (hasDetachedComments(node.pos)) { + // get comments without detached comments + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + // get the leading comments from the node + leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile); + } + return leadingComments; } - else { - // get the leading comments from the node - leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile); - } - return leadingComments; } } @@ -4151,10 +4173,12 @@ module ts { function emitTrailingDeclarationComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { - var trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); + if (node.parent) { + if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { + var trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end); + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); + } } } diff --git a/tests/baselines/reference/arrowFunctionContexts.js b/tests/baselines/reference/arrowFunctionContexts.js index abb8fd0ab7a..cdf902a6c37 100644 --- a/tests/baselines/reference/arrowFunctionContexts.js +++ b/tests/baselines/reference/arrowFunctionContexts.js @@ -103,6 +103,7 @@ var __extends = this.__extends || function (d, b) { __.prototype = b.prototype; d.prototype = new __(); }; +// Arrow function used in with statement with (window) { var p = function () { return this; }; } @@ -142,6 +143,7 @@ var M; // Repeat above for module members that are functions? (necessary to redo all of them?) var M2; (function (M2) { + // Arrow function used in with statement with (window) { var p = function () { return this; }; } diff --git a/tests/baselines/reference/augmentedTypesEnum2.js b/tests/baselines/reference/augmentedTypesEnum2.js index 434e508f14c..f0c86e5640b 100644 --- a/tests/baselines/reference/augmentedTypesEnum2.js +++ b/tests/baselines/reference/augmentedTypesEnum2.js @@ -31,7 +31,7 @@ var e2; (function (e2) { e2[e2["One"] = 0] = "One"; })(e2 || (e2 = {})); -; +; // error var e2 = (function () { function e2() { } diff --git a/tests/baselines/reference/augmentedTypesInterface.js b/tests/baselines/reference/augmentedTypesInterface.js index a5039f8b1d0..e28864fd547 100644 --- a/tests/baselines/reference/augmentedTypesInterface.js +++ b/tests/baselines/reference/augmentedTypesInterface.js @@ -47,5 +47,5 @@ var i3; (function (i3) { i3[i3["One"] = 0] = "One"; })(i3 || (i3 = {})); -; +; // error //import i4 = require(''); // error diff --git a/tests/baselines/reference/augmentedTypesModules.js b/tests/baselines/reference/augmentedTypesModules.js index a9bff3fa74b..3b7544996a1 100644 --- a/tests/baselines/reference/augmentedTypesModules.js +++ b/tests/baselines/reference/augmentedTypesModules.js @@ -124,21 +124,21 @@ var m1d; var m1d = 1; // error function m2() { } -; +; // ok since the module is not instantiated var m2a; (function (m2a) { var y = 2; })(m2a || (m2a = {})); function m2a() { } -; +; // error since the module is instantiated var m2b; (function (m2b) { m2b.y = 2; })(m2b || (m2b = {})); function m2b() { } -; +; // error since the module is instantiated // should be errors to have function first function m2c() { } diff --git a/tests/baselines/reference/augmentedTypesModules2.js b/tests/baselines/reference/augmentedTypesModules2.js index d1551b6244e..70fd31f03e0 100644 --- a/tests/baselines/reference/augmentedTypesModules2.js +++ b/tests/baselines/reference/augmentedTypesModules2.js @@ -31,21 +31,21 @@ module m2g { export class C { foo() { } } } //// [augmentedTypesModules2.js] function m2() { } -; +; // ok since the module is not instantiated var m2a; (function (m2a) { var y = 2; })(m2a || (m2a = {})); function m2a() { } -; +; // error since the module is instantiated var m2b; (function (m2b) { m2b.y = 2; })(m2b || (m2b = {})); function m2b() { } -; +; // error since the module is instantiated function m2c() { } ; @@ -59,7 +59,7 @@ var m2cc; })(m2cc || (m2cc = {})); function m2cc() { } -; +; // error to have module first function m2f() { } ; diff --git a/tests/baselines/reference/commaOperatorOtherValidOperation.js b/tests/baselines/reference/commaOperatorOtherValidOperation.js index 4d556472adc..383b7c5058e 100644 --- a/tests/baselines/reference/commaOperatorOtherValidOperation.js +++ b/tests/baselines/reference/commaOperatorOtherValidOperation.js @@ -22,6 +22,7 @@ function foo1() //// [commaOperatorOtherValidOperation.js] +//Comma operator in for loop for (var i = 0, j = 10; i < j; i++, j--) { } //Comma operator in fuction arguments and return diff --git a/tests/baselines/reference/commentsOnObjectLiteral1.js b/tests/baselines/reference/commentsOnObjectLiteral1.js index 1c47ed68d8d..feb6a521b8d 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral1.js +++ b/tests/baselines/reference/commentsOnObjectLiteral1.js @@ -8,4 +8,8 @@ var Person = makeClass( ); //// [commentsOnObjectLiteral1.js] -var Person = makeClass({}); +var Person = makeClass( +/** + @scope Person +*/ +{}); diff --git a/tests/baselines/reference/commentsVarDecl.js b/tests/baselines/reference/commentsVarDecl.js index 5105e03879d..5ff2a3c1c6a 100644 --- a/tests/baselines/reference/commentsVarDecl.js +++ b/tests/baselines/reference/commentsVarDecl.js @@ -66,7 +66,9 @@ var n = 30; /** var deckaration with comment on type as well*/ var y = 20; /// var deckaration with comment on type as well -var yy = 20; +var yy = +/// value comment +20; /** comment2 */ var z = function (x, y) { return x + y; }; var z2; diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js index aa1d59aee81..b1be921849c 100644 --- a/tests/baselines/reference/constDeclarations-scopes.js +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -189,6 +189,7 @@ while (false) { label2: label3: label4: const c = 0; n = c; } +// Try/catch/finally try { const c = 0; n = c; @@ -201,12 +202,14 @@ finally { const c = 0; n = c; } +// Switch switch (0) { case 0: const c = 0; n = c; break; } +// blocks { const c = 0; n = c; diff --git a/tests/baselines/reference/constDeclarations-scopes2.js b/tests/baselines/reference/constDeclarations-scopes2.js index 1d0f252ab4f..d407cf56801 100644 --- a/tests/baselines/reference/constDeclarations-scopes2.js +++ b/tests/baselines/reference/constDeclarations-scopes2.js @@ -20,6 +20,7 @@ for (const c = 0; c < 10; n = c ) { const c = "string"; var n; var b; +// for scope for (const c = 0; c < 10; n = c) { // for block const c = false; diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js index 8be43633d70..8238f69ca15 100644 --- a/tests/baselines/reference/constDeclarations-validContexts.js +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -153,6 +153,7 @@ if (true) { while (false) { label2: label3: label4: const c9 = 0; } +// Try/catch/finally try { const c10 = 0; } @@ -162,6 +163,7 @@ catch (e) { finally { const c12 = 0; } +// Switch switch (0) { case 0: const c13 = 0; @@ -170,6 +172,7 @@ switch (0) { const c14 = 0; break; } +// blocks { const c15 = 0; { diff --git a/tests/baselines/reference/escapedIdentifiers.js b/tests/baselines/reference/escapedIdentifiers.js index cabeb7f1d5d..5de505e4cb7 100644 --- a/tests/baselines/reference/escapedIdentifiers.js +++ b/tests/baselines/reference/escapedIdentifiers.js @@ -204,19 +204,20 @@ constructorTestObject.arg\u0031 = 1; constructorTestObject.arg2 = 'string'; constructorTestObject.arg\u0033 = true; constructorTestObject.arg4 = 2; +// Lables l\u0061bel1: while (false) { while (false) - continue label1; + continue label1; // it will go to next iteration of outer loop } label2: while (false) { while (false) - continue l\u0061bel2; + continue l\u0061bel2; // it will go to next iteration of outer loop } label3: while (false) { while (false) - continue label3; + continue label3; // it will go to next iteration of outer loop } l\u0061bel4: while (false) { while (false) - continue l\u0061bel4; + continue l\u0061bel4; // it will go to next iteration of outer loop } diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.js b/tests/baselines/reference/forStatementsMultipleInvalidDecl.js index 73db1ff3c7d..4dbfe7e62bc 100644 --- a/tests/baselines/reference/forStatementsMultipleInvalidDecl.js +++ b/tests/baselines/reference/forStatementsMultipleInvalidDecl.js @@ -93,6 +93,7 @@ var M; } M.F2 = F2; })(M || (M = {})); +// all of these are errors for (var a;;) { } for (var a = 1;;) { diff --git a/tests/baselines/reference/genericChainedCalls.js b/tests/baselines/reference/genericChainedCalls.js index 618d34cbc5a..71d83a906bf 100644 --- a/tests/baselines/reference/genericChainedCalls.js +++ b/tests/baselines/reference/genericChainedCalls.js @@ -15,7 +15,8 @@ var s3 = s2.func(num => num.toString()) //// [genericChainedCalls.js] -var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }).func(function (num) { return num.toString(); }); +var r1 = v1.func(function (num) { return num.toString(); }).func(function (str) { return str.length; }) // error, number doesn't have a length +.func(function (num) { return num.toString(); }); var s1 = v1.func(function (num) { return num.toString(); }); var s2 = s1.func(function (str) { return str.length; }); // should also error var s3 = s2.func(function (num) { return num.toString(); }); diff --git a/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js b/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js index 72d68da2287..6332f444487 100644 --- a/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js +++ b/tests/baselines/reference/implicitAnyDeclareFunctionWithoutFormalType.js @@ -18,22 +18,22 @@ function foo(x) { ; function bar(x, y) { } -; +; // error at "y"; no error at "x" function func2(a, b, c) { } -; +; // error at "a,b,c" function func3() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } } -; +; // error at "args" function func4(z, w) { if (z === void 0) { z = null; } if (w === void 0) { w = undefined; } } -; +; // error at "z,w" // these shouldn't be errors function noError1(x, y) { if (x === void 0) { x = 3; } diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js index 95b617d79ee..ae09bf2e40e 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js @@ -16,7 +16,7 @@ var x1: any; var y1 = new x1; var x; // error at "x" function func(k) { } -; +; //error at "k" func(x); // this shouldn't be an error var bar = 3; diff --git a/tests/baselines/reference/implicitAnyInCatch.js b/tests/baselines/reference/implicitAnyInCatch.js index 9952c7ca327..29a2e03a130 100644 --- a/tests/baselines/reference/implicitAnyInCatch.js +++ b/tests/baselines/reference/implicitAnyInCatch.js @@ -15,6 +15,7 @@ class C { //// [implicitAnyInCatch.js] +// this should not be an error try { } catch (error) { diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index d0f70693d7c..dbe18311eff 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -205,6 +205,7 @@ for (let l = 0; n = l; l++) { } for (let l in {}) { } +// Try/catch/finally try { let l = 0; n = l; @@ -217,12 +218,14 @@ finally { let l = 0; n = l; } +// Switch switch (0) { case 0: let l = 0; n = l; break; } +// blocks { let l = 0; n = l; diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index fe9ed903bf5..ee821794b12 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -173,6 +173,7 @@ if (true) { while (false) { label2: label3: label4: let l9 = 0; } +// Try/catch/finally try { let l10 = 0; } @@ -182,6 +183,7 @@ catch (e) { finally { let l12 = 0; } +// Switch switch (0) { case 0: let l13 = 0; @@ -190,6 +192,7 @@ switch (0) { let l14 = 0; break; } +// blocks { let l15 = 0; { @@ -247,6 +250,7 @@ var o = { let l29 = 0; } }; +// labels label: let l30 = 0; { label2: let l31 = 0; diff --git a/tests/baselines/reference/overEagerReturnTypeSpecialization.js b/tests/baselines/reference/overEagerReturnTypeSpecialization.js index 18c61a2aa78..67d2005eca9 100644 --- a/tests/baselines/reference/overEagerReturnTypeSpecialization.js +++ b/tests/baselines/reference/overEagerReturnTypeSpecialization.js @@ -16,5 +16,7 @@ var r2: I1 = v1.func(num => num.toString()) // Correctly returns an I1 +.func(function (str) { return str.length; }); // should error +var r2 = v1.func(function (num) { return num.toString(); }) // Correctly returns an I1 +.func(function (str) { return str.length; }); // should be ok diff --git a/tests/baselines/reference/parserSbp_7.9_A9_T3.js b/tests/baselines/reference/parserSbp_7.9_A9_T3.js index 60c8c4ad6eb..192ca617211 100644 --- a/tests/baselines/reference/parserSbp_7.9_A9_T3.js +++ b/tests/baselines/reference/parserSbp_7.9_A9_T3.js @@ -19,6 +19,13 @@ do { //// [parserSbp_7.9_A9_T3.js] // Copyright 2009 the Sputnik authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. +/** + * Check Do-While Statement for automatic semicolon insertion + * + * @path bestPractice/Sbp_7.9_A9_T3.js + * @description Execute do { \n ; \n }while(false) true + */ +//CHECK#1 do { ; } while (false); diff --git a/tests/baselines/reference/promiseChaining.js b/tests/baselines/reference/promiseChaining.js index 20961542b22..ce15e2d44c1 100644 --- a/tests/baselines/reference/promiseChaining.js +++ b/tests/baselines/reference/promiseChaining.js @@ -19,7 +19,7 @@ var Chain = (function () { Chain.prototype.then = function (cb) { var result = cb(this.value); // should get a fresh type parameter which each then call - var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // No error + var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*string*/.then(function (x) { return x.length; }); // No error return new Chain(result); }; return Chain; diff --git a/tests/baselines/reference/promiseChaining1.js b/tests/baselines/reference/promiseChaining1.js index ee79d3268ba..001f1ffc1a6 100644 --- a/tests/baselines/reference/promiseChaining1.js +++ b/tests/baselines/reference/promiseChaining1.js @@ -19,7 +19,7 @@ var Chain2 = (function () { Chain2.prototype.then = function (cb) { var result = cb(this.value); // should get a fresh type parameter which each then call - var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function + var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*Function*/.then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function return new Chain2(result); }; return Chain2; diff --git a/tests/baselines/reference/recursiveInitializer.js b/tests/baselines/reference/recursiveInitializer.js index c7a723c35d7..82abf2b50af 100644 --- a/tests/baselines/reference/recursiveInitializer.js +++ b/tests/baselines/reference/recursiveInitializer.js @@ -23,10 +23,10 @@ var f = (x: string) => f(x); // number unless otherwise specified var n1 = n1++; var n2 = n2 + n2; -var n3 = n3 + n3; +var n3 /* any */ = n3 + n3; // string unless otherwise specified var s1 = s1 + ''; -var s2 = s2 + s2; +var s2 /* any */ = s2 + s2; var s3 = s3 + s3; var s4 = '' + s4; // boolean unless otherwise specified diff --git a/tests/baselines/reference/scopingInCatchBlocks.js b/tests/baselines/reference/scopingInCatchBlocks.js index 8590173147c..2d3ca7098b5 100644 --- a/tests/baselines/reference/scopingInCatchBlocks.js +++ b/tests/baselines/reference/scopingInCatchBlocks.js @@ -19,9 +19,9 @@ catch (ex1) { try { } catch (ex1) { -} +} // should not error try { } catch (ex1) { -} +} // should not error var x = ex1; // should error diff --git a/tests/baselines/reference/sourceMapValidationClasses.js b/tests/baselines/reference/sourceMapValidationClasses.js index 96724f7c3c7..e3b705bc4b0 100644 --- a/tests/baselines/reference/sourceMapValidationClasses.js +++ b/tests/baselines/reference/sourceMapValidationClasses.js @@ -57,9 +57,9 @@ var Foo; var greeter = new Greeter("Hello, world!"); var str = greeter.greet(); function foo2(greeting) { - var restGreetings = []; + var restGreetings /* more greeting */ = []; for (var _i = 1; _i < arguments.length; _i++) { - restGreetings[_i - 1] = arguments[_i]; + restGreetings /* more greeting */[_i - 1] = arguments[_i]; } var greeters = []; /* inline block comment */ greeters[0] = new Greeter(greeting); @@ -69,6 +69,7 @@ var Foo; return greeters; } var b = foo2("Hello", "World", "!"); + // This is simple signle line comment for (var j = 0; j < b.length; j++) { b[j].greet(); } diff --git a/tests/baselines/reference/sourceMapValidationClasses.js.map b/tests/baselines/reference/sourceMapValidationClasses.js.map index 2a1b381e116..68ded9631e2 100644 --- a/tests/baselines/reference/sourceMapValidationClasses.js.map +++ b/tests/baselines/reference/sourceMapValidationClasses.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationClasses.js.map] -{"version":3,"file":"sourceMapValidationClasses.js","sourceRoot":"","sources":["sourceMapValidationClasses.ts"],"names":["Foo","Foo.Bar","Foo.Bar.Greeter","Foo.Bar.Greeter.constructor","Foo.Bar.Greeter.greet","Foo.Bar.foo","Foo.Bar.foo2"],"mappings":"AAAA,IAAO,GAAG,CAmCT;AAnCD,WAAO,GAAG;IAACA,IAAAA,GAAGA,CAmCbA;IAnCUA,WAAAA,GAAGA,EAACA,CAACA;QACZC,YAAYA,CAACA;QAEbA,IAAMA,OAAOA;YACTC,SADEA,OAAOA,CACUA,QAAgBA;gBAAhBC,aAAQA,GAARA,QAAQA,CAAQA;YACnCA,CAACA;YAEDD,uBAAKA,GAALA;gBACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;YAC5CA,CAACA;YACLF,cAACA;QAADA,CAACA,AAPDD,IAOCA;QAGDA,SAASA,GAAGA,CAACA,QAAgBA;YACzBI,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;QACjCA,CAACA;QAEDJ,IAAIA,OAAOA,GAAGA,IAAIA,OAAOA,CAACA,eAAeA,CAACA,CAACA;QAC3CA,IAAIA,GAAGA,GAAGA,OAAOA,CAACA,KAAKA,EAAEA,CAACA;QAE1BA,SAASA,IAAIA,CAACA,QAAgBA;YAAEK,uBAA8CA;iBAA9CA,WAA8CA,CAA9CA,sBAA8CA,CAA9CA,IAA8CA;gBAA9CA,sCAA8CA;;YAC1EA,IAAIA,QAAQA,GAAcA,EAAEA,EAAEA,0BAA0BA,AAA3BA;YAC7BA,QAAQA,CAACA,CAACA,CAACA,GAAGA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;YACpCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,aAAaA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;gBAC5CA,QAAQA,CAACA,IAAIA,CAACA,IAAIA,OAAOA,CAACA,aAAaA,CAACA,CAACA,CAACA,CAACA,CAACA,CAACA;YACjDA,CAACA;YAEDA,MAAMA,CAACA,QAAQA,CAACA;QACpBA,CAACA;QAEDL,IAAIA,CAACA,GAAGA,IAAIA,CAACA,OAAOA,EAAEA,OAAOA,EAAEA,GAAGA,CAACA,CAACA;QAEpCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,CAACA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;YAChCA,CAACA,CAACA,CAACA,CAACA,CAACA,KAAKA,EAAEA,CAACA;QACjBA,CAACA;IACLA,CAACA,EAnCUD,GAAGA,GAAHA,OAAGA,KAAHA,OAAGA,QAmCbA;AAADA,CAACA,EAnCM,GAAG,KAAH,GAAG,QAmCT"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationClasses.js","sourceRoot":"","sources":["sourceMapValidationClasses.ts"],"names":["Foo","Foo.Bar","Foo.Bar.Greeter","Foo.Bar.Greeter.constructor","Foo.Bar.Greeter.greet","Foo.Bar.foo","Foo.Bar.foo2"],"mappings":"AAAA,IAAO,GAAG,CAmCT;AAnCD,WAAO,GAAG;IAACA,IAAAA,GAAGA,CAmCbA;IAnCUA,WAAAA,GAAGA,EAACA,CAACA;QACZC,YAAYA,CAACA;QAEbA,IAAMA,OAAOA;YACTC,SADEA,OAAOA,CACUA,QAAgBA;gBAAhBC,aAAQA,GAARA,QAAQA,CAAQA;YACnCA,CAACA;YAEDD,uBAAKA,GAALA;gBACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;YAC5CA,CAACA;YACLF,cAACA;QAADA,CAACA,AAPDD,IAOCA;QAGDA,SAASA,GAAGA,CAACA,QAAgBA;YACzBI,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;QACjCA,CAACA;QAEDJ,IAAIA,OAAOA,GAAGA,IAAIA,OAAOA,CAACA,eAAeA,CAACA,CAACA;QAC3CA,IAAIA,GAAGA,GAAGA,OAAOA,CAACA,KAAKA,EAAEA,CAACA;QAE1BA,SAASA,IAAIA,CAACA,QAAgBA;YAAEK,kBAAiBA,mBAAmBA,MAAUA;iBAA9CA,WAA8CA,CAA9CA,sBAA8CA,CAA9CA,IAA8CA;gBAA9CA,cAAiBA,mBAAmBA,yBAAUA;;YAC1EA,IAAIA,QAAQA,GAAcA,EAAEA,EAAEA,0BAA0BA,AAA3BA;YAC7BA,QAAQA,CAACA,CAACA,CAACA,GAAGA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,CAACA;YACpCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,aAAaA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;gBAC5CA,QAAQA,CAACA,IAAIA,CAACA,IAAIA,OAAOA,CAACA,aAAaA,CAACA,CAACA,CAACA,CAACA,CAACA,CAACA;YACjDA,CAACA;YAEDA,MAAMA,CAACA,QAAQA,CAACA;QACpBA,CAACA;QAEDL,IAAIA,CAACA,GAAGA,IAAIA,CAACA,OAAOA,EAAEA,OAAOA,EAAEA,GAAGA,CAACA,CAACA;QAEpCA,AADAA,qCAAqCA;QACrCA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,CAACA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;YAChCA,CAACA,CAACA,CAACA,CAACA,CAACA,KAAKA,EAAEA,CAACA;QACjBA,CAACA;IACLA,CAACA,EAnCUD,GAAGA,GAAHA,OAAGA,KAAHA,OAAGA,QAmCbA;AAADA,CAACA,EAnCM,GAAG,KAAH,GAAG,QAmCT"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClasses.sourcemap.txt b/tests/baselines/reference/sourceMapValidationClasses.sourcemap.txt index d82ac6c3e05..6cd77b696ff 100644 --- a/tests/baselines/reference/sourceMapValidationClasses.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationClasses.sourcemap.txt @@ -433,7 +433,7 @@ sourceFile:sourceMapValidationClasses.ts 3 > ^^^^ 4 > ^ 5 > ^^^^^^^^ -6 > ^^^^^^-> +6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > > @@ -447,14 +447,20 @@ sourceFile:sourceMapValidationClasses.ts 4 >Emitted(20, 23) Source(21, 19) + SourceIndex(0) name (Foo.Bar) 5 >Emitted(20, 31) Source(21, 35) + SourceIndex(0) name (Foo.Bar) --- ->>> var restGreetings = []; +>>> var restGreetings /* more greeting */ = []; 1->^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^ +4 > ^^^^^^ +5 > ^^^^^-> 1->, -2 > ...restGreetings /* more greeting */: string[] +2 > ...restGreetings +3 > /* more greeting */ +4 > : string[] 1->Emitted(21, 13) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2) -2 >Emitted(21, 36) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2) +2 >Emitted(21, 31) Source(21, 54) + SourceIndex(0) name (Foo.Bar.foo2) +3 >Emitted(21, 50) Source(21, 73) + SourceIndex(0) name (Foo.Bar.foo2) +4 >Emitted(21, 56) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2) --- >>> for (var _i = 1; _i < arguments.length; _i++) { 1->^^^^^^^^^^^^^^^^^ @@ -463,6 +469,7 @@ sourceFile:sourceMapValidationClasses.ts 4 > ^^^^^^^^^^^^^^^^^^^^^^ 5 > ^ 6 > ^^^^ +7 > ^^^^^^^^^^^^^^^^^^^-> 1-> 2 > ...restGreetings /* more greeting */: string[] 3 > @@ -476,13 +483,19 @@ sourceFile:sourceMapValidationClasses.ts 5 >Emitted(22, 53) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2) 6 >Emitted(22, 57) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2) --- ->>> restGreetings[_i - 1] = arguments[_i]; -1 >^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -1 > -2 > ...restGreetings /* more greeting */: string[] -1 >Emitted(23, 17) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2) -2 >Emitted(23, 55) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2) +>>> restGreetings /* more greeting */[_i - 1] = arguments[_i]; +1->^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> +2 > ...restGreetings +3 > /* more greeting */ +4 > : string[] +1->Emitted(23, 17) Source(21, 37) + SourceIndex(0) name (Foo.Bar.foo2) +2 >Emitted(23, 31) Source(21, 54) + SourceIndex(0) name (Foo.Bar.foo2) +3 >Emitted(23, 50) Source(21, 73) + SourceIndex(0) name (Foo.Bar.foo2) +4 >Emitted(23, 75) Source(21, 83) + SourceIndex(0) name (Foo.Bar.foo2) --- >>> } >>> var greeters = []; /* inline block comment */ @@ -717,7 +730,7 @@ sourceFile:sourceMapValidationClasses.ts 11> ^^^ 12> ^ 13> ^ -14> ^-> +14> ^^-> 1-> > > @@ -747,8 +760,21 @@ sourceFile:sourceMapValidationClasses.ts 12>Emitted(32, 44) Source(31, 40) + SourceIndex(0) name (Foo.Bar) 13>Emitted(32, 45) Source(31, 41) + SourceIndex(0) name (Foo.Bar) --- ->>> for (var j = 0; j < b.length; j++) { +>>> // This is simple signle line comment 1->^^^^^^^^ +2 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > // This is simple signle line comment + > +2 > +3 > // This is simple signle line comment +1->Emitted(33, 9) Source(33, 5) + SourceIndex(0) name (Foo.Bar) +2 >Emitted(33, 9) Source(32, 5) + SourceIndex(0) name (Foo.Bar) +3 >Emitted(33, 46) Source(32, 42) + SourceIndex(0) name (Foo.Bar) +--- +>>> for (var j = 0; j < b.length; j++) { +1 >^^^^^^^^ 2 > ^^^ 3 > ^ 4 > ^ @@ -768,8 +794,7 @@ sourceFile:sourceMapValidationClasses.ts 18> ^^ 19> ^^ 20> ^ -1-> - > // This is simple signle line comment +1 > > 2 > for 3 > @@ -790,26 +815,26 @@ sourceFile:sourceMapValidationClasses.ts 18> ++ 19> ) 20> { -1->Emitted(33, 9) Source(33, 5) + SourceIndex(0) name (Foo.Bar) -2 >Emitted(33, 12) Source(33, 8) + SourceIndex(0) name (Foo.Bar) -3 >Emitted(33, 13) Source(33, 9) + SourceIndex(0) name (Foo.Bar) -4 >Emitted(33, 14) Source(33, 10) + SourceIndex(0) name (Foo.Bar) -5 >Emitted(33, 17) Source(33, 13) + SourceIndex(0) name (Foo.Bar) -6 >Emitted(33, 18) Source(33, 14) + SourceIndex(0) name (Foo.Bar) -7 >Emitted(33, 19) Source(33, 15) + SourceIndex(0) name (Foo.Bar) -8 >Emitted(33, 22) Source(33, 18) + SourceIndex(0) name (Foo.Bar) -9 >Emitted(33, 23) Source(33, 19) + SourceIndex(0) name (Foo.Bar) -10>Emitted(33, 25) Source(33, 21) + SourceIndex(0) name (Foo.Bar) -11>Emitted(33, 26) Source(33, 22) + SourceIndex(0) name (Foo.Bar) -12>Emitted(33, 29) Source(33, 25) + SourceIndex(0) name (Foo.Bar) -13>Emitted(33, 30) Source(33, 26) + SourceIndex(0) name (Foo.Bar) -14>Emitted(33, 31) Source(33, 27) + SourceIndex(0) name (Foo.Bar) -15>Emitted(33, 37) Source(33, 33) + SourceIndex(0) name (Foo.Bar) -16>Emitted(33, 39) Source(33, 35) + SourceIndex(0) name (Foo.Bar) -17>Emitted(33, 40) Source(33, 36) + SourceIndex(0) name (Foo.Bar) -18>Emitted(33, 42) Source(33, 38) + SourceIndex(0) name (Foo.Bar) -19>Emitted(33, 44) Source(33, 40) + SourceIndex(0) name (Foo.Bar) -20>Emitted(33, 45) Source(33, 41) + SourceIndex(0) name (Foo.Bar) +1 >Emitted(34, 9) Source(33, 5) + SourceIndex(0) name (Foo.Bar) +2 >Emitted(34, 12) Source(33, 8) + SourceIndex(0) name (Foo.Bar) +3 >Emitted(34, 13) Source(33, 9) + SourceIndex(0) name (Foo.Bar) +4 >Emitted(34, 14) Source(33, 10) + SourceIndex(0) name (Foo.Bar) +5 >Emitted(34, 17) Source(33, 13) + SourceIndex(0) name (Foo.Bar) +6 >Emitted(34, 18) Source(33, 14) + SourceIndex(0) name (Foo.Bar) +7 >Emitted(34, 19) Source(33, 15) + SourceIndex(0) name (Foo.Bar) +8 >Emitted(34, 22) Source(33, 18) + SourceIndex(0) name (Foo.Bar) +9 >Emitted(34, 23) Source(33, 19) + SourceIndex(0) name (Foo.Bar) +10>Emitted(34, 25) Source(33, 21) + SourceIndex(0) name (Foo.Bar) +11>Emitted(34, 26) Source(33, 22) + SourceIndex(0) name (Foo.Bar) +12>Emitted(34, 29) Source(33, 25) + SourceIndex(0) name (Foo.Bar) +13>Emitted(34, 30) Source(33, 26) + SourceIndex(0) name (Foo.Bar) +14>Emitted(34, 31) Source(33, 27) + SourceIndex(0) name (Foo.Bar) +15>Emitted(34, 37) Source(33, 33) + SourceIndex(0) name (Foo.Bar) +16>Emitted(34, 39) Source(33, 35) + SourceIndex(0) name (Foo.Bar) +17>Emitted(34, 40) Source(33, 36) + SourceIndex(0) name (Foo.Bar) +18>Emitted(34, 42) Source(33, 38) + SourceIndex(0) name (Foo.Bar) +19>Emitted(34, 44) Source(33, 40) + SourceIndex(0) name (Foo.Bar) +20>Emitted(34, 45) Source(33, 41) + SourceIndex(0) name (Foo.Bar) --- >>> b[j].greet(); 1 >^^^^^^^^^^^^ @@ -831,15 +856,15 @@ sourceFile:sourceMapValidationClasses.ts 7 > greet 8 > () 9 > ; -1 >Emitted(34, 13) Source(34, 9) + SourceIndex(0) name (Foo.Bar) -2 >Emitted(34, 14) Source(34, 10) + SourceIndex(0) name (Foo.Bar) -3 >Emitted(34, 15) Source(34, 11) + SourceIndex(0) name (Foo.Bar) -4 >Emitted(34, 16) Source(34, 12) + SourceIndex(0) name (Foo.Bar) -5 >Emitted(34, 17) Source(34, 13) + SourceIndex(0) name (Foo.Bar) -6 >Emitted(34, 18) Source(34, 14) + SourceIndex(0) name (Foo.Bar) -7 >Emitted(34, 23) Source(34, 19) + SourceIndex(0) name (Foo.Bar) -8 >Emitted(34, 25) Source(34, 21) + SourceIndex(0) name (Foo.Bar) -9 >Emitted(34, 26) Source(34, 22) + SourceIndex(0) name (Foo.Bar) +1 >Emitted(35, 13) Source(34, 9) + SourceIndex(0) name (Foo.Bar) +2 >Emitted(35, 14) Source(34, 10) + SourceIndex(0) name (Foo.Bar) +3 >Emitted(35, 15) Source(34, 11) + SourceIndex(0) name (Foo.Bar) +4 >Emitted(35, 16) Source(34, 12) + SourceIndex(0) name (Foo.Bar) +5 >Emitted(35, 17) Source(34, 13) + SourceIndex(0) name (Foo.Bar) +6 >Emitted(35, 18) Source(34, 14) + SourceIndex(0) name (Foo.Bar) +7 >Emitted(35, 23) Source(34, 19) + SourceIndex(0) name (Foo.Bar) +8 >Emitted(35, 25) Source(34, 21) + SourceIndex(0) name (Foo.Bar) +9 >Emitted(35, 26) Source(34, 22) + SourceIndex(0) name (Foo.Bar) --- >>> } 1 >^^^^^^^^ @@ -848,8 +873,8 @@ sourceFile:sourceMapValidationClasses.ts 1 > > 2 > } -1 >Emitted(35, 9) Source(35, 5) + SourceIndex(0) name (Foo.Bar) -2 >Emitted(35, 10) Source(35, 6) + SourceIndex(0) name (Foo.Bar) +1 >Emitted(36, 9) Source(35, 5) + SourceIndex(0) name (Foo.Bar) +2 >Emitted(36, 10) Source(35, 6) + SourceIndex(0) name (Foo.Bar) --- >>> })(Bar = Foo.Bar || (Foo.Bar = {})); 1->^^^^ @@ -906,15 +931,15 @@ sourceFile:sourceMapValidationClasses.ts > b[j].greet(); > } > } -1->Emitted(36, 5) Source(36, 1) + SourceIndex(0) name (Foo.Bar) -2 >Emitted(36, 6) Source(36, 2) + SourceIndex(0) name (Foo.Bar) -3 >Emitted(36, 8) Source(1, 12) + SourceIndex(0) name (Foo) -4 >Emitted(36, 11) Source(1, 15) + SourceIndex(0) name (Foo) -5 >Emitted(36, 14) Source(1, 12) + SourceIndex(0) name (Foo) -6 >Emitted(36, 21) Source(1, 15) + SourceIndex(0) name (Foo) -7 >Emitted(36, 26) Source(1, 12) + SourceIndex(0) name (Foo) -8 >Emitted(36, 33) Source(1, 15) + SourceIndex(0) name (Foo) -9 >Emitted(36, 41) Source(36, 2) + SourceIndex(0) name (Foo) +1->Emitted(37, 5) Source(36, 1) + SourceIndex(0) name (Foo.Bar) +2 >Emitted(37, 6) Source(36, 2) + SourceIndex(0) name (Foo.Bar) +3 >Emitted(37, 8) Source(1, 12) + SourceIndex(0) name (Foo) +4 >Emitted(37, 11) Source(1, 15) + SourceIndex(0) name (Foo) +5 >Emitted(37, 14) Source(1, 12) + SourceIndex(0) name (Foo) +6 >Emitted(37, 21) Source(1, 15) + SourceIndex(0) name (Foo) +7 >Emitted(37, 26) Source(1, 12) + SourceIndex(0) name (Foo) +8 >Emitted(37, 33) Source(1, 15) + SourceIndex(0) name (Foo) +9 >Emitted(37, 41) Source(36, 2) + SourceIndex(0) name (Foo) --- >>>})(Foo || (Foo = {})); 1 > @@ -967,12 +992,12 @@ sourceFile:sourceMapValidationClasses.ts > b[j].greet(); > } > } -1 >Emitted(37, 1) Source(36, 1) + SourceIndex(0) name (Foo) -2 >Emitted(37, 2) Source(36, 2) + SourceIndex(0) name (Foo) -3 >Emitted(37, 4) Source(1, 8) + SourceIndex(0) -4 >Emitted(37, 7) Source(1, 11) + SourceIndex(0) -5 >Emitted(37, 12) Source(1, 8) + SourceIndex(0) -6 >Emitted(37, 15) Source(1, 11) + SourceIndex(0) -7 >Emitted(37, 23) Source(36, 2) + SourceIndex(0) +1 >Emitted(38, 1) Source(36, 1) + SourceIndex(0) name (Foo) +2 >Emitted(38, 2) Source(36, 2) + SourceIndex(0) name (Foo) +3 >Emitted(38, 4) Source(1, 8) + SourceIndex(0) +4 >Emitted(38, 7) Source(1, 11) + SourceIndex(0) +5 >Emitted(38, 12) Source(1, 8) + SourceIndex(0) +6 >Emitted(38, 15) Source(1, 11) + SourceIndex(0) +7 >Emitted(38, 23) Source(36, 2) + SourceIndex(0) --- >>>//# sourceMappingURL=sourceMapValidationClasses.js.map \ No newline at end of file diff --git a/tests/baselines/reference/switchAssignmentCompat.js b/tests/baselines/reference/switchAssignmentCompat.js index 7b3f2af80bb..1e6792ee378 100644 --- a/tests/baselines/reference/switchAssignmentCompat.js +++ b/tests/baselines/reference/switchAssignmentCompat.js @@ -13,5 +13,5 @@ var Foo = (function () { return Foo; })(); switch (0) { - case Foo: break; + case Foo: break; // Error expected } diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.js b/tests/baselines/reference/switchCasesExpressionTypeMismatch.js index a35dc633e35..ca354779be1 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.js +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.js @@ -25,12 +25,13 @@ var Foo = (function () { return Foo; })(); switch (0) { - case Foo: break; - case "sss": break; - case 123: break; - case true: break; + case Foo: break; // Error + case "sss": break; // Error + case 123: break; // No Error + case true: break; // Error } var s = 0; +// No error for all switch (s) { case Foo: break; case "sss": break; diff --git a/tests/baselines/reference/throwStatements.js b/tests/baselines/reference/throwStatements.js index 871bbc2ff0a..146d1232792 100644 --- a/tests/baselines/reference/throwStatements.js +++ b/tests/baselines/reference/throwStatements.js @@ -149,6 +149,7 @@ throw aFunctionInModule; // no initializer or annotation, so this is an 'any' var x; throw x; +// literals throw 0.0; throw false; throw null; diff --git a/tests/baselines/reference/typeGuardsInConditionalExpression.js b/tests/baselines/reference/typeGuardsInConditionalExpression.js index 303a27dc938..ebe84879d2b 100644 --- a/tests/baselines/reference/typeGuardsInConditionalExpression.js +++ b/tests/baselines/reference/typeGuardsInConditionalExpression.js @@ -105,56 +105,73 @@ function foo12(x: number | string | boolean) { // the type of a variable or parameter is narrowed by any type guard in the condition when false, // provided the false expression contains no assignments to the variable or parameter. function foo(x) { - return typeof x === "string" ? x.length : x++; // number + return typeof x === "string" ? x.length // string + : x++; // number } function foo2(x) { // x is assigned in the if true branch, the type is not narrowed - return typeof x === "string" ? (x = 10 && x) : x; // string | number + return typeof x === "string" ? (x = 10 && x) // string | number + : x; // string | number } function foo3(x) { // x is assigned in the if false branch, the type is not narrowed // even though assigned using same type as narrowed expression - return typeof x === "string" ? (x = "Hello" && x) : x; // string | number + return typeof x === "string" ? (x = "Hello" && x) // string | number + : x; // string | number } function foo4(x) { // false branch updates the variable - so here it is not number // even though assigned using same type as narrowed expression - return typeof x === "string" ? x : (x = 10 && x); // string | number + return typeof x === "string" ? x // string | number + : (x = 10 && x); // string | number } function foo5(x) { // false branch updates the variable - so here it is not number - return typeof x === "string" ? x : (x = "hello" && x); // string | number + return typeof x === "string" ? x // string | number + : (x = "hello" && x); // string | number } function foo6(x) { // Modify in both branches - return typeof x === "string" ? (x = 10 && x) : (x = "hello" && x); // string | number + return typeof x === "string" ? (x = 10 && x) // string | number + : (x = "hello" && x); // string | number } function foo7(x) { - return typeof x === "string" ? x === "hello" : typeof x === "boolean" ? x : x == 10; // number + return typeof x === "string" ? x === "hello" // string + : typeof x === "boolean" ? x // boolean + : x == 10; // number } function foo8(x) { var b; - return typeof x === "string" ? x === "hello" : ((b = x) && (typeof x === "boolean" ? x : x == 10)); // number + return typeof x === "string" ? x === "hello" : ((b = x) && (typeof x === "boolean" ? x // boolean + : x == 10)); // number } function foo9(x) { var y = 10; // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - return typeof x === "string" ? ((y = x.length) && x === "hello") : x === 10; // number + return typeof x === "string" ? ((y = x.length) && x === "hello") // string + : x === 10; // number } function foo10(x) { // Mixing typeguards var b; - return typeof x === "string" ? x : ((b = x) && typeof x === "number" && x.toString()); // x is number + return typeof x === "string" ? x // string + : ((b = x) // x is number | boolean + && typeof x === "number" && x.toString()); // x is number } function foo11(x) { // Mixing typeguards // Assigning value to x deep inside another guard stops narrowing of type too var b; - return typeof x === "string" ? x : ((b = x) && typeof x === "number" && (x = 10) && x); // x is number | boolean | string + return typeof x === "string" ? x // number | boolean | string - changed in the false branch + : ((b = x) // x is number | boolean | string - because the assignment changed it + && typeof x === "number" && (x = 10) // assignment to x + && x); // x is number | boolean | string } function foo12(x) { // Mixing typeguards // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression var b; - return typeof x === "string" ? (x = 10 && x.toString().length) : ((b = x) && typeof x === "number" && x); // x is number + return typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here + : ((b = x) // x is number | boolean | string - changed in true branch + && typeof x === "number" && x); // x is number } diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js index 317017c9acc..239eeb4bfe7 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.js @@ -84,25 +84,29 @@ module m1 { function foo(x) { return typeof x === "string" ? x : function f() { var b = x; // number | boolean - return typeof x === "boolean" ? x.toString() : x.toString(); // number + return typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number }(); } function foo2(x) { return typeof x === "string" ? x : function f(a) { var b = x; // new scope - number | boolean - return typeof x === "boolean" ? x.toString() : x.toString(); // number + return typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number }(x); // x here is narrowed to number | boolean } function foo3(x) { return typeof x === "string" ? x : (function () { var b = x; // new scope - number | boolean - return typeof x === "boolean" ? x.toString() : x.toString(); // number + return typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number })(); } function foo4(x) { return typeof x === "string" ? x : (function (a) { var b = x; // new scope - number | boolean - return typeof x === "boolean" ? x.toString() : x.toString(); // number + return typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number })(x); // x here is narrowed to number | boolean } // Type guards affect nested function expressions, but not nested function declarations @@ -125,7 +129,8 @@ var m; y = x; // string; } else { - y = typeof x === "boolean" ? x.toString() : x.toString(); // number + y = typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number } })(m2 || (m2 = {})); })(m || (m = {})); @@ -142,7 +147,8 @@ var m1; y = x; // string; } else { - y = typeof x === "boolean" ? x.toString() : x.toString(); // number + y = typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number } })(m3 = m2.m3 || (m2.m3 = {})); })(m2 || (m2 = {})); diff --git a/tests/baselines/reference/typeGuardsInIfStatement.js b/tests/baselines/reference/typeGuardsInIfStatement.js index 6b1fb4b062c..c228c038579 100644 --- a/tests/baselines/reference/typeGuardsInIfStatement.js +++ b/tests/baselines/reference/typeGuardsInIfStatement.js @@ -258,7 +258,8 @@ function foo10(x) { else { var y; var b = x; // number | boolean - return typeof x === "number" ? x === 10 : x; // x should be boolean + return typeof x === "number" ? x === 10 // number + : x; // x should be boolean } } function foo11(x) { @@ -270,7 +271,13 @@ function foo11(x) { else { var y; var b = x; // number | boolean | string - because below we are changing value of x in if statement - return typeof x === "number" ? (x = 10 && x.toString()) : (y = x && x.toString()); + return typeof x === "number" ? ( + // change value of x + x = 10 && x.toString() // number | boolean | string + ) : ( + // do not change value + y = x && x.toString() // number | boolean | string + ); } } function foo12(x) { @@ -282,6 +289,7 @@ function foo12(x) { else { x = 10; var b = x; // number | boolean | string - return typeof x === "number" ? x.toString() : x.toString(); // boolean | string + return typeof x === "number" ? x.toString() // number + : x.toString(); // boolean | string } } diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js index 501c5d8a9f9..ffba829c37d 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.js @@ -71,26 +71,37 @@ function foo3(x) { return typeof x === "string" && ((x = "hello") && x); // string | number } function foo4(x) { - return typeof x !== "string" && typeof x !== "number" && x; // boolean + return typeof x !== "string" // string | number | boolean + && typeof x !== "number" // number | boolean + && x; // boolean } function foo5(x) { // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop var b; - return typeof x !== "string" && ((b = x) && (typeof x !== "number" && x)); // boolean + return typeof x !== "string" // string | number | boolean + && ((b = x) && (typeof x !== "number" // number | boolean + && x)); // boolean } function foo6(x) { // Mixing typeguard narrowing in if statement with conditional expression typeguard - return typeof x !== "string" && (typeof x !== "number" ? x : x === 10); // number + return typeof x !== "string" // string | number | boolean + && (typeof x !== "number" // number | boolean + ? x // boolean + : x === 10); // number } function foo7(x) { var y; var z; // Mixing typeguard narrowing // Assigning value to x deep inside another guard stops narrowing of type too - return typeof x !== "string" && ((z = x) && (typeof x === "number" ? (x = 10 && x.toString()) : (y = x && x.toString()))); // number | boolean | string + return typeof x !== "string" && ((z = x) // string | number | boolean - x changed deeper in conditional expression + && (typeof x === "number" ? (x = 10 && x.toString()) // number | boolean | string + : (y = x && x.toString()))); // number | boolean | string } function foo8(x) { // Mixing typeguard // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - return typeof x !== "string" && (x = 10) && (typeof x === "number" ? x : x.length); // string + return typeof x !== "string" && (x = 10) // change x - number| string + && (typeof x === "number" ? x // number + : x.length); // string } diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js index d2b7938a9ca..5f5880a4947 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.js @@ -71,26 +71,37 @@ function foo3(x) { return typeof x !== "string" || ((x = "hello") || x); // string | number } function foo4(x) { - return typeof x === "string" || typeof x === "number" || x; // boolean + return typeof x === "string" // string | number | boolean + || typeof x === "number" // number | boolean + || x; // boolean } function foo5(x) { // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop var b; - return typeof x === "string" || ((b = x) || (typeof x === "number" || x)); // boolean + return typeof x === "string" // string | number | boolean + || ((b = x) || (typeof x === "number" // number | boolean + || x)); // boolean } function foo6(x) { // Mixing typeguard - return typeof x === "string" || (typeof x !== "number" ? x : x === 10); // number + return typeof x === "string" // string | number | boolean + || (typeof x !== "number" // number | boolean + ? x // boolean + : x === 10); // number } function foo7(x) { var y; var z; // Mixing typeguard narrowing // Assigning value to x deep inside another guard stops narrowing of type too - return typeof x === "string" || ((z = x) || (typeof x === "number" ? (x = 10 && x.toString()) : (y = x && x.toString()))); // number | boolean | string + return typeof x === "string" || ((z = x) // string | number | boolean - x changed deeper in conditional expression + || (typeof x === "number" ? (x = 10 && x.toString()) // number | boolean | string + : (y = x && x.toString()))); // number | boolean | string } function foo8(x) { // Mixing typeguard // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - return typeof x === "string" || (x = 10) || (typeof x === "number" ? x : x.length); // string + return typeof x === "string" || (x = 10) // change x - number| string + || (typeof x === "number" ? x // number + : x.length); // string } diff --git a/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js b/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js index 5196497478e..cddf9ebf254 100644 --- a/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js +++ b/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js @@ -131,12 +131,12 @@ var WinJS; })(WinJS || (WinJS = {})); var Errors; (function (Errors) { - var ConnectionError = (function () { - function ConnectionError(request) { + var ConnectionError /* extends Error */ = (function () { + function ConnectionError /* extends Error */(request) { } - return ConnectionError; + return ConnectionError /* extends Error */; })(); - Errors.ConnectionError = ConnectionError; + Errors.ConnectionError /* extends Error */ = ConnectionError /* extends Error */; })(Errors || (Errors = {})); var FileService = (function () { function FileService() { From 0940d3bb3b923615568f5cc56d876b4a6576cf79 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 22 Jan 2015 17:16:18 -0800 Subject: [PATCH 41/71] handle union properties in when doing getOccurences\findAllReferences --- src/services/services.ts | 3 ++- tests/cases/fourslash/scopeOfUnionProperties.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/scopeOfUnionProperties.ts diff --git a/src/services/services.ts b/src/services/services.ts index 84e5e7fefa5..d56c2c29639 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3903,7 +3903,8 @@ module ts { } // if this symbol is visible from its parent container, e.g. exported, then bail out - if (symbol.parent) { + // if symbol correspond to the union property - bail out + if (symbol.parent || (symbol.getFlags() & SymbolFlags.UnionProperty)) { return undefined; } diff --git a/tests/cases/fourslash/scopeOfUnionProperties.ts b/tests/cases/fourslash/scopeOfUnionProperties.ts new file mode 100644 index 00000000000..ec2fe3a9ac5 --- /dev/null +++ b/tests/cases/fourslash/scopeOfUnionProperties.ts @@ -0,0 +1,7 @@ +/// + +////function f(s: string | number) { +//// s.constr/*1*/uctor +////} +goTo.marker("1") +verify.occurrencesAtPositionCount(1); From 379d03b5a732824e561bc4c67e5232431c260c7c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 22 Jan 2015 18:20:40 -0800 Subject: [PATCH 42/71] use nameTable - services layer storage of identifiers in the file --- src/services/services.ts | 64 +++++++++++++++---- .../fourslash/getOccurrencesAfterEdit.ts | 15 +++++ 2 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 tests/cases/fourslash/getOccurrencesAfterEdit.ts diff --git a/src/services/services.ts b/src/services/services.ts index 84e5e7fefa5..e662f6f2de1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -59,7 +59,7 @@ module ts { isOpen: boolean; version: string; scriptSnapshot: IScriptSnapshot; - + nameTable: Map; getNamedDeclarations(): Declaration[]; } @@ -750,6 +750,7 @@ module ts { public isOpen: boolean; public languageVersion: ScriptTarget; public identifiers: Map; + public nameTable: Map; private namedDeclarations: Declaration[]; @@ -1546,6 +1547,8 @@ module ts { export function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile { var sourceFile = createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version, isOpen); + // after full parsing we can use table with interned strings as name table + sourceFile.nameTable = sourceFile.identifiers; return sourceFile; } @@ -1577,6 +1580,9 @@ module ts { if (!disableIncrementalParsing) { var newSourceFile = sourceFile.update(scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange); setSourceFileFields(newSourceFile, scriptSnapshot, version, isOpen); + // after incremental parsing nameTable might not be up-to-date + // drop it so it can be lazily recreated later + newSourceFile.nameTable = undefined; return newSourceFile; } } @@ -3235,7 +3241,7 @@ module ts { if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - return getReferencesForNode(node, [sourceFile], /*findInStrings:*/ false, /*findInComments:*/ false); + return getReferencesForNode(node, [sourceFile], /*searchOnlyInCurrentFile*/ true, /*findInStrings:*/ false, /*findInComments:*/ false); } switch (node.kind) { @@ -3788,10 +3794,31 @@ module ts { } Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.NumericLiteral || node.kind === SyntaxKind.StringLiteral); - return getReferencesForNode(node, program.getSourceFiles(), findInStrings, findInComments); + return getReferencesForNode(node, program.getSourceFiles(), /*searchOnlyInCurrentFile*/ false, findInStrings, findInComments); } - function getReferencesForNode(node: Node, sourceFiles: SourceFile[], findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { + function initializeNameTable(sourceFile: SourceFile): void { + var nameTable: Map = {}; + + walk(sourceFile); + sourceFile.nameTable = nameTable; + + function walk(node: Node) { + switch (node.kind) { + case SyntaxKind.Identifier: + nameTable[(node).text] = (node).text; + break; + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + nameTable[(node).text] = (node).text; + break; + default: + forEachChild(node, walk); + } + } + } + + function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { // Labels if (isLabelName(node)) { if (isJumpStatementTarget(node)) { @@ -3847,15 +3874,28 @@ module ts { getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } else { - var internedName = getInternedName(symbol, declarations) - forEach(sourceFiles, sourceFile => { - cancellationToken.throwIfCancellationRequested(); + if (searchOnlyInCurrentFile) { + Debug.assert(sourceFiles.length === 1); + result = []; + getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + } + else { + var internedName = getInternedName(symbol, declarations) + forEach(sourceFiles, sourceFile => { + cancellationToken.throwIfCancellationRequested(); - if (lookUp(sourceFile.identifiers, internedName)) { - result = result || []; - getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); - } - }); + if (!sourceFile.nameTable) { + initializeNameTable(sourceFile) + } + + Debug.assert(sourceFile.nameTable !== undefined); + + if (lookUp(sourceFile.nameTable, internedName)) { + result = result || []; + getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + } + }); + } } return result; diff --git a/tests/cases/fourslash/getOccurrencesAfterEdit.ts b/tests/cases/fourslash/getOccurrencesAfterEdit.ts new file mode 100644 index 00000000000..f878da9356d --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesAfterEdit.ts @@ -0,0 +1,15 @@ +/// + +/////*0*/ +////function f(s: string) { +//// s.con/*1*/structor +////} + +goTo.marker("1"); +verify.occurrencesAtPositionCount(1); + +goTo.marker("0"); +edit.insert("\r\n"); + +goTo.marker("1"); +verify.occurrencesAtPositionCount(1); \ No newline at end of file From 4a7aa7e929c96adf4b3bf67408931603c90f4738 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 22 Jan 2015 19:09:10 -0800 Subject: [PATCH 43/71] Address CR feedback --- src/compiler/binder.ts | 17 +++++++++-------- src/compiler/checker.ts | 34 +++++++++++++++++++++------------- src/compiler/emitter.ts | 6 +++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 730fff06897..fe52e26ddd1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -50,12 +50,13 @@ module ts { } /** - * Returns false if any of the following are true: - * 1. declaration has no name - * 2. declaration has a literal name (not computed) - * 3. declaration has a computed property name that is a known symbol + * A declaration has a dynamic name if both of the following are true: + * 1. The declaration has a computed property name + * 2. The computed name is *not* expressed as Symbol., where name + * is a property of the Symbol constructor that denotes a built in + * Symbol. */ - export function hasComputedNameButNotSymbol(declaration: Declaration): boolean { + export function hasDynamicName(declaration: Declaration): boolean { return declaration.name && declaration.name.kind === SyntaxKind.ComputedPropertyName; } @@ -96,7 +97,7 @@ module ts { if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) { return '"' + (node.name).text + '"'; } - Debug.assert(!hasComputedNameButNotSymbol(node)); + Debug.assert(!hasDynamicName(node)); return (node.name).text; } switch (node.kind) { @@ -118,7 +119,7 @@ module ts { } function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol { - Debug.assert(!hasComputedNameButNotSymbol(node)); + Debug.assert(!hasDynamicName(node)); var name = getDeclarationName(node); if (name !== undefined) { @@ -508,7 +509,7 @@ module ts { } function bindPropertyOrMethodOrAccessor(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); } else { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index feaeff75e8f..66edc7cda2d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -337,6 +337,15 @@ module ts { break loop; } break; + + // It is not legal to reference a class's own type parameters from a computed property name that + // belongs to the class. For example: + // + // function foo() { return '' } + // class C { // <-- Class's own type parameter T + // [foo()]() { } // <-- Reference to T from class's own computed property + // } + // case SyntaxKind.ComputedPropertyName: var grandparent = location.parent.parent; if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) { @@ -1716,7 +1725,7 @@ module ts { if (declaration.kind === SyntaxKind.Parameter) { var func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present - if (func.kind === SyntaxKind.SetAccessor && !hasComputedNameButNotSymbol(func)) { + if (func.kind === SyntaxKind.SetAccessor && !hasDynamicName(func)) { var getter = getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); @@ -2632,7 +2641,7 @@ module ts { else { // TypeScript 1.0 spec (April 2014): // If only one accessor includes a type annotation, the other behaves as if it had the same type annotation. - if (declaration.kind === SyntaxKind.GetAccessor && !hasComputedNameButNotSymbol(declaration)) { + if (declaration.kind === SyntaxKind.GetAccessor && !hasDynamicName(declaration)) { var setter = getDeclarationOfKind(declaration.symbol, SyntaxKind.SetAccessor); returnType = getAnnotatedAccessorType(setter); } @@ -5165,7 +5174,7 @@ module ts { var objectLiteral = element.parent; var type = getContextualType(objectLiteral); if (type) { - if (!hasComputedNameButNotSymbol(element)) { + if (!hasDynamicName(element)) { // For a (non-symbol) computed property, there is no reason to look up the name // in the type. It will just be "__computed", which does not appear in any // SymbolTable. @@ -5418,9 +5427,8 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - // This will only allow types number, string, or any. Any types more complex will - // be disallowed, even union types like string | number. In the future, we might consider - // allowing types like that. + // This will allow types number, string, or any. It will also allow enums, the unknown + // type, and any union of these types (like string | number). if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); } @@ -5477,7 +5485,7 @@ module ts { checkAccessorDeclaration(memberDecl); } - if (!hasComputedNameButNotSymbol(memberDecl)) { + if (!hasDynamicName(memberDecl)) { properties[member.name] = member; } } @@ -7079,7 +7087,7 @@ module ts { } function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type { - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { checkComputedPropertyName(node.name); } @@ -7090,7 +7098,7 @@ module ts { // Grammar checking checkGrammarMethod(node); - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { checkComputedPropertyName(node.name); } @@ -7464,7 +7472,7 @@ module ts { } } - if (!hasComputedNameButNotSymbol(node)) { + if (!hasDynamicName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. var otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor; @@ -7902,7 +7910,7 @@ module ts { function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { checkSignatureDeclaration(node); - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { // This check will account for methods in class/interface declarations, // as well as accessors in classes/object literals checkComputedPropertyName(node.name); @@ -8136,7 +8144,7 @@ module ts { function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkSourceElement(node.type); // For a computed property, just check the initializer and exit - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); @@ -8501,7 +8509,7 @@ module ts { // Only process instance properties with computed names here. // Static properties cannot be in conflict with indexers, // and properties with literal names were already checked. - if (!(member.flags & NodeFlags.Static) && hasComputedNameButNotSymbol(member)) { + if (!(member.flags & NodeFlags.Static) && hasDynamicName(member)) { var propType = getTypeOfSymbol(member.symbol); checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String); checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b61b87b8dc7..6626823379b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -932,7 +932,7 @@ module ts { } function emitPropertyDeclaration(node: Declaration) { - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { return; } @@ -1036,7 +1036,7 @@ module ts { } function emitAccessorDeclaration(node: AccessorDeclaration) { - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { return; } @@ -1117,7 +1117,7 @@ module ts { } function emitFunctionDeclaration(node: FunctionLikeDeclaration) { - if (hasComputedNameButNotSymbol(node)) { + if (hasDynamicName(node)) { return; } From 05ec43a0f3e6669b35d9d7b4b41f4ae485e25619 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 23 Jan 2015 12:04:55 -0800 Subject: [PATCH 44/71] make sure that enum values are computed before the emit --- src/compiler/checker.ts | 4 ++-- src/harness/fourslash.ts | 12 ++++++++++++ .../constEnumsEmitOutputInMultipleFiles.ts | 18 ++++++++++++++++++ tests/cases/fourslash/fourslash.ts | 4 ++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/constEnumsEmitOutputInMultipleFiles.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7233c2e85d5..a606a3f00fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10001,8 +10001,8 @@ module ts { if (symbol && (symbol.flags & SymbolFlags.EnumMember)) { var declaration = symbol.valueDeclaration; var constantValue: number; - if (declaration.kind === SyntaxKind.EnumMember && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue; + if (declaration.kind === SyntaxKind.EnumMember) { + return getEnumMemberValue(declaration); } } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index cfc83af76e5..512248197a4 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -548,6 +548,18 @@ module FourSlash { } } + public verifyGetEmitOutputForCurrentFile(expected: string): void { + var emit = this.languageService.getEmitOutput(this.activeFile.fileName); + if (emit.outputFiles.length !== 1) { + throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName); + } + this.taoInvalidReason = 'verifyGetEmitOutputForCurrentFile impossible'; + var actual = emit.outputFiles[0].text; + if (actual !== expected) { + this.raiseError("Expected emit output to be '" + expected + "', but got '" + actual + "'"); + } + } + public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) { this.scenarioActions.push(''); this.scenarioActions.push(''); diff --git a/tests/cases/fourslash/constEnumsEmitOutputInMultipleFiles.ts b/tests/cases/fourslash/constEnumsEmitOutputInMultipleFiles.ts new file mode 100644 index 00000000000..0f6be184d8c --- /dev/null +++ b/tests/cases/fourslash/constEnumsEmitOutputInMultipleFiles.ts @@ -0,0 +1,18 @@ +/// + +// @Filename: a.ts +////const enum TestEnum { +//// Foo, Bar +////} +////var testFirstFile = TestEnum.Bar; + +// @Filename: b.ts +/////// +/////*1*/ +////var testInOtherFile = TestEnum.Bar; + +goTo.marker("1"); +verify.verifyGetEmitOutputForCurrentFile( +"/// \r\n\ +var testInOtherFile = 1 /* Bar */;\r\n" + ) \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 0f458041521..5b88b15f9fa 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -264,6 +264,10 @@ module FourSlashInterface { FourSlash.currentTestState.verifyCurrentFileContent(text); } + public verifyGetEmitOutputForCurrentFile(expected: string): void { + FourSlash.currentTestState.verifyGetEmitOutputForCurrentFile(expected); + } + public currentParameterHelpArgumentNameIs(name: string) { FourSlash.currentTestState.verifyCurrentParameterHelpName(name); } From 6040e55fa42fdb0877c0f062840667a7f3ea9c54 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 23 Jan 2015 15:36:36 -0800 Subject: [PATCH 45/71] add 'find all references' test --- .../fourslash/findReferencesAfterEdit.ts | 22 +++++++++++++++++++ .../cases/fourslash/getOccurencesAfterEdit.ts | 18 +++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/cases/fourslash/findReferencesAfterEdit.ts create mode 100644 tests/cases/fourslash/getOccurencesAfterEdit.ts diff --git a/tests/cases/fourslash/findReferencesAfterEdit.ts b/tests/cases/fourslash/findReferencesAfterEdit.ts new file mode 100644 index 00000000000..5eca1a3b8f2 --- /dev/null +++ b/tests/cases/fourslash/findReferencesAfterEdit.ts @@ -0,0 +1,22 @@ +/// + +// @Filename: a.ts +////interface A { +//// foo: string; +////} + +// @Filename: b.ts +/////// +/////*0*/ +////function foo(x: A) { +//// x.f/*1*/oo +////} + +goTo.marker("1"); +verify.referencesCountIs(2); + +goTo.marker("0"); +edit.insert("\r\n"); + +goTo.marker("1"); +verify.referencesCountIs(2); \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurencesAfterEdit.ts b/tests/cases/fourslash/getOccurencesAfterEdit.ts new file mode 100644 index 00000000000..0654cc3962c --- /dev/null +++ b/tests/cases/fourslash/getOccurencesAfterEdit.ts @@ -0,0 +1,18 @@ +/// + +/////*0*/ +////interface A { +//// foo: string; +////} +////function foo(x: A) { +//// x.f/*1*/oo +////} + +goTo.marker("1"); +verify.occurrencesAtPositionCount(2); + +goTo.marker("0"); +edit.insert("\r\n"); + +goTo.marker("1"); +verify.occurrencesAtPositionCount(2); \ No newline at end of file From da6070bcf755e1f36cb8b61f8658f0d08a41c7ce Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 23 Jan 2015 15:39:50 -0800 Subject: [PATCH 46/71] fixed typo in test name --- .../cases/fourslash/getOccurencesAfterEdit.ts | 18 ------------------ .../cases/fourslash/getOccurrencesAfterEdit.ts | 11 +++++++---- 2 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 tests/cases/fourslash/getOccurencesAfterEdit.ts diff --git a/tests/cases/fourslash/getOccurencesAfterEdit.ts b/tests/cases/fourslash/getOccurencesAfterEdit.ts deleted file mode 100644 index 0654cc3962c..00000000000 --- a/tests/cases/fourslash/getOccurencesAfterEdit.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// - -/////*0*/ -////interface A { -//// foo: string; -////} -////function foo(x: A) { -//// x.f/*1*/oo -////} - -goTo.marker("1"); -verify.occurrencesAtPositionCount(2); - -goTo.marker("0"); -edit.insert("\r\n"); - -goTo.marker("1"); -verify.occurrencesAtPositionCount(2); \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesAfterEdit.ts b/tests/cases/fourslash/getOccurrencesAfterEdit.ts index f878da9356d..0654cc3962c 100644 --- a/tests/cases/fourslash/getOccurrencesAfterEdit.ts +++ b/tests/cases/fourslash/getOccurrencesAfterEdit.ts @@ -1,15 +1,18 @@ /// /////*0*/ -////function f(s: string) { -//// s.con/*1*/structor +////interface A { +//// foo: string; +////} +////function foo(x: A) { +//// x.f/*1*/oo ////} goTo.marker("1"); -verify.occurrencesAtPositionCount(1); +verify.occurrencesAtPositionCount(2); goTo.marker("0"); edit.insert("\r\n"); goTo.marker("1"); -verify.occurrencesAtPositionCount(1); \ No newline at end of file +verify.occurrencesAtPositionCount(2); \ No newline at end of file From b05f2bf1a3ebbd0a1967c63d5cd6852d396f4bad Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 23 Jan 2015 17:08:30 -0800 Subject: [PATCH 47/71] handle binding patterns correctly when getting script lexical structure --- src/services/navigationBar.ts | 2 +- .../cases/fourslash/scriptLexicalStructureBindingPatterns.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 9051ee80399..5ffcc6e1b6a 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -51,7 +51,7 @@ module ts.NavigationBar { forEach((node).elements, visit); break; case SyntaxKind.VariableDeclaration: - if (isBindingPattern(node)) { + if (isBindingPattern((node).name)) { visit((node).name); break; } diff --git a/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts b/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts new file mode 100644 index 00000000000..b3141de5720 --- /dev/null +++ b/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts @@ -0,0 +1,4 @@ +/// +////var foo, {} +////var bar, [] +verify.getScriptLexicalStructureListCount(3); // global (1) + variable declarations (2) From f4ca318c39ca4181fb331c2b03980524359c0572 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 24 Jan 2015 00:17:55 -0800 Subject: [PATCH 48/71] add binding elements from variable declaration into script lexical structure --- src/services/navigationBar.ts | 36 ++++++++++++++----- .../scriptLexicalStructureBindingPatterns.ts | 19 +++++++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 5ffcc6e1b6a..423ee5e58a6 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -50,6 +50,7 @@ module ts.NavigationBar { case SyntaxKind.ArrayBindingPattern: forEach((node).elements, visit); break; + case SyntaxKind.BindingElement: case SyntaxKind.VariableDeclaration: if (isBindingPattern((node).name)) { visit((node).name); @@ -262,17 +263,34 @@ module ts.NavigationBar { return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); case SyntaxKind.VariableDeclaration: - if (isBindingPattern((node).name)) { - break; - } - if (isConst(node)) { - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.constElement); - } - else if (isLet(node)) { - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.letElement); + case SyntaxKind.BindingElement: + var variableDeclarationNode: Node; + var name: Node; + + if (node.kind === SyntaxKind.BindingElement) { + name = (node).name; + variableDeclarationNode = node; + // binding elements are added only for variable declarations + // bubble up to the containing variable declaration + while (variableDeclarationNode && variableDeclarationNode.kind !== SyntaxKind.VariableDeclaration) { + variableDeclarationNode = variableDeclarationNode.parent; + } + Debug.assert(variableDeclarationNode !== undefined); } else { - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.variableElement); + Debug.assert(!isBindingPattern((node).name)); + variableDeclarationNode = node; + name = (node).name; + } + + if (isConst(variableDeclarationNode)) { + return createItem(node, getTextOfNode(name), ts.ScriptElementKind.constElement); + } + else if (isLet(variableDeclarationNode)) { + return createItem(node, getTextOfNode(name), ts.ScriptElementKind.letElement); + } + else { + return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement); } case SyntaxKind.Constructor: diff --git a/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts b/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts index b3141de5720..2b363bfad3b 100644 --- a/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts +++ b/tests/cases/fourslash/scriptLexicalStructureBindingPatterns.ts @@ -1,4 +1,21 @@ /// +////'use strict' ////var foo, {} ////var bar, [] -verify.getScriptLexicalStructureListCount(3); // global (1) + variable declarations (2) +////let foo1, {a, b} +////const bar1, [c, d] +////var {e, x: [f, g]} = {a:1, x:[]}; + +verify.getScriptLexicalStructureListCount(12); // global (1) + variable declarations (4) + binding patterns (7) +verify.getScriptLexicalStructureListContains("foo", "var"); +verify.getScriptLexicalStructureListContains("bar", "var"); +verify.getScriptLexicalStructureListContains("foo1", "let") +verify.getScriptLexicalStructureListContains("a", "let"); +verify.getScriptLexicalStructureListContains("b", "let"); +verify.getScriptLexicalStructureListContains("bar1", "const"); +verify.getScriptLexicalStructureListContains("c", "const"); +verify.getScriptLexicalStructureListContains("d", "const"); +verify.getScriptLexicalStructureListContains("e", "var"); +verify.getScriptLexicalStructureListContains("f", "var"); +verify.getScriptLexicalStructureListContains("g", "var"); + From 15dcccde7ddbbb3626a3e3c2d5a53fe27650196a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 24 Jan 2015 08:03:29 -0800 Subject: [PATCH 49/71] Improved subtype compatibility for types of object literals --- src/compiler/checker.ts | 73 ++++++++++++++++++++--------------------- src/compiler/types.ts | 5 ++- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7233c2e85d5..431d81696a1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -66,8 +66,8 @@ module ts { var numberType = createIntrinsicType(TypeFlags.Number, "number"); var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean"); var voidType = createIntrinsicType(TypeFlags.Void, "void"); - var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.Unwidened, "undefined"); - var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.Unwidened, "null"); + var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefined, "undefined"); + var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefined, "null"); var unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); var resolvingType = createIntrinsicType(TypeFlags.Any, "__resolving__"); @@ -2807,15 +2807,19 @@ module ts { } } - function getUnwidenedFlagOfTypes(types: Type[]): TypeFlags { - return forEach(types, t => t.flags & TypeFlags.Unwidened) || 0; + function getWideningFlagsOfTypes(types: Type[]): TypeFlags { + var result: TypeFlags = 0; + for (var i = 0; i < types.length; i++) { + result |= types[i].flags; + } + return result & TypeFlags.RequiresWidening; } function createTypeReference(target: GenericType, typeArguments: Type[]): TypeReference { var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = TypeFlags.Reference | getUnwidenedFlagOfTypes(typeArguments); + var flags = TypeFlags.Reference | getWideningFlagsOfTypes(typeArguments); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -3076,7 +3080,7 @@ module ts { var id = getTypeListId(sortedTypes); var type = unionTypes[id]; if (!type) { - type = unionTypes[id] = createObjectType(TypeFlags.Union | getUnwidenedFlagOfTypes(sortedTypes)); + type = unionTypes[id] = createObjectType(TypeFlags.Union | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; } return type; @@ -3692,12 +3696,13 @@ module ts { } var result = Ternary.True; var properties = getPropertiesOfObjectType(target); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & TypeFlags.ObjectLiteral); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (relation === subtypeRelation || !(targetProp.flags & SymbolFlags.Optional)) { + if (!(targetProp.flags & SymbolFlags.Optional) || requireOptionalProperties) { if (reportErrors) { reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -4088,10 +4093,6 @@ module ts { errorMessageChainHead); } - function isTypeOfObjectLiteral(type: Type): boolean { - return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; - } - function isArrayType(type: Type): boolean { return type.flags & TypeFlags.Reference && (type).target === globalArrayType; } @@ -4104,13 +4105,18 @@ module ts { var properties = getPropertiesOfObjectType(type); var members: SymbolTable = {}; forEach(properties, p => { - var symbol = createSymbol(p.flags | SymbolFlags.Transient, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = getWidenedType(getTypeOfSymbol(p)); - symbol.target = p; - if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration; - members[symbol.name] = symbol; + var propType = getTypeOfSymbol(p); + var widenedType = getWidenedType(propType); + if (propType !== widenedType) { + var symbol = createSymbol(p.flags | SymbolFlags.Transient, p.name); + symbol.declarations = p.declarations; + symbol.parent = p.parent; + symbol.type = getWidenedType(getTypeOfSymbol(p)); + symbol.target = p; + if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration; + p = symbol; + } + members[p.name] = p; }); var stringIndexType = getIndexTypeOfType(type, IndexKind.String); var numberIndexType = getIndexTypeOfType(type, IndexKind.Number); @@ -4120,16 +4126,16 @@ module ts { } function getWidenedType(type: Type): Type { - if (type.flags & TypeFlags.Unwidened) { + if (type.flags & TypeFlags.RequiresWidening) { if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) { return anyType; } + if (type.flags & TypeFlags.ObjectLiteral) { + return getWidenedTypeOfObjectLiteral(type); + } if (type.flags & TypeFlags.Union) { return getUnionType(map((type).types, getWidenedType)); } - if (isTypeOfObjectLiteral(type)) { - return getWidenedTypeOfObjectLiteral(type); - } if (isArrayType(type)) { return createArrayType(getWidenedType((type).typeArguments[0])); } @@ -4150,11 +4156,11 @@ module ts { if (isArrayType(type)) { return reportWideningErrorsInType((type).typeArguments[0]); } - if (isTypeOfObjectLiteral(type)) { + if (type.flags & TypeFlags.ObjectLiteral) { var errorReported = false; forEach(getPropertiesOfObjectType(type), p => { var t = getTypeOfSymbol(p); - if (t.flags & TypeFlags.Unwidened) { + if (t.flags & TypeFlags.ContainsUndefined) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -4198,7 +4204,7 @@ module ts { } function reportErrorsFromWidening(declaration: Declaration, type: Type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.Unwidened) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.ContainsUndefined) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); @@ -5455,21 +5461,10 @@ module ts { } } - // If object literal is contextually (but not inferentially) typed, copy missing optional properties from - // the contextual type such that the resulting type becomes a subtype in cases where only optional properties - // were omitted. There is no need to create new property objects as nothing in them needs to change. - if (contextualType && !isInferentialContext(contextualMapper)) { - forEach(getPropertiesOfObjectType(contextualType), p => { - if (p.flags & SymbolFlags.Optional && !hasProperty(properties, p.name)) { - properties[p.name] = p; - } - }); - } - var stringIndexType = getIndexType(IndexKind.String); var numberIndexType = getIndexType(IndexKind.Number); var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= (typeFlags & TypeFlags.Unwidened); + result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsLiteral | (typeFlags & TypeFlags.ContainsUndefined); return result; function getIndexType(kind: IndexKind) { @@ -5485,7 +5480,9 @@ module ts { } } } - return propTypes.length ? getUnionType(propTypes) : undefinedType; + var result = propTypes.length ? getUnionType(propTypes) : undefinedType; + typeFlags |= result.flags; + return result; } return undefined; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b8c842641d7..474fdf30fed 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1283,12 +1283,15 @@ module ts { Union = 0x00004000, // Union Anonymous = 0x00008000, // Anonymous FromSignature = 0x00010000, // Created for signature assignment check - Unwidened = 0x00020000, // Unwidened type (is or contains Undefined or Null type) + ObjectLiteral = 0x00020000, // Originates in an object literal + ContainsUndefined = 0x00040000, // Type is or contains Undefined or Null type + ContainsLiteral = 0x00080000, // Type is or contains object literal type Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, StringLike = String | StringLiteral, NumberLike = Number | Enum, ObjectType = Class | Interface | Reference | Tuple | Anonymous, + RequiresWidening = ContainsUndefined | ContainsLiteral } // Properties common to all types From d6eb486c3ad424bcc101733cb23893ce1ab51e2a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 24 Jan 2015 08:04:23 -0800 Subject: [PATCH 50/71] Accepting new baselines --- .../baselines/reference/arrayCast.errors.txt | 2 ++ .../reference/assignmentCompatBug2.errors.txt | 16 +++++++------- .../assignmentCompatWithObjectMembers3.types | 4 ++-- .../reference/assignmentCompatability1.types | 2 +- .../reference/assignmentCompatability2.types | 2 +- .../reference/assignmentCompatability3.types | 2 +- .../reference/assignmentCompatability4.types | 2 +- .../reference/assignmentCompatability5.types | 2 +- .../reference/assignmentCompatability6.types | 4 ++-- .../reference/assignmentCompatability7.types | 4 ++-- .../reference/assignmentCompatability8.types | 2 +- .../reference/assignmentCompatability9.types | 2 +- .../reference/getterSetterNonAccessor.types | 4 ++-- tests/baselines/reference/indexer2.errors.txt | 20 ------------------ tests/baselines/reference/indexer2.types | 21 +++++++++++++++++++ .../baselines/reference/indexer2A.errors.txt | 15 ++----------- .../reference/intTypeCheck.errors.txt | 8 +++---- .../reference/interfaceContextualType.types | 12 +++++------ .../reference/objectLitGetterSetter.types | 4 ++-- .../objectLiteralContextualTyping.types | 4 ++-- .../optionalAccessorsInInterface1.types | 4 ++-- .../optionalPropertiesTest.errors.txt | 8 +++---- ...adBindingAcrossDeclarationBoundaries.types | 6 +++--- ...dBindingAcrossDeclarationBoundaries2.types | 6 +++--- ...notationBestCommonTypeInArrayLiteral.types | 6 +++--- .../baselines/reference/underscoreTest1.types | 6 +++--- 26 files changed, 80 insertions(+), 88 deletions(-) delete mode 100644 tests/baselines/reference/indexer2.errors.txt create mode 100644 tests/baselines/reference/indexer2.types diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index 53be1c903a3..10562cc57e4 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. Type '{ foo: string; }' is not assignable to type '{ id: number; }'. + Property 'id' is missing in type '{ foo: string; }'. ==== tests/cases/compiler/arrayCast.ts (1 errors) ==== @@ -9,6 +10,7 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. !!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2352: Property 'id' is missing in type '{ foo: string; }'. // Should succeed, as the {} element causes the type of the array to be {}[] <{ id: number; }[]>[{ foo: "s" }, {}]; \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatBug2.errors.txt b/tests/baselines/reference/assignmentCompatBug2.errors.txt index b90c470d771..15bf1111391 100644 --- a/tests/baselines/reference/assignmentCompatBug2.errors.txt +++ b/tests/baselines/reference/assignmentCompatBug2.errors.txt @@ -2,10 +2,10 @@ tests/cases/compiler/assignmentCompatBug2.ts(1,5): error TS2322: Type '{ a: numb Property 'b' is missing in type '{ a: number; }'. tests/cases/compiler/assignmentCompatBug2.ts(3,1): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'. Property 'b' is missing in type '{ a: number; }'. -tests/cases/compiler/assignmentCompatBug2.ts(15,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. - Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }'. -tests/cases/compiler/assignmentCompatBug2.ts(20,1): error TS2322: Type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. - Property 'g' is missing in type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }'. +tests/cases/compiler/assignmentCompatBug2.ts(15,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. + Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; }'. +tests/cases/compiler/assignmentCompatBug2.ts(20,1): error TS2322: Type '{ f: (n: number) => number; m: number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. + Property 'g' is missing in type '{ f: (n: number) => number; m: number; }'. tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; n: number; k: (a: any) => any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n: number; k: (a: any) => any; }'. @@ -33,16 +33,16 @@ tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2322: Type '{ f: (n: b3 = { ~~ -!!! error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. -!!! error TS2322: Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n?: number; k?(a: any): any; }'. +!!! error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. +!!! error TS2322: Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; }'. f: (n) => { return 0; }, g: (s) => { return 0; }, }; // error b3 = { ~~ -!!! error TS2322: Type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. -!!! error TS2322: Property 'g' is missing in type '{ f: (n: number) => number; m: number; n?: number; k?(a: any): any; }'. +!!! error TS2322: Type '{ f: (n: number) => number; m: number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. +!!! error TS2322: Property 'g' is missing in type '{ f: (n: number) => number; m: number; }'. f: (n) => { return 0; }, m: 0, }; // error diff --git a/tests/baselines/reference/assignmentCompatWithObjectMembers3.types b/tests/baselines/reference/assignmentCompatWithObjectMembers3.types index ff7ef23307d..85a7e59ffbc 100644 --- a/tests/baselines/reference/assignmentCompatWithObjectMembers3.types +++ b/tests/baselines/reference/assignmentCompatWithObjectMembers3.types @@ -51,13 +51,13 @@ var b: { foo: string; baz?: string } var a2: S2 = { foo: '' }; >a2 : S2 >S2 : S2 ->{ foo: '' } : { foo: string; bar?: string; } +>{ foo: '' } : { foo: string; } >foo : string var b2: T2 = { foo: '' }; >b2 : T2 >T2 : T2 ->{ foo: '' } : { foo: string; baz?: string; } +>{ foo: '' } : { foo: string; } >foo : string s = t; diff --git a/tests/baselines/reference/assignmentCompatability1.types b/tests/baselines/reference/assignmentCompatability1.types index 8bb4301b201..9949fc14bf5 100644 --- a/tests/baselines/reference/assignmentCompatability1.types +++ b/tests/baselines/reference/assignmentCompatability1.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability2.types b/tests/baselines/reference/assignmentCompatability2.types index 69a20b34dd7..16da45c7e35 100644 --- a/tests/baselines/reference/assignmentCompatability2.types +++ b/tests/baselines/reference/assignmentCompatability2.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability3.types b/tests/baselines/reference/assignmentCompatability3.types index 4b598fba84c..61279b9c7fa 100644 --- a/tests/baselines/reference/assignmentCompatability3.types +++ b/tests/baselines/reference/assignmentCompatability3.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability4.types b/tests/baselines/reference/assignmentCompatability4.types index 3d8e776ff72..f7e5801e9b3 100644 --- a/tests/baselines/reference/assignmentCompatability4.types +++ b/tests/baselines/reference/assignmentCompatability4.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability5.types b/tests/baselines/reference/assignmentCompatability5.types index 970c913955d..80eda3e510b 100644 --- a/tests/baselines/reference/assignmentCompatability5.types +++ b/tests/baselines/reference/assignmentCompatability5.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability6.types b/tests/baselines/reference/assignmentCompatability6.types index cf131600c41..5e9ae8c6a2f 100644 --- a/tests/baselines/reference/assignmentCompatability6.types +++ b/tests/baselines/reference/assignmentCompatability6.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; @@ -29,7 +29,7 @@ module __test2__ { >T : T >obj3 : interfaceWithOptional >interfaceWithOptional : interfaceWithOptional ->{ } : { one?: number; } +>{ } : {} export var __val__obj3 = obj3; >__val__obj3 : interfaceWithOptional diff --git a/tests/baselines/reference/assignmentCompatability7.types b/tests/baselines/reference/assignmentCompatability7.types index 5bb46428314..b7b2ab70566 100644 --- a/tests/baselines/reference/assignmentCompatability7.types +++ b/tests/baselines/reference/assignmentCompatability7.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; @@ -32,7 +32,7 @@ module __test2__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability8.types b/tests/baselines/reference/assignmentCompatability8.types index 21fa300a37d..1c009eea482 100644 --- a/tests/baselines/reference/assignmentCompatability8.types +++ b/tests/baselines/reference/assignmentCompatability8.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/assignmentCompatability9.types b/tests/baselines/reference/assignmentCompatability9.types index cc8df0387e7..a8235220bec 100644 --- a/tests/baselines/reference/assignmentCompatability9.types +++ b/tests/baselines/reference/assignmentCompatability9.types @@ -12,7 +12,7 @@ module __test1__ { >U : U >obj4 : interfaceWithPublicAndOptional >interfaceWithPublicAndOptional : interfaceWithPublicAndOptional ->{ one: 1 } : { one: number; two?: string; } +>{ one: 1 } : { one: number; } >one : number export var __val__obj4 = obj4; diff --git a/tests/baselines/reference/getterSetterNonAccessor.types b/tests/baselines/reference/getterSetterNonAccessor.types index 0c1be481b3a..f3e5d549cff 100644 --- a/tests/baselines/reference/getterSetterNonAccessor.types +++ b/tests/baselines/reference/getterSetterNonAccessor.types @@ -14,8 +14,8 @@ Object.defineProperty({}, "0", ({ >{} : {} >({ get: getFunc, set: setFunc, configurable: true }) : PropertyDescriptor >PropertyDescriptor : PropertyDescriptor ->({ get: getFunc, set: setFunc, configurable: true }) : { get: () => any; set: (v: any) => void; configurable: boolean; enumerable?: boolean; value?: any; writable?: boolean; } ->{ get: getFunc, set: setFunc, configurable: true } : { get: () => any; set: (v: any) => void; configurable: boolean; enumerable?: boolean; value?: any; writable?: boolean; } +>({ get: getFunc, set: setFunc, configurable: true }) : { get: () => any; set: (v: any) => void; configurable: boolean; } +>{ get: getFunc, set: setFunc, configurable: true } : { get: () => any; set: (v: any) => void; configurable: boolean; } get: getFunc, >get : () => any diff --git a/tests/baselines/reference/indexer2.errors.txt b/tests/baselines/reference/indexer2.errors.txt deleted file mode 100644 index 28020a570ed..00000000000 --- a/tests/baselines/reference/indexer2.errors.txt +++ /dev/null @@ -1,20 +0,0 @@ -tests/cases/compiler/indexer2.ts(6,25): error TS2352: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other. - Types of property 'hasOwnProperty' are incompatible. - Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean'. - Types of parameters 'v' and 'objectId' are incompatible. - Type 'string' is not assignable to type 'number'. - - -==== tests/cases/compiler/indexer2.ts (1 errors) ==== - interface IHeapObjectProperty {} - interface IDirectChildrenMap { - hasOwnProperty(objectId: number) : boolean; - [objectId: number] : IHeapObjectProperty[]; - } - var directChildrenMap = {}; - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other. -!!! error TS2352: Types of property 'hasOwnProperty' are incompatible. -!!! error TS2352: Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean'. -!!! error TS2352: Types of parameters 'v' and 'objectId' are incompatible. -!!! error TS2352: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/indexer2.types b/tests/baselines/reference/indexer2.types new file mode 100644 index 00000000000..7f1ccd41cb5 --- /dev/null +++ b/tests/baselines/reference/indexer2.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/indexer2.ts === +interface IHeapObjectProperty {} +>IHeapObjectProperty : IHeapObjectProperty + +interface IDirectChildrenMap { +>IDirectChildrenMap : IDirectChildrenMap + + hasOwnProperty(objectId: number) : boolean; +>hasOwnProperty : (objectId: number) => boolean +>objectId : number + + [objectId: number] : IHeapObjectProperty[]; +>objectId : number +>IHeapObjectProperty : IHeapObjectProperty +} +var directChildrenMap = {}; +>directChildrenMap : IDirectChildrenMap +>{} : IDirectChildrenMap +>IDirectChildrenMap : IDirectChildrenMap +>{} : { [x: number]: undefined; } + diff --git a/tests/baselines/reference/indexer2A.errors.txt b/tests/baselines/reference/indexer2A.errors.txt index f2314c5b49b..adf90fb743f 100644 --- a/tests/baselines/reference/indexer2A.errors.txt +++ b/tests/baselines/reference/indexer2A.errors.txt @@ -1,12 +1,7 @@ tests/cases/compiler/indexer2A.ts(4,5): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/compiler/indexer2A.ts(7,25): error TS2352: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other. - Types of property 'hasOwnProperty' are incompatible. - Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean'. - Types of parameters 'v' and 'objectId' are incompatible. - Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/indexer2A.ts (2 errors) ==== +==== tests/cases/compiler/indexer2A.ts (1 errors) ==== class IHeapObjectProperty { } class IDirectChildrenMap { // Decided to enforce a semicolon after declarations @@ -15,10 +10,4 @@ tests/cases/compiler/indexer2A.ts(7,25): error TS2352: Neither type '{ [x: numbe !!! error TS2391: Function implementation is missing or not immediately following the declaration. [objectId: number]: IHeapObjectProperty[] } - var directChildrenMap = {}; - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other. -!!! error TS2352: Types of property 'hasOwnProperty' are incompatible. -!!! error TS2352: Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean'. -!!! error TS2352: Types of parameters 'v' and 'objectId' are incompatible. -!!! error TS2352: Type 'string' is not assignable to type 'number'. \ No newline at end of file + var directChildrenMap = {}; \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 237a4b8e7f2..5f7c213a916 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -39,8 +39,8 @@ tests/cases/compiler/intTypeCheck.ts(146,5): error TS2322: Type 'boolean' is not tests/cases/compiler/intTypeCheck.ts(146,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(146,22): error TS2304: Cannot find name 'i4'. tests/cases/compiler/intTypeCheck.ts(147,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(152,5): error TS2322: Type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }' is not assignable to type 'i5'. - Property 'p' is missing in type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }'. +tests/cases/compiler/intTypeCheck.ts(152,5): error TS2322: Type '{}' is not assignable to type 'i5'. + Property 'p' is missing in type '{}'. tests/cases/compiler/intTypeCheck.ts(153,5): error TS2322: Type 'Object' is not assignable to type 'i5'. Property 'p' is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(154,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -313,8 +313,8 @@ tests/cases/compiler/intTypeCheck.ts(203,17): error TS2351: Cannot use 'new' wit var obj44: i5; var obj45: i5 = {}; ~~~~~ -!!! error TS2322: Type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }' is not assignable to type 'i5'. -!!! error TS2322: Property 'p' is missing in type '{ p1?: any; p2?: string; p4?(): any; p5?(): void; p7?(pa1: any, pa2: any): void; }'. +!!! error TS2322: Type '{}' is not assignable to type 'i5'. +!!! error TS2322: Property 'p' is missing in type '{}'. var obj46: i5 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i5'. diff --git a/tests/baselines/reference/interfaceContextualType.types b/tests/baselines/reference/interfaceContextualType.types index 412a48cfbda..3078ecfdfa4 100644 --- a/tests/baselines/reference/interfaceContextualType.types +++ b/tests/baselines/reference/interfaceContextualType.types @@ -34,27 +34,27 @@ class Bug { >{} : { [x: string]: undefined; } this.values['comments'] = { italic: true }; ->this.values['comments'] = { italic: true } : { italic: boolean; bold?: boolean; } +>this.values['comments'] = { italic: true } : { italic: boolean; } >this.values['comments'] : IOptions >this.values : IMap >this : Bug >values : IMap ->{ italic: true } : { italic: boolean; bold?: boolean; } +>{ italic: true } : { italic: boolean; } >italic : boolean } shouldBeOK() { >shouldBeOK : () => void this.values = { ->this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; bold?: boolean; }; comments: { italic: boolean; bold?: boolean; }; } +>this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } >this.values : IMap >this : Bug >values : IMap ->{ comments: { italic: true } } : { [x: string]: { italic: boolean; bold?: boolean; }; comments: { italic: boolean; bold?: boolean; }; } +>{ comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } comments: { italic: true } ->comments : { italic: boolean; bold?: boolean; } ->{ italic: true } : { italic: boolean; bold?: boolean; } +>comments : { italic: boolean; } +>{ italic: true } : { italic: boolean; } >italic : boolean }; diff --git a/tests/baselines/reference/objectLitGetterSetter.types b/tests/baselines/reference/objectLitGetterSetter.types index bbb7ee10140..92decfd4068 100644 --- a/tests/baselines/reference/objectLitGetterSetter.types +++ b/tests/baselines/reference/objectLitGetterSetter.types @@ -11,8 +11,8 @@ >obj : {} >({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : PropertyDescriptor >PropertyDescriptor : PropertyDescriptor ->({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : { get: () => number; set: (v: any) => void; configurable?: boolean; enumerable?: boolean; value?: any; writable?: boolean; } ->{ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } } : { get: () => number; set: (v: any) => void; configurable?: boolean; enumerable?: boolean; value?: any; writable?: boolean; } +>({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : { get: () => number; set: (v: any) => void; } +>{ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } } : { get: () => number; set: (v: any) => void; } get: function () { >get : () => number diff --git a/tests/baselines/reference/objectLiteralContextualTyping.types b/tests/baselines/reference/objectLiteralContextualTyping.types index 495e8df1438..32c9e91b2c7 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.types +++ b/tests/baselines/reference/objectLiteralContextualTyping.types @@ -24,7 +24,7 @@ var x = foo({ name: "Sprocket" }); >x : string >foo({ name: "Sprocket" }) : string >foo : { (item: Item): string; (item: any): number; } ->{ name: "Sprocket" } : { name: string; description?: string; } +>{ name: "Sprocket" } : { name: string; } >name : string var x: string; @@ -74,7 +74,7 @@ var b = bar({}); >b : {} >bar({}) : {} >bar : (param: { x?: T; }) => T ->{} : { x?: {}; } +>{} : {} var b: {}; >b : {} diff --git a/tests/baselines/reference/optionalAccessorsInInterface1.types b/tests/baselines/reference/optionalAccessorsInInterface1.types index f1dcd854f75..c426cdba178 100644 --- a/tests/baselines/reference/optionalAccessorsInInterface1.types +++ b/tests/baselines/reference/optionalAccessorsInInterface1.types @@ -21,7 +21,7 @@ defineMyProperty({}, "name", { get: function () { return 5; } }); >defineMyProperty({}, "name", { get: function () { return 5; } }) : any >defineMyProperty : (o: any, p: string, attributes: MyPropertyDescriptor) => any >{} : {} ->{ get: function () { return 5; } } : { get: () => number; set?(v: any): void; } +>{ get: function () { return 5; } } : { get: () => number; } >get : () => number >function () { return 5; } : () => number @@ -47,7 +47,7 @@ defineMyProperty2({}, "name", { get: function () { return 5; } }); >defineMyProperty2({}, "name", { get: function () { return 5; } }) : any >defineMyProperty2 : (o: any, p: string, attributes: MyPropertyDescriptor2) => any >{} : {} ->{ get: function () { return 5; } } : { get: () => number; set?: (v: any) => void; } +>{ get: function () { return 5; } } : { get: () => number; } >get : () => number >function () { return 5; } : () => number diff --git a/tests/baselines/reference/optionalPropertiesTest.errors.txt b/tests/baselines/reference/optionalPropertiesTest.errors.txt index a904911e232..a4b721e92ef 100644 --- a/tests/baselines/reference/optionalPropertiesTest.errors.txt +++ b/tests/baselines/reference/optionalPropertiesTest.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/optionalPropertiesTest.ts(14,1): error TS2322: Type '{ name: string; print?(): void; }' is not assignable to type 'IFoo'. - Property 'id' is missing in type '{ name: string; print?(): void; }'. +tests/cases/compiler/optionalPropertiesTest.ts(14,1): error TS2322: Type '{ name: string; }' is not assignable to type 'IFoo'. + Property 'id' is missing in type '{ name: string; }'. tests/cases/compiler/optionalPropertiesTest.ts(25,5): error TS2322: Type '{}' is not assignable to type 'i1'. Property 'M' is missing in type '{}'. tests/cases/compiler/optionalPropertiesTest.ts(26,5): error TS2322: Type '{}' is not assignable to type 'i3'. @@ -24,8 +24,8 @@ tests/cases/compiler/optionalPropertiesTest.ts(40,1): error TS2322: Type 'i2' is foo = { id: 1234, name: "test" }; // Ok foo = { name: "test" }; // Error, id missing ~~~ -!!! error TS2322: Type '{ name: string; print?(): void; }' is not assignable to type 'IFoo'. -!!! error TS2322: Property 'id' is missing in type '{ name: string; print?(): void; }'. +!!! error TS2322: Type '{ name: string; }' is not assignable to type 'IFoo'. +!!! error TS2322: Property 'id' is missing in type '{ name: string; }'. foo = {id: 1234, print:()=>{}} // Ok var s = foo.name || "default"; diff --git a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types index f597c93bdda..311cf971b61 100644 --- a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types +++ b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries.types @@ -105,17 +105,17 @@ var a1 = a.a({}); >a.a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } >a : A >a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } ->{} : { r?: any; } +>{} : {} var a1 = a({}); >a1 : Opt3 >a({}) : Opt3 >a : A ->{} : { r?: any; } +>{} : {} var a1 = new a({}); >a1 : Opt3 >new a({}) : Opt3 >a : A ->{} : { r?: any; } +>{} : {} diff --git a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types index a854c159e0c..e67ff2f8de6 100644 --- a/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types +++ b/tests/baselines/reference/overloadBindingAcrossDeclarationBoundaries2.types @@ -108,17 +108,17 @@ var a1 = a.a({}); >a.a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } >a : A >a : { (o: Opt1): Opt1; (o: Opt2): Opt2; (o: Opt3): Opt3; (o: Opt4): Opt4; } ->{} : { r?: any; } +>{} : {} var a1 = a({}); >a1 : Opt3 >a({}) : Opt3 >a : A ->{} : { r?: any; } +>{} : {} var a1 = new a({}); >a1 : Opt3 >new a({}) : Opt3 >a : A ->{} : { r?: any; } +>{} : {} diff --git a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types index 661aa3c3cbb..27fcd05bb28 100644 --- a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types +++ b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types @@ -23,16 +23,16 @@ interface IMenuItem { var menuData: IMenuItem[] = [ >menuData : IMenuItem[] >IMenuItem : IMenuItem ->[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : ({ "id": string; "type": string; "link": string; "icon": string; classes?: string; text?: string; } | { "id": string; "type": string; "link": string; "text": string; classes?: string; icon?: string; })[] +>[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : ({ "id": string; "type": string; "link": string; "icon": string; } | { "id": string; "type": string; "link": string; "text": string; })[] { ->{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; classes?: string; text?: string; } +>{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; } "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { ->{ "id": "productName", "type": "default", "link": "", "text": "Product Name" } : { "id": string; "type": string; "link": string; "text": string; classes?: string; icon?: string; } +>{ "id": "productName", "type": "default", "link": "", "text": "Product Name" } : { "id": string; "type": string; "link": string; "text": string; } "id": "productName", "type": "default", diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 9e4f5ea1d1b..a3347457b8a 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -1317,11 +1317,11 @@ compiled2({ epithet: "stooge" }); >epithet : string _.templateSettings = { ->_.templateSettings = { interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; evaluate?: RegExp; escape?: RegExp; } +>_.templateSettings = { interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; } >_.templateSettings : Underscore.TemplateSettings >_ : Underscore.Static >templateSettings : Underscore.TemplateSettings ->{ interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; evaluate?: RegExp; escape?: RegExp; } +>{ interpolate: /\{\{(.+?)\}\}/g} : { interpolate: RegExp; } interpolate: /\{\{(.+?)\}\}/g >interpolate : RegExp @@ -1347,7 +1347,7 @@ _.template("Using 'with': <%= data.answer %>", { answer: 'no' }, { variable: 'da >template : { (templateString: string): (data: any) => string; (templateString: string, data: any, settings?: Underscore.TemplateSettings): string; } >{ answer: 'no' } : { answer: string; } >answer : string ->{ variable: 'data' } : { variable: string; evaluate?: RegExp; interpolate?: RegExp; escape?: RegExp; } +>{ variable: 'data' } : { variable: string; } >variable : string === tests/cases/compiler/underscoreTest1_underscore.ts === From 95a314a754f70271682e06b2ae82f21a54130e07 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 24 Jan 2015 17:21:49 -0800 Subject: [PATCH 51/71] Correct support for type guards with unions containing enums --- src/compiler/checker.ts | 53 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a606a3f00fd..f5592560ed4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -107,6 +107,21 @@ module ts { var diagnostics: Diagnostic[] = []; var diagnosticsModified: boolean = false; + var primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = { + "string": { + type: stringType, + flags: TypeFlags.StringLike + }, + "number": { + type: numberType, + flags: TypeFlags.NumberLike + }, + "boolean": { + type: booleanType, + flags: TypeFlags.Boolean + } + }; + function addDiagnostic(diagnostic: Diagnostic) { diagnostics.push(diagnostic); diagnosticsModified = true; @@ -4454,12 +4469,15 @@ module ts { Debug.fail("should not get here"); } - // Remove one or more primitive types from a union type - function subtractPrimitiveTypes(type: Type, subtractMask: TypeFlags): Type { + // For a union type, remove all constituent types for which the given flags have the given state + function removeTypesFromUnionType(type: Type, maskFlags: TypeFlags, maskState: boolean): Type { if (type.flags & TypeFlags.Union) { var types = (type).types; - if (forEach(types, t => t.flags & subtractMask)) { - return getUnionType(filter(types, t => !(t.flags & subtractMask))); + if (forEach(types, t => !(t.flags & maskFlags) !== maskState)) { + var reducedType = getUnionType(filter(types, t => !(t.flags & maskFlags) === maskState)); + if (reducedType !== emptyObjectType) { + return reducedType; + } } } return type; @@ -4635,8 +4653,8 @@ module ts { // Stop at the first containing function or module declaration break loop; } - // Use narrowed type if it is a subtype and construct contains no assignments to variable - if (narrowedType !== type && isTypeSubtypeOf(narrowedType, type)) { + // Use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { if (isVariableAssignedWithin(symbol, node)) { break; } @@ -4656,20 +4674,29 @@ module ts { if (left.expression.kind !== SyntaxKind.Identifier || getResolvedSymbol(left.expression) !== symbol) { return type; } - var t = right.text; - var checkType: Type = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + var typeInfo = primitiveTypeInfo[right.text]; if (expr.operator === SyntaxKind.ExclamationEqualsEqualsToken) { assumeTrue = !assumeTrue; } if (assumeTrue) { - // The assumed result is true. If check was for a primitive type, that type is the narrowed type. Otherwise we can - // remove the primitive types from the narrowed type. - return checkType === emptyObjectType ? subtractPrimitiveTypes(type, TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean) : checkType; + // Assumed result is true. If check was not for a primitive type, remove all primitive types + if (!typeInfo) { + return removeTypesFromUnionType(type, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean, true); + } + // Check was for a primitive type, return that primitive type if it is a subtype + if (isTypeSubtypeOf(typeInfo.type, type)) { + return typeInfo.type; + } + // Otherwise, remove all types that aren't of the primitive type kind + return removeTypesFromUnionType(type, typeInfo.flags, false); } else { - // The assumed result is false. If check was for a primitive type we can remove that type from the narrowed type. + // Assumed result is false. If check was for a primitive type, remove that primitive type + if (typeInfo) { + return removeTypesFromUnionType(type, typeInfo.flags, true); + } // Otherwise we don't have enough information to do anything. - return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + return type; } } From 7f63180b64ed83877416ac42165c98180a7907e9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 24 Jan 2015 17:23:22 -0800 Subject: [PATCH 52/71] Adding tests --- .../reference/TypeGuardWithEnumUnion.js | 77 +++++++++++++++ .../reference/TypeGuardWithEnumUnion.types | 96 +++++++++++++++++++ .../typeGuards/TypeGuardWithEnumUnion.ts | 35 +++++++ 3 files changed, 208 insertions(+) create mode 100644 tests/baselines/reference/TypeGuardWithEnumUnion.js create mode 100644 tests/baselines/reference/TypeGuardWithEnumUnion.types create mode 100644 tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.js b/tests/baselines/reference/TypeGuardWithEnumUnion.js new file mode 100644 index 00000000000..f582c70857a --- /dev/null +++ b/tests/baselines/reference/TypeGuardWithEnumUnion.js @@ -0,0 +1,77 @@ +//// [TypeGuardWithEnumUnion.ts] +enum Color { R, G, B } + +function f1(x: Color | string) { + if (typeof x === "number") { + var y = x; + var y: Color; + } + else { + var z = x; + var z: string; + } +} + +function f2(x: Color | string | string[]) { + if (typeof x === "object") { + var y = x; + var y: string[]; + } + if (typeof x === "number") { + var z = x; + var z: Color; + } + else { + var w = x; + var w: string | string[]; + } + if (typeof x === "string") { + var a = x; + var a: string; + } + else { + var b = x; + var b: Color | string[]; + } +} + + +//// [TypeGuardWithEnumUnion.js] +var Color; +(function (Color) { + Color[Color["R"] = 0] = "R"; + Color[Color["G"] = 1] = "G"; + Color[Color["B"] = 2] = "B"; +})(Color || (Color = {})); +function f1(x) { + if (typeof x === "number") { + var y = x; + var y; + } + else { + var z = x; + var z; + } +} +function f2(x) { + if (typeof x === "object") { + var y = x; + var y; + } + if (typeof x === "number") { + var z = x; + var z; + } + else { + var w = x; + var w; + } + if (typeof x === "string") { + var a = x; + var a; + } + else { + var b = x; + var b; + } +} diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types b/tests/baselines/reference/TypeGuardWithEnumUnion.types new file mode 100644 index 00000000000..9296e0ad04e --- /dev/null +++ b/tests/baselines/reference/TypeGuardWithEnumUnion.types @@ -0,0 +1,96 @@ +=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts === +enum Color { R, G, B } +>Color : Color +>R : Color +>G : Color +>B : Color + +function f1(x: Color | string) { +>f1 : (x: string | Color) => void +>x : string | Color +>Color : Color + + if (typeof x === "number") { +>typeof x === "number" : boolean +>typeof x : string +>x : string | Color + + var y = x; +>y : Color +>x : Color + + var y: Color; +>y : Color +>Color : Color + } + else { + var z = x; +>z : string +>x : string + + var z: string; +>z : string + } +} + +function f2(x: Color | string | string[]) { +>f2 : (x: string | string[] | Color) => void +>x : string | string[] | Color +>Color : Color + + if (typeof x === "object") { +>typeof x === "object" : boolean +>typeof x : string +>x : string | string[] | Color + + var y = x; +>y : string[] +>x : string[] + + var y: string[]; +>y : string[] + } + if (typeof x === "number") { +>typeof x === "number" : boolean +>typeof x : string +>x : string | string[] | Color + + var z = x; +>z : Color +>x : Color + + var z: Color; +>z : Color +>Color : Color + } + else { + var w = x; +>w : string | string[] +>x : string | string[] + + var w: string | string[]; +>w : string | string[] + } + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | string[] | Color + + var a = x; +>a : string +>x : string + + var a: string; +>a : string + } + else { + var b = x; +>b : string[] | Color +>x : string[] | Color + + var b: Color | string[]; +>b : string[] | Color +>Color : Color + } +} + diff --git a/tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts b/tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts new file mode 100644 index 00000000000..3d105e91502 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts @@ -0,0 +1,35 @@ +enum Color { R, G, B } + +function f1(x: Color | string) { + if (typeof x === "number") { + var y = x; + var y: Color; + } + else { + var z = x; + var z: string; + } +} + +function f2(x: Color | string | string[]) { + if (typeof x === "object") { + var y = x; + var y: string[]; + } + if (typeof x === "number") { + var z = x; + var z: Color; + } + else { + var w = x; + var w: string | string[]; + } + if (typeof x === "string") { + var a = x; + var a: string; + } + else { + var b = x; + var b: Color | string[]; + } +} From e5e06d8ca52cc1c6361436565e62fc97f206dada Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 25 Jan 2015 16:14:20 -0800 Subject: [PATCH 53/71] Allow union types containing primtives as first argument in instanceof --- src/compiler/checker.ts | 2 +- src/compiler/types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f5592560ed4..d3e119700b5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6776,7 +6776,7 @@ module ts { // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { + if (isTypeOfKind(leftType, TypeFlags.Primitive)) { error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b8c842641d7..207006cdaf8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1286,6 +1286,7 @@ module ts { Unwidened = 0x00020000, // Unwidened type (is or contains Undefined or Null type) Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, + Primitive = String | Number | Boolean | Void | Undefined | Null | StringLiteral | Enum, StringLike = String | StringLiteral, NumberLike = Number | Enum, ObjectType = Class | Interface | Reference | Tuple | Anonymous, From 0410394de04ad02c06054aee5a554cb7655d6804 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 25 Jan 2015 16:25:38 -0800 Subject: [PATCH 54/71] Modifying test --- .../reference/instanceofOperatorWithLHSIsObject.js | 7 ++++++- .../reference/instanceofOperatorWithLHSIsObject.types | 10 ++++++++++ .../instanceofOperatorWithLHSIsObject.ts | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/instanceofOperatorWithLHSIsObject.js b/tests/baselines/reference/instanceofOperatorWithLHSIsObject.js index 5ccf195cd88..c687027ae9b 100644 --- a/tests/baselines/reference/instanceofOperatorWithLHSIsObject.js +++ b/tests/baselines/reference/instanceofOperatorWithLHSIsObject.js @@ -7,10 +7,13 @@ var x2: Function; var a: {}; var b: Object; var c: C; +var d: string | C; var r1 = a instanceof x1; var r2 = b instanceof x2; -var r3 = c instanceof x1; +var r3 = c instanceof x1; +var r4 = d instanceof x1; + //// [instanceofOperatorWithLHSIsObject.js] var C = (function () { @@ -23,6 +26,8 @@ var x2; var a; var b; var c; +var d; var r1 = a instanceof x1; var r2 = b instanceof x2; var r3 = c instanceof x1; +var r4 = d instanceof x1; diff --git a/tests/baselines/reference/instanceofOperatorWithLHSIsObject.types b/tests/baselines/reference/instanceofOperatorWithLHSIsObject.types index 26aea98028e..9962a23dced 100644 --- a/tests/baselines/reference/instanceofOperatorWithLHSIsObject.types +++ b/tests/baselines/reference/instanceofOperatorWithLHSIsObject.types @@ -20,6 +20,10 @@ var c: C; >c : C >C : C +var d: string | C; +>d : string | C +>C : C + var r1 = a instanceof x1; >r1 : boolean >a instanceof x1 : boolean @@ -38,3 +42,9 @@ var r3 = c instanceof x1; >c : C >x1 : any +var r4 = d instanceof x1; +>r4 : boolean +>d instanceof x1 : boolean +>d : string | C +>x1 : any + diff --git a/tests/cases/conformance/expressions/binaryOperators/instanceofOperator/instanceofOperatorWithLHSIsObject.ts b/tests/cases/conformance/expressions/binaryOperators/instanceofOperator/instanceofOperatorWithLHSIsObject.ts index 285335e40e7..6b88cd39f2a 100644 --- a/tests/cases/conformance/expressions/binaryOperators/instanceofOperator/instanceofOperatorWithLHSIsObject.ts +++ b/tests/cases/conformance/expressions/binaryOperators/instanceofOperator/instanceofOperatorWithLHSIsObject.ts @@ -6,7 +6,9 @@ var x2: Function; var a: {}; var b: Object; var c: C; +var d: string | C; var r1 = a instanceof x1; var r2 = b instanceof x2; -var r3 = c instanceof x1; \ No newline at end of file +var r3 = c instanceof x1; +var r4 = d instanceof x1; From 75404a7e00cc22a8873ec6eb9c7d92d6db7420c2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 26 Jan 2015 13:09:23 -0800 Subject: [PATCH 55/71] Addressing CR feedback --- src/compiler/checker.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d3e119700b5..336bfab5ccb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4469,14 +4469,16 @@ module ts { Debug.fail("should not get here"); } - // For a union type, remove all constituent types for which the given flags have the given state - function removeTypesFromUnionType(type: Type, maskFlags: TypeFlags, maskState: boolean): Type { + // For a union type, remove all constituent types for that are of the given type kind (when isOfTypeKind is true) + // or not of the given type kind (when isOfTypeKind is false) + function removeTypesFromUnionType(type: Type, typeKind: TypeFlags, isOfTypeKind: boolean): Type { if (type.flags & TypeFlags.Union) { var types = (type).types; - if (forEach(types, t => !(t.flags & maskFlags) !== maskState)) { - var reducedType = getUnionType(filter(types, t => !(t.flags & maskFlags) === maskState)); - if (reducedType !== emptyObjectType) { - return reducedType; + if (forEach(types, t => !!(t.flags & typeKind) === isOfTypeKind)) { + // Above we checked if we have anything to remove, now use the opposite test to do the removal + var narrowedType = getUnionType(filter(types, t => !(t.flags & typeKind) === isOfTypeKind)); + if (narrowedType !== emptyObjectType) { + return narrowedType; } } } @@ -4687,7 +4689,8 @@ module ts { if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; } - // Otherwise, remove all types that aren't of the primitive type kind + // Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is + // union of enum types and other types. return removeTypesFromUnionType(type, typeInfo.flags, false); } else { @@ -4757,7 +4760,8 @@ module ts { return type; } - // Narrow the given type based on the given expression having the assumed boolean value + // Narrow the given type based on the given expression having the assumed boolean value. The returned type + // will be a subtype or the same type as the argument. function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type { switch (expr.kind) { case SyntaxKind.ParenthesizedExpression: From a298835f01b660e7b44ea526fde8060fa03779bb Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 26 Jan 2015 16:23:21 -0800 Subject: [PATCH 56/71] Addressing CR feedback --- src/compiler/checker.ts | 15 +++++++++------ src/compiler/types.ts | 42 ++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 431d81696a1..9e88a6cb01a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -66,8 +66,8 @@ module ts { var numberType = createIntrinsicType(TypeFlags.Number, "number"); var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean"); var voidType = createIntrinsicType(TypeFlags.Void, "void"); - var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefined, "undefined"); - var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefined, "null"); + var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined"); + var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null"); var unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); var resolvingType = createIntrinsicType(TypeFlags.Any, "__resolving__"); @@ -2807,6 +2807,9 @@ module ts { } } + // This function is used to propagate widening flags when creating new object types references and union types. + // It is only necessary to do so if a constituent type might be the undefined type, the null type, or the type + // of an object literal (since those types have widening related information we need to track). function getWideningFlagsOfTypes(types: Type[]): TypeFlags { var result: TypeFlags = 0; for (var i = 0; i < types.length; i++) { @@ -4111,7 +4114,7 @@ module ts { var symbol = createSymbol(p.flags | SymbolFlags.Transient, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; - symbol.type = getWidenedType(getTypeOfSymbol(p)); + symbol.type = widenedType; symbol.target = p; if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration; p = symbol; @@ -4160,7 +4163,7 @@ module ts { var errorReported = false; forEach(getPropertiesOfObjectType(type), p => { var t = getTypeOfSymbol(p); - if (t.flags & TypeFlags.ContainsUndefined) { + if (t.flags & TypeFlags.ContainsUndefinedOrNull) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -4204,7 +4207,7 @@ module ts { } function reportErrorsFromWidening(declaration: Declaration, type: Type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.ContainsUndefined) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.ContainsUndefinedOrNull) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); @@ -5464,7 +5467,7 @@ module ts { var stringIndexType = getIndexType(IndexKind.String); var numberIndexType = getIndexType(IndexKind.Number); var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsLiteral | (typeFlags & TypeFlags.ContainsUndefined); + result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsUndefinedOrNull); return result; function getIndexType(kind: IndexKind) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 474fdf30fed..ad20efcef3e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1266,32 +1266,32 @@ module ts { } export const enum TypeFlags { - Any = 0x00000001, - String = 0x00000002, - Number = 0x00000004, - Boolean = 0x00000008, - Void = 0x00000010, - Undefined = 0x00000020, - Null = 0x00000040, - Enum = 0x00000080, // Enum type - StringLiteral = 0x00000100, // String literal type - TypeParameter = 0x00000200, // Type parameter - Class = 0x00000400, // Class - Interface = 0x00000800, // Interface - Reference = 0x00001000, // Generic type reference - Tuple = 0x00002000, // Tuple - Union = 0x00004000, // Union - Anonymous = 0x00008000, // Anonymous - FromSignature = 0x00010000, // Created for signature assignment check - ObjectLiteral = 0x00020000, // Originates in an object literal - ContainsUndefined = 0x00040000, // Type is or contains Undefined or Null type - ContainsLiteral = 0x00080000, // Type is or contains object literal type + Any = 0x00000001, + String = 0x00000002, + Number = 0x00000004, + Boolean = 0x00000008, + Void = 0x00000010, + Undefined = 0x00000020, + Null = 0x00000040, + Enum = 0x00000080, // Enum type + StringLiteral = 0x00000100, // String literal type + TypeParameter = 0x00000200, // Type parameter + Class = 0x00000400, // Class + Interface = 0x00000800, // Interface + Reference = 0x00001000, // Generic type reference + Tuple = 0x00002000, // Tuple + Union = 0x00004000, // Union + Anonymous = 0x00008000, // Anonymous + FromSignature = 0x00010000, // Created for signature assignment check + ObjectLiteral = 0x00020000, // Originates in an object literal + ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type + ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, StringLike = String | StringLiteral, NumberLike = Number | Enum, ObjectType = Class | Interface | Reference | Tuple | Anonymous, - RequiresWidening = ContainsUndefined | ContainsLiteral + RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral } // Properties common to all types From 35b2038af75bd80e4569c4896e50776e1ff0350a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 26 Jan 2015 16:46:52 -0800 Subject: [PATCH 57/71] Addressing CR feedback --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 336bfab5ccb..0c4d6c2da73 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4469,7 +4469,7 @@ module ts { Debug.fail("should not get here"); } - // For a union type, remove all constituent types for that are of the given type kind (when isOfTypeKind is true) + // For a union type, remove all constituent types that are of the given type kind (when isOfTypeKind is true) // or not of the given type kind (when isOfTypeKind is false) function removeTypesFromUnionType(type: Type, typeKind: TypeFlags, isOfTypeKind: boolean): Type { if (type.flags & TypeFlags.Union) { @@ -4683,7 +4683,7 @@ module ts { if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { - return removeTypesFromUnionType(type, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean, true); + return removeTypesFromUnionType(type, /*typeKind*/ TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean, /*isOfTypeKind*/ true); } // Check was for a primitive type, return that primitive type if it is a subtype if (isTypeSubtypeOf(typeInfo.type, type)) { @@ -4691,12 +4691,12 @@ module ts { } // Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is // union of enum types and other types. - return removeTypesFromUnionType(type, typeInfo.flags, false); + return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ false); } else { // Assumed result is false. If check was for a primitive type, remove that primitive type if (typeInfo) { - return removeTypesFromUnionType(type, typeInfo.flags, true); + return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ true); } // Otherwise we don't have enough information to do anything. return type; From ca8c446d3f62769ac3a739a54164cccefe150142 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 26 Jan 2015 16:48:53 -0800 Subject: [PATCH 58/71] Use transient symbols when computing the indexers for object literals --- src/compiler/checker.ts | 20 ++++++++++++------- .../objectLiteralIndexerNoImplicitAny.js | 13 ++++++++++++ .../objectLiteralIndexerNoImplicitAny.types | 16 +++++++++++++++ .../objectLiteralIndexerNoImplicitAny.ts | 8 ++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/objectLiteralIndexerNoImplicitAny.js create mode 100644 tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types create mode 100644 tests/cases/compiler/objectLiteralIndexerNoImplicitAny.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fd85a477bd4..e5624fb8916 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5441,7 +5441,8 @@ module ts { // Grammar checking checkGrammarObjectLiteralExpression(node); - var properties: SymbolTable = {}; + var propertiesTable: SymbolTable = {}; + var propertiesArray: Symbol[] = []; var contextualType = getContextualType(node); var typeFlags: TypeFlags; @@ -5486,8 +5487,9 @@ module ts { } if (!hasDynamicName(memberDecl)) { - properties[member.name] = member; + propertiesTable[member.name] = member; } + propertiesArray.push(member); } // If object literal is contextually (but not inferentially) typed, copy missing optional properties from @@ -5495,25 +5497,29 @@ module ts { // were omitted. There is no need to create new property objects as nothing in them needs to change. if (contextualType && !isInferentialContext(contextualMapper)) { forEach(getPropertiesOfObjectType(contextualType), p => { - if (p.flags & SymbolFlags.Optional && !hasProperty(properties, p.name)) { - properties[p.name] = p; + if (p.flags & SymbolFlags.Optional && !hasProperty(propertiesTable, p.name)) { + propertiesTable[p.name] = p; } }); } var stringIndexType = getIndexType(IndexKind.String); var numberIndexType = getIndexType(IndexKind.Number); - var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); + var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); result.flags |= (typeFlags & TypeFlags.Unwidened); return result; function getIndexType(kind: IndexKind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { var propTypes: Type[] = []; - for (var i = 0; i < node.properties.length; i++) { + for (var i = 0; i < propertiesArray.length; i++) { var propertyDecl = node.properties[i]; if (kind === IndexKind.String || isNumericName(propertyDecl.name)) { - var type = getTypeOfSymbol(getSymbolOfNode(propertyDecl)); + // Do not call getSymbolOfNode(propertyDecl), as that will get the + // original symbol for the node. We actually want to get the symbol + // created by checkObjectLiteral, since that will be appropriately + // contextually typed and resolved. + var type = getTypeOfSymbol(propertiesArray[i]); if (!contains(propTypes, type)) { propTypes.push(type); } diff --git a/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.js b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.js new file mode 100644 index 00000000000..2cbb76b200d --- /dev/null +++ b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.js @@ -0,0 +1,13 @@ +//// [objectLiteralIndexerNoImplicitAny.ts] +interface I { + [s: string]: any; +} + +var x: I = { + p: null +} + +//// [objectLiteralIndexerNoImplicitAny.js] +var x = { + p: null +}; diff --git a/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types new file mode 100644 index 00000000000..14bcc6f5b62 --- /dev/null +++ b/tests/baselines/reference/objectLiteralIndexerNoImplicitAny.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/objectLiteralIndexerNoImplicitAny.ts === +interface I { +>I : I + + [s: string]: any; +>s : string +} + +var x: I = { +>x : I +>I : I +>{ p: null} : { [x: string]: null; p: null; } + + p: null +>p : null +} diff --git a/tests/cases/compiler/objectLiteralIndexerNoImplicitAny.ts b/tests/cases/compiler/objectLiteralIndexerNoImplicitAny.ts new file mode 100644 index 00000000000..c21d8df52fc --- /dev/null +++ b/tests/cases/compiler/objectLiteralIndexerNoImplicitAny.ts @@ -0,0 +1,8 @@ +//@noImplicitAny: true +interface I { + [s: string]: any; +} + +var x: I = { + p: null +} \ No newline at end of file From 93dbcf006f3855c20f02e587970add1744cf32d1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 26 Jan 2015 18:42:17 -0800 Subject: [PATCH 59/71] Contextually type parameters in super calls using type arguments on the base class. --- src/compiler/checker.ts | 31 +++++++++++++-- .../superCallArgsMustMatch.errors.txt | 29 ++++++++++++++ .../reference/superCallArgsMustMatch.types | 38 ------------------- .../superCallParameterContextualTyping1.js | 35 +++++++++++++++++ .../superCallParameterContextualTyping1.types | 34 +++++++++++++++++ ...rCallParameterContextualTyping2.errors.txt | 17 +++++++++ .../superCallParameterContextualTyping2.js | 34 +++++++++++++++++ .../superCallParameterContextualTyping1.ts | 11 ++++++ .../superCallParameterContextualTyping2.ts | 11 ++++++ ...ntextuallyTypedArrowFunctionInSuperCall.ts | 20 ++++++++++ 10 files changed, 219 insertions(+), 41 deletions(-) create mode 100644 tests/baselines/reference/superCallArgsMustMatch.errors.txt delete mode 100644 tests/baselines/reference/superCallArgsMustMatch.types create mode 100644 tests/baselines/reference/superCallParameterContextualTyping1.js create mode 100644 tests/baselines/reference/superCallParameterContextualTyping1.types create mode 100644 tests/baselines/reference/superCallParameterContextualTyping2.errors.txt create mode 100644 tests/baselines/reference/superCallParameterContextualTyping2.js create mode 100644 tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping1.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts create mode 100644 tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e5624fb8916..6887421ba32 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5978,11 +5978,36 @@ module ts { return args; } + // In a 'super' call, type arguments are not provided within the CallExpression node itself. + // Instead, they must be fetched from the class declaration's base type node. + function getEffectiveTypeArguments(callExpression: CallExpression): TypeNode[] { + if (callExpression.expression.kind === SyntaxKind.SuperKeyword) { + // TODO (drosen): 1) Discuss if checking needs to be done at this point. + // 2) Have a test where type arguments are not provided on the base class. + // 3) Have a test where the base class is not generic. + var containingClass = getAncestor(callExpression, SyntaxKind.ClassDeclaration); + var baseClassTypeNode = getClassBaseTypeNode(containingClass); + return baseClassTypeNode.typeArguments; + } + else { + // Ordinary case - simple function invocation. + return (callExpression).typeArguments; + } + } + function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature { var isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; - var typeArguments = isTaggedTemplate ? undefined : (node).typeArguments; - forEach(typeArguments, checkSourceElement); + var typeArguments: TypeNode[]; + + if (!isTaggedTemplate) { + typeArguments = getEffectiveTypeArguments(node); + + // We already perform checking on the type arguments on the class declaration itself. + if ((node).expression.kind !== SyntaxKind.SuperKeyword) { + forEach(typeArguments, checkSourceElement); + } + } var candidates = candidatesOutArray || []; // collectCandidates fills up the candidates array directly @@ -6248,7 +6273,7 @@ module ts { // Another error has already been reported return resolveErrorCall(node); } - + // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including call signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith diff --git a/tests/baselines/reference/superCallArgsMustMatch.errors.txt b/tests/baselines/reference/superCallArgsMustMatch.errors.txt new file mode 100644 index 00000000000..e9a665acd1f --- /dev/null +++ b/tests/baselines/reference/superCallArgsMustMatch.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/superCallArgsMustMatch.ts(15,15): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + +==== tests/cases/compiler/superCallArgsMustMatch.ts (1 errors) ==== + class T5{ + + public foo: T; + + constructor(public bar: T) { } + + } + + + + class T6 extends T5{ + + constructor() { + + super("hi"); // Should error, base constructor has type T for first arg, which is fixed as number in the extends clause + ~~~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + + var x: number = this.foo; + + } + + } + + \ No newline at end of file diff --git a/tests/baselines/reference/superCallArgsMustMatch.types b/tests/baselines/reference/superCallArgsMustMatch.types deleted file mode 100644 index c2019881d94..00000000000 --- a/tests/baselines/reference/superCallArgsMustMatch.types +++ /dev/null @@ -1,38 +0,0 @@ -=== tests/cases/compiler/superCallArgsMustMatch.ts === -class T5{ ->T5 : T5 ->T : T - - public foo: T; ->foo : T ->T : T - - constructor(public bar: T) { } ->bar : T ->T : T - -} - - - -class T6 extends T5{ ->T6 : T6 ->T5 : T5 - - constructor() { - - super("hi"); // Should error, base constructor has type T for first arg, which is fixed as number in the extends clause ->super("hi") : void ->super : typeof T5 - - var x: number = this.foo; ->x : number ->this.foo : number ->this : T6 ->foo : number - - } - -} - - diff --git a/tests/baselines/reference/superCallParameterContextualTyping1.js b/tests/baselines/reference/superCallParameterContextualTyping1.js new file mode 100644 index 00000000000..b11d62d62c8 --- /dev/null +++ b/tests/baselines/reference/superCallParameterContextualTyping1.js @@ -0,0 +1,35 @@ +//// [superCallParameterContextualTyping1.ts] + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + // Ensure 'value' is of type 'number (and not '{}') by using its 'toExponential()' method. + constructor() { super(value => String(value.toExponential())); } +} + + +//// [superCallParameterContextualTyping1.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + // Ensure 'value' is of type 'number (and not '{}') by using its 'toExponential()' method. + function B() { + _super.call(this, function (value) { return String(value.toExponential()); }); + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallParameterContextualTyping1.types b/tests/baselines/reference/superCallParameterContextualTyping1.types new file mode 100644 index 00000000000..23aa3147997 --- /dev/null +++ b/tests/baselines/reference/superCallParameterContextualTyping1.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping1.ts === + +class A { +>A : A +>T1 : T1 +>T2 : T2 + + constructor(private map: (value: T1) => T2) { +>map : (value: T1) => T2 +>value : T1 +>T1 : T1 +>T2 : T2 + + } +} + +class B extends A { +>B : B +>A : A + + // Ensure 'value' is of type 'number (and not '{}') by using its 'toExponential()' method. + constructor() { super(value => String(value.toExponential())); } +>super(value => String(value.toExponential())) : void +>super : typeof A +>value => String(value.toExponential()) : (value: number) => string +>value : number +>String(value.toExponential()) : string +>String : StringConstructor +>value.toExponential() : string +>value.toExponential : (fractionDigits?: number) => string +>value : number +>toExponential : (fractionDigits?: number) => string +} + diff --git a/tests/baselines/reference/superCallParameterContextualTyping2.errors.txt b/tests/baselines/reference/superCallParameterContextualTyping2.errors.txt new file mode 100644 index 00000000000..a1e89d41efc --- /dev/null +++ b/tests/baselines/reference/superCallParameterContextualTyping2.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts(10,43): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts (1 errors) ==== + + class A { + constructor(private map: (value: T1) => T2) { + + } + } + + class C extends A { + // Ensure 'value' is not of type 'any' by invoking it with type arguments. + constructor() { super(value => String(value())); } + ~~~~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallParameterContextualTyping2.js b/tests/baselines/reference/superCallParameterContextualTyping2.js new file mode 100644 index 00000000000..61e8b94f00f --- /dev/null +++ b/tests/baselines/reference/superCallParameterContextualTyping2.js @@ -0,0 +1,34 @@ +//// [superCallParameterContextualTyping2.ts] + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class C extends A { + // Ensure 'value' is not of type 'any' by invoking it with type arguments. + constructor() { super(value => String(value())); } +} + +//// [superCallParameterContextualTyping2.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var C = (function (_super) { + __extends(C, _super); + // Ensure 'value' is not of type 'any' by invoking it with type arguments. + function C() { + _super.call(this, function (value) { return String(value()); }); + } + return C; +})(A); diff --git a/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping1.ts new file mode 100644 index 00000000000..7bcde9a6955 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping1.ts @@ -0,0 +1,11 @@ + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + // Ensure 'value' is of type 'number (and not '{}') by using its 'toExponential()' method. + constructor() { super(value => String(value.toExponential())); } +} diff --git a/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts new file mode 100644 index 00000000000..32b43374946 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping2.ts @@ -0,0 +1,11 @@ + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class C extends A { + // Ensure 'value' is not of type 'any' by invoking it with type arguments. + constructor() { super(value => String(value())); } +} \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts b/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts new file mode 100644 index 00000000000..6a5e71bd4a0 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts @@ -0,0 +1,20 @@ +/// + +////class A { +//// constructor(private map: (value: T1) => T2) { +//// +//// } +////} +//// +////class B extends A { +//// constructor() { super(va/*1*/lue => String(va/*2*/lue.toExpone/*3*/ntial())); } +////} + +goTo.marker('1'); +verify.quickInfoIs('(var) value: number'); + +goTo.marker('2'); +verify.quickInfoIs('(var) value: number'); + +goTo.marker('3'); +verify.quickInfoIs('(method) Number.toExponential(fractionDigits?: number): string'); \ No newline at end of file From 1638ae75186d9a8ac200f5c3723960be2f683a14 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 10:52:40 -0800 Subject: [PATCH 60/71] Updated comments and formatting as per review feedback. --- src/services/services.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index a88b31bd2fe..13212ede54c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -335,13 +335,14 @@ module ts { var paramTag = "@param"; var jsDocCommentParts: SymbolDisplayPart[] = []; - ts.forEach(declarations,(declaration, indexOfDeclaration) => { + ts.forEach(declarations, (declaration, indexOfDeclaration) => { + // Make sure we are collecting doc comment from declaration once, + // In case of union property there might be same declaration multiple times + // which only varies in type parameter + // Eg. var a: Array | Array; a.length + // The property length will have two declarations of property length coming + // from Array - Array and Array if (indexOf(declarations, declaration) === indexOfDeclaration) { - // Already collected the doc comments from this declaration. - // Eg. var a: Array | Array; a.length - // The property length will have two declarations of property length coming - // from Array - Array and Array - var sourceFileOfDeclaration = getSourceFileOfNode(declaration); // If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments if (canUseParsedParamTagComments && declaration.kind === SyntaxKind.Parameter) { From 4646d6355859fa59fe52ab8801e6c686ff9f0748 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Jan 2015 13:28:32 -0800 Subject: [PATCH 61/71] Fixed fourslash test. --- .../quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts b/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts index 6a5e71bd4a0..e24a484979a 100644 --- a/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts +++ b/tests/cases/fourslash/quickInfoForContextuallyTypedArrowFunctionInSuperCall.ts @@ -11,10 +11,10 @@ ////} goTo.marker('1'); -verify.quickInfoIs('(var) value: number'); +verify.quickInfoIs('(parameter) value: number'); goTo.marker('2'); -verify.quickInfoIs('(var) value: number'); +verify.quickInfoIs('(parameter) value: number'); goTo.marker('3'); verify.quickInfoIs('(method) Number.toExponential(fractionDigits?: number): string'); \ No newline at end of file From 8ee09dbe6ebdcd18c3208936b6226c712a0050ea Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Jan 2015 13:36:10 -0800 Subject: [PATCH 62/71] Addressed Jason's pedantic correction over the wording of a comment. --- .../baselines/reference/superCallArgsMustMatch.errors.txt | 6 ++++-- tests/baselines/reference/superCallArgsMustMatch.js | 8 ++++++-- tests/cases/compiler/superCallArgsMustMatch.ts | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/superCallArgsMustMatch.errors.txt b/tests/baselines/reference/superCallArgsMustMatch.errors.txt index e9a665acd1f..06758b44fe6 100644 --- a/tests/baselines/reference/superCallArgsMustMatch.errors.txt +++ b/tests/baselines/reference/superCallArgsMustMatch.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/superCallArgsMustMatch.ts(15,15): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +tests/cases/compiler/superCallArgsMustMatch.ts(17,15): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. ==== tests/cases/compiler/superCallArgsMustMatch.ts (1 errors) ==== @@ -16,7 +16,9 @@ tests/cases/compiler/superCallArgsMustMatch.ts(15,15): error TS2345: Argument of constructor() { - super("hi"); // Should error, base constructor has type T for first arg, which is fixed as number in the extends clause + // Should error; base constructor has type T for first arg, + // which is instantiated with 'number' in the extends clause + super("hi"); ~~~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. diff --git a/tests/baselines/reference/superCallArgsMustMatch.js b/tests/baselines/reference/superCallArgsMustMatch.js index 0b772fd39d8..e38c519ead9 100644 --- a/tests/baselines/reference/superCallArgsMustMatch.js +++ b/tests/baselines/reference/superCallArgsMustMatch.js @@ -13,7 +13,9 @@ class T6 extends T5{ constructor() { - super("hi"); // Should error, base constructor has type T for first arg, which is fixed as number in the extends clause + // Should error; base constructor has type T for first arg, + // which is instantiated with 'number' in the extends clause + super("hi"); var x: number = this.foo; @@ -39,7 +41,9 @@ var T5 = (function () { var T6 = (function (_super) { __extends(T6, _super); function T6() { - _super.call(this, "hi"); // Should error, base constructor has type T for first arg, which is fixed as number in the extends clause + // Should error; base constructor has type T for first arg, + // which is instantiated with 'number' in the extends clause + _super.call(this, "hi"); var x = this.foo; } return T6; diff --git a/tests/cases/compiler/superCallArgsMustMatch.ts b/tests/cases/compiler/superCallArgsMustMatch.ts index a27aff3919b..5407c3301fa 100644 --- a/tests/cases/compiler/superCallArgsMustMatch.ts +++ b/tests/cases/compiler/superCallArgsMustMatch.ts @@ -12,7 +12,9 @@ class T6 extends T5{ constructor() { - super("hi"); // Should error, base constructor has type T for first arg, which is fixed as number in the extends clause + // Should error; base constructor has type T for first arg, + // which is instantiated with 'number' in the extends clause + super("hi"); var x: number = this.foo; From 40796b2c6d64b1d3b304b33ece97bd6893437762 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Jan 2015 14:42:39 -0800 Subject: [PATCH 63/71] Added more tests. --- ...IncorrectNumberOfTypeArguments1.errors.txt | 19 +++++++++++ ...eButWithIncorrectNumberOfTypeArguments1.js | 32 +++++++++++++++++ ...ericTypeButWithNoTypeArguments1.errors.txt | 19 +++++++++++ ...sFromGenericTypeButWithNoTypeArguments1.js | 32 +++++++++++++++++ ...enericTypeButWithTypeArguments1.errors.txt | 19 +++++++++++ ...ivesNonGenericTypeButWithTypeArguments1.js | 32 +++++++++++++++++ ...CallFromClassThatHasNoBaseType1.errors.txt | 16 +++++++++ .../superCallFromClassThatHasNoBaseType1.js | 25 ++++++++++++++ .../superCallFromFunction1.errors.txt | 10 ++++++ .../reference/superCallFromFunction1.js | 10 ++++++ .../reference/superNewCall1.errors.txt | 23 +++++++++++++ tests/baselines/reference/superNewCall1.js | 34 +++++++++++++++++++ ...eButWithIncorrectNumberOfTypeArguments1.ts | 10 ++++++ ...sFromGenericTypeButWithNoTypeArguments1.ts | 10 ++++++ ...ivesNonGenericTypeButWithTypeArguments1.ts | 10 ++++++ .../superCallFromClassThatHasNoBaseType1.ts | 10 ++++++ .../cases/compiler/superCallFromFunction1.ts | 4 +++ tests/cases/compiler/superNewCall1.ts | 12 +++++++ 18 files changed, 327 insertions(+) create mode 100644 tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.errors.txt create mode 100644 tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.js create mode 100644 tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.errors.txt create mode 100644 tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.js create mode 100644 tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.errors.txt create mode 100644 tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.js create mode 100644 tests/baselines/reference/superCallFromClassThatHasNoBaseType1.errors.txt create mode 100644 tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js create mode 100644 tests/baselines/reference/superCallFromFunction1.errors.txt create mode 100644 tests/baselines/reference/superCallFromFunction1.js create mode 100644 tests/baselines/reference/superNewCall1.errors.txt create mode 100644 tests/baselines/reference/superNewCall1.js create mode 100644 tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts create mode 100644 tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts create mode 100644 tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts create mode 100644 tests/cases/compiler/superCallFromClassThatHasNoBaseType1.ts create mode 100644 tests/cases/compiler/superCallFromFunction1.ts create mode 100644 tests/cases/compiler/superNewCall1.ts diff --git a/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.errors.txt b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.errors.txt new file mode 100644 index 00000000000..14905b224ad --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts(8,17): error TS2314: Generic type 'A' requires 2 type argument(s). +tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts(9,21): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts (2 errors) ==== + + class A { + constructor(private map: (value: T1) => T2) { + + } + } + + class B extends A { + ~~~~~~~~~ +!!! error TS2314: Generic type 'A' requires 2 type argument(s). + constructor() { super(value => String(value)); } + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.js b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.js new file mode 100644 index 00000000000..92abed0d66d --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.js @@ -0,0 +1,32 @@ +//// [superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts] + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + constructor() { super(value => String(value)); } +} + +//// [superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.call(this, function (value) { return String(value); }); + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.errors.txt b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.errors.txt new file mode 100644 index 00000000000..d402272df1b --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts(8,17): error TS2314: Generic type 'A' requires 2 type argument(s). +tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts(9,21): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts (2 errors) ==== + + class A { + constructor(private map: (value: T1) => T2) { + + } + } + + class B extends A { + ~ +!!! error TS2314: Generic type 'A' requires 2 type argument(s). + constructor() { super(value => String(value)); } + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.js b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.js new file mode 100644 index 00000000000..7e3c61e6690 --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.js @@ -0,0 +1,32 @@ +//// [superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts] + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + constructor() { super(value => String(value)); } +} + +//// [superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.call(this, function (value) { return String(value); }); + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.errors.txt b/tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.errors.txt new file mode 100644 index 00000000000..8bbf8b87cd3 --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts(8,17): error TS2315: Type 'A' is not generic. +tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts(9,21): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts (2 errors) ==== + + class A { + constructor(private map: (value: number) => string) { + + } + } + + class B extends A { + ~~~~~~~~~~~~~~~~~ +!!! error TS2315: Type 'A' is not generic. + constructor() { super(value => String(value)); } + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.js b/tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.js new file mode 100644 index 00000000000..b48d5bb7f58 --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.js @@ -0,0 +1,32 @@ +//// [superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts] + +class A { + constructor(private map: (value: number) => string) { + + } +} + +class B extends A { + constructor() { super(value => String(value)); } +} + +//// [superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.call(this, function (value) { return String(value); }); + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.errors.txt b/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.errors.txt new file mode 100644 index 00000000000..bac5abad004 --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/superCallFromClassThatHasNoBaseType1.ts(9,21): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/compiler/superCallFromClassThatHasNoBaseType1.ts (1 errors) ==== + + class A { + constructor(private map: (value: number) => string) { + + } + } + + class B { + constructor() { super(value => String(value)); } + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js b/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js new file mode 100644 index 00000000000..7818aed7ff8 --- /dev/null +++ b/tests/baselines/reference/superCallFromClassThatHasNoBaseType1.js @@ -0,0 +1,25 @@ +//// [superCallFromClassThatHasNoBaseType1.ts] + +class A { + constructor(private map: (value: number) => string) { + + } +} + +class B { + constructor() { super(value => String(value)); } +} + +//// [superCallFromClassThatHasNoBaseType1.js] +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var B = (function () { + function B() { + _super.call(this, function (value) { return String(value); }); + } + return B; +})(); diff --git a/tests/baselines/reference/superCallFromFunction1.errors.txt b/tests/baselines/reference/superCallFromFunction1.errors.txt new file mode 100644 index 00000000000..374a3aeb16c --- /dev/null +++ b/tests/baselines/reference/superCallFromFunction1.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/superCallFromFunction1.ts(3,5): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/compiler/superCallFromFunction1.ts (1 errors) ==== + + function foo() { + super(value => String(value)); + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallFromFunction1.js b/tests/baselines/reference/superCallFromFunction1.js new file mode 100644 index 00000000000..a7fcbaaeff0 --- /dev/null +++ b/tests/baselines/reference/superCallFromFunction1.js @@ -0,0 +1,10 @@ +//// [superCallFromFunction1.ts] + +function foo() { + super(value => String(value)); +} + +//// [superCallFromFunction1.js] +function foo() { + _super.call(this, function (value) { return String(value); }); +} diff --git a/tests/baselines/reference/superNewCall1.errors.txt b/tests/baselines/reference/superNewCall1.errors.txt new file mode 100644 index 00000000000..2b104e7d647 --- /dev/null +++ b/tests/baselines/reference/superNewCall1.errors.txt @@ -0,0 +1,23 @@ +tests/cases/compiler/superNewCall1.ts(9,5): error TS2377: Constructors for derived classes must contain a 'super' call. +tests/cases/compiler/superNewCall1.ts(10,9): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + + +==== tests/cases/compiler/superNewCall1.ts (2 errors) ==== + + class A { + constructor(private map: (value: T1) => T2) { + + } + } + + class B extends A { + constructor() { + ~~~~~~~~~~~~~~~ + new super(value => String(value)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + } + ~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. + } \ No newline at end of file diff --git a/tests/baselines/reference/superNewCall1.js b/tests/baselines/reference/superNewCall1.js new file mode 100644 index 00000000000..d9b74ac5080 --- /dev/null +++ b/tests/baselines/reference/superNewCall1.js @@ -0,0 +1,34 @@ +//// [superNewCall1.ts] + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + constructor() { + new super(value => String(value)); + } +} + +//// [superNewCall1.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A(map) { + this.map = map; + } + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + new _super.prototype(function (value) { return String(value); }); + } + return B; +})(A); diff --git a/tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts b/tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts new file mode 100644 index 00000000000..d633ccb018f --- /dev/null +++ b/tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithIncorrectNumberOfTypeArguments1.ts @@ -0,0 +1,10 @@ + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + constructor() { super(value => String(value)); } +} \ No newline at end of file diff --git a/tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts b/tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts new file mode 100644 index 00000000000..c09fb37db2d --- /dev/null +++ b/tests/cases/compiler/superCallFromClassThatDerivesFromGenericTypeButWithNoTypeArguments1.ts @@ -0,0 +1,10 @@ + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + constructor() { super(value => String(value)); } +} \ No newline at end of file diff --git a/tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts b/tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts new file mode 100644 index 00000000000..99755d87fbf --- /dev/null +++ b/tests/cases/compiler/superCallFromClassThatDerivesNonGenericTypeButWithTypeArguments1.ts @@ -0,0 +1,10 @@ + +class A { + constructor(private map: (value: number) => string) { + + } +} + +class B extends A { + constructor() { super(value => String(value)); } +} \ No newline at end of file diff --git a/tests/cases/compiler/superCallFromClassThatHasNoBaseType1.ts b/tests/cases/compiler/superCallFromClassThatHasNoBaseType1.ts new file mode 100644 index 00000000000..5f030bd5562 --- /dev/null +++ b/tests/cases/compiler/superCallFromClassThatHasNoBaseType1.ts @@ -0,0 +1,10 @@ + +class A { + constructor(private map: (value: number) => string) { + + } +} + +class B { + constructor() { super(value => String(value)); } +} \ No newline at end of file diff --git a/tests/cases/compiler/superCallFromFunction1.ts b/tests/cases/compiler/superCallFromFunction1.ts new file mode 100644 index 00000000000..81874204e1a --- /dev/null +++ b/tests/cases/compiler/superCallFromFunction1.ts @@ -0,0 +1,4 @@ + +function foo() { + super(value => String(value)); +} \ No newline at end of file diff --git a/tests/cases/compiler/superNewCall1.ts b/tests/cases/compiler/superNewCall1.ts new file mode 100644 index 00000000000..b3792d55221 --- /dev/null +++ b/tests/cases/compiler/superNewCall1.ts @@ -0,0 +1,12 @@ + +class A { + constructor(private map: (value: T1) => T2) { + + } +} + +class B extends A { + constructor() { + new super(value => String(value)); + } +} \ No newline at end of file From 9d8319dc79b206eb62bcbd98138dd41dbd67854e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Jan 2015 14:55:42 -0800 Subject: [PATCH 64/71] Perform checking, document function. --- src/compiler/checker.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6887421ba32..8eb834c63a4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5978,16 +5978,21 @@ module ts { return args; } - // In a 'super' call, type arguments are not provided within the CallExpression node itself. - // Instead, they must be fetched from the class declaration's base type node. + /** + * In a 'super' call, type arguments are not provided within the CallExpression node itself. + * Instead, they must be fetched from the class declaration's base type node. + * + * If 'node' is a 'super' call (e.g. super(...), new super(...)), then we attempt to fetch + * the type arguments off the containing class's first heritage clause (if one exists). Note that if + * type arguments are supplied on the 'super' call, they are ignored (though this is syntactically incorrect). + * + * In all other cases, the call's explicit type arguments are returned. + */ function getEffectiveTypeArguments(callExpression: CallExpression): TypeNode[] { if (callExpression.expression.kind === SyntaxKind.SuperKeyword) { - // TODO (drosen): 1) Discuss if checking needs to be done at this point. - // 2) Have a test where type arguments are not provided on the base class. - // 3) Have a test where the base class is not generic. var containingClass = getAncestor(callExpression, SyntaxKind.ClassDeclaration); - var baseClassTypeNode = getClassBaseTypeNode(containingClass); - return baseClassTypeNode.typeArguments; + var baseClassTypeNode = containingClass && getClassBaseTypeNode(containingClass); + return baseClassTypeNode && baseClassTypeNode.typeArguments; } else { // Ordinary case - simple function invocation. From 0ffa722e23a14f281debebd8d0612dfc66909ddd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Jan 2015 14:57:38 -0800 Subject: [PATCH 65/71] Removed superfluous type assertion. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8eb834c63a4..732acf1843b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5996,7 +5996,7 @@ module ts { } else { // Ordinary case - simple function invocation. - return (callExpression).typeArguments; + return callExpression.typeArguments; } } From 34b342ac9731a1db3a349bc075345ec41943f2c8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 27 Jan 2015 17:09:57 -0800 Subject: [PATCH 66/71] Fix method name. --- src/compiler/emitter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e6a44148fe2..36741ab6cb0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3687,13 +3687,13 @@ module ts { } } - function shouldEnumModuleDeclaration(node: ModuleDeclaration) { + function shouldEmitModuleDeclaration(node: ModuleDeclaration) { return isInstantiatedModule(node, compilerOptions.preserveConstEnums); } function emitModuleDeclaration(node: ModuleDeclaration) { // Emit only if this module is non-ambient. - var shouldEmit = shouldEnumModuleDeclaration(node); + var shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { return emitPinnedOrTripleSlashComments(node); @@ -3967,7 +3967,7 @@ module ts { case SyntaxKind.ModuleDeclaration: // Only emit the leading/trailing comments for a module if we're actually // emitting the module as well. - return shouldEnumModuleDeclaration(node); + return shouldEmitModuleDeclaration(node); case SyntaxKind.EnumDeclaration: // Only emit the leading/trailing comments for an enum if we're actually From 3c5ff5310fc553e0256f7e8c3b3763ee4d60fe62 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 27 Jan 2015 17:16:28 -0800 Subject: [PATCH 67/71] CR feedback . --- src/compiler/emitter.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 945ff3e15ae..34978ed7fd6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3307,7 +3307,9 @@ module ts { write(" "); emitStart(node.body); write("return "); - // Don't emit comments on this body. We'll have already taken care of it above. + + // Don't emit comments on this body. We'll have already taken care of it above + // when we called emitDetachedComments. emitNode(node.body, /*disableComments:*/ true); emitEnd(node.body); write(";"); @@ -3979,7 +3981,7 @@ module ts { function shouldEmitLeadingAndTrailingComments(node: Node) { switch (node.kind) { - // All of thes entities are emitted in a specialized fashion. As such, we allow + // All of these entities are emitted in a specialized fashion. As such, we allow // the specilized methods for each to handle the comments on the nodes. case SyntaxKind.InterfaceDeclaration: case SyntaxKind.FunctionDeclaration: From e4d30515323724f3884de8f29e21a418473857ca Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Jan 2015 22:39:48 -0800 Subject: [PATCH 68/71] Added Jason's example for contextually typing parameters. --- .../superCallParameterContextualTyping3.js | 67 +++++++++++++++++ .../superCallParameterContextualTyping3.types | 73 +++++++++++++++++++ .../superCallParameterContextualTyping3.ts | 31 ++++++++ 3 files changed, 171 insertions(+) create mode 100644 tests/baselines/reference/superCallParameterContextualTyping3.js create mode 100644 tests/baselines/reference/superCallParameterContextualTyping3.types create mode 100644 tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts diff --git a/tests/baselines/reference/superCallParameterContextualTyping3.js b/tests/baselines/reference/superCallParameterContextualTyping3.js new file mode 100644 index 00000000000..e33bcb29bb8 --- /dev/null +++ b/tests/baselines/reference/superCallParameterContextualTyping3.js @@ -0,0 +1,67 @@ +//// [superCallParameterContextualTyping3.ts] +interface ContextualType { + method(parameter: T): void; +} + +class CBase { + constructor(param: ContextualType) { + } + + foo(param: ContextualType) { + } +} + +class C extends CBase { + constructor() { + // Should be okay. + // 'p' should have type 'string'. + super({ + method(p) { + p.length; + } + }); + + // Should be okay. + // 'p' should have type 'string'. + super.foo({ + method(p) { + p.length; + } + }); + } +} + +//// [superCallParameterContextualTyping3.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var CBase = (function () { + function CBase(param) { + } + CBase.prototype.foo = function (param) { + }; + return CBase; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + // Should be okay. + // 'p' should have type 'string'. + _super.call(this, { + method: function (p) { + p.length; + } + }); + // Should be okay. + // 'p' should have type 'string'. + _super.prototype.foo.call(this, { + method: function (p) { + p.length; + } + }); + } + return C; +})(CBase); diff --git a/tests/baselines/reference/superCallParameterContextualTyping3.types b/tests/baselines/reference/superCallParameterContextualTyping3.types new file mode 100644 index 00000000000..4a8515d110c --- /dev/null +++ b/tests/baselines/reference/superCallParameterContextualTyping3.types @@ -0,0 +1,73 @@ +=== tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts === +interface ContextualType { +>ContextualType : ContextualType +>T : T + + method(parameter: T): void; +>method : (parameter: T) => void +>parameter : T +>T : T +} + +class CBase { +>CBase : CBase +>T : T + + constructor(param: ContextualType) { +>param : ContextualType +>ContextualType : ContextualType +>T : T + } + + foo(param: ContextualType) { +>foo : (param: ContextualType) => void +>param : ContextualType +>ContextualType : ContextualType +>T : T + } +} + +class C extends CBase { +>C : C +>CBase : CBase + + constructor() { + // Should be okay. + // 'p' should have type 'string'. + super({ +>super({ method(p) { p.length; } }) : void +>super : typeof CBase +>{ method(p) { p.length; } } : { method(p: string): void; } + + method(p) { +>method : (p: string) => void +>p : string + + p.length; +>p.length : number +>p : string +>length : number + } + }); + + // Should be okay. + // 'p' should have type 'string'. + super.foo({ +>super.foo({ method(p) { p.length; } }) : void +>super.foo : (param: ContextualType) => void +>super : CBase +>foo : (param: ContextualType) => void +>{ method(p) { p.length; } } : { method(p: string): void; } + + method(p) { +>method : (p: string) => void +>p : string + + p.length; +>p.length : number +>p : string +>length : number + } + }); + } +} diff --git a/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts b/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts new file mode 100644 index 00000000000..760337f3efa --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts @@ -0,0 +1,31 @@ +interface ContextualType { + method(parameter: T): void; +} + +class CBase { + constructor(param: ContextualType) { + } + + foo(param: ContextualType) { + } +} + +class C extends CBase { + constructor() { + // Should be okay. + // 'p' should have type 'string'. + super({ + method(p) { + p.length; + } + }); + + // Should be okay. + // 'p' should have type 'string'. + super.foo({ + method(p) { + p.length; + } + }); + } +} \ No newline at end of file From 2f9e65f16b64e524adb245159ecee82bfc5f9dff Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 29 Jan 2015 12:44:43 -0800 Subject: [PATCH 69/71] Update gitignore to ignore internal test folders --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8e2c10d7b32..57e8804d7c3 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ scripts/word2md.js scripts/ior.js scripts/*.js.map coverage/ +internal/ From d0ca71f445125e59797a42dfca7ed5525816dc43 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 29 Jan 2015 13:32:27 -0800 Subject: [PATCH 70/71] Correctly copy assumptions back into the relational cache --- src/compiler/checker.ts | 18 ++- .../reference/promisePermutations.errors.txt | 39 ++--- .../reference/promisePermutations2.errors.txt | 135 +++++------------- 3 files changed, 53 insertions(+), 139 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 760547d8fac..c2e79bdafe7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3471,7 +3471,7 @@ module ts { // where errors were being reported. if (errorInfo.next === undefined) { errorInfo = undefined; - isRelatedTo(source, target, errorNode !== undefined, headMessage, true); + isRelatedTo(source, target, errorNode !== undefined, headMessage, /* mustRecompute */ true); } if (containingMessageChain) { errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); @@ -3652,8 +3652,11 @@ module ts { } var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; var related = relation[id]; + //var related: RelationComparisonResult = undefined; // relation[id]; if (related !== undefined) { - if (!elaborateErrors || related === RelationComparisonResult.FailedAndReported) { + // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate + // errors, we can use the cached value. Otherwise, recompute the relation + if (!elaborateErrors || (related === RelationComparisonResult.FailedAndReported)) { return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False; } } @@ -3706,9 +3709,14 @@ module ts { if (result) { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up - var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1]; - for (var key in maybeCache) { - destinationCache[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : RelationComparisonResult.Failed; + if (result === Ternary.True || depth === 0) { + var key: string; + for (key in maybeCache) { + relation[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : (reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed); + } + } + else { + copyMap(maybeCache, maybeStack[depth - 1]); } } else { diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index d4082015054..744fd5da90e 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -1,11 +1,6 @@ -tests/cases/compiler/promisePermutations.ts(55,34): error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. - Type 'IPromise' is not assignable to type 'Promise'. -tests/cases/compiler/promisePermutations.ts(56,34): error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. - Type 'IPromise' is not assignable to type 'Promise'. -tests/cases/compiler/promisePermutations.ts(73,35): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. - Type 'IPromise' is not assignable to type 'Promise'. -tests/cases/compiler/promisePermutations.ts(74,35): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. - Type 'IPromise' is not assignable to type 'Promise'. +tests/cases/compiler/promisePermutations.ts(74,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'IPromise'. tests/cases/compiler/promisePermutations.ts(79,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'x' and 'value' are incompatible. Type 'number' is not assignable to type 'string'. @@ -55,14 +50,10 @@ tests/cases/compiler/promisePermutations.ts(137,11): error TS2453: The type argu tests/cases/compiler/promisePermutations.ts(144,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations.ts(151,21): error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(value: {}) => Promise'. - Type 'IPromise' is not assignable to type 'Promise'. tests/cases/compiler/promisePermutations.ts(152,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Types of property 'then' are incompatible. Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. -tests/cases/compiler/promisePermutations.ts(153,36): error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. - Type 'IPromise' is not assignable to type 'Promise'. tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -76,7 +67,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t Type 'Promise' is not assignable to type 'IPromise'. -==== tests/cases/compiler/promisePermutations.ts (38 errors) ==== +==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== interface Promise { then(success?: (value: T) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; then(success?: (value: T) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; @@ -132,13 +123,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s1a = s1.then(testFunction, testFunction, testFunction); var s1b = s1.then(testFunctionP, testFunctionP, testFunctionP); var s1c = s1.then(testFunctionP, testFunction, testFunction); - ~~~~~~~~~~~~ -!!! error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. -!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s1d = s1.then(testFunctionP, testFunction, testFunction).then(testFunction, testFunction, testFunction); - ~~~~~~~~~~~~ -!!! error TS2345: Argument of type '() => IPromise' is not assignable to parameter of type '(error: any) => Promise'. -!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var r2: IPromise<{ x: number; }>; var r2a = r2.then(testFunction2, testFunction2, testFunction2); @@ -156,13 +141,11 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); - ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. -!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error - ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. -!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -316,9 +299,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - ~~~~~~~~~ -!!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(value: {}) => Promise'. -!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~ !!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. @@ -326,9 +306,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok - ~~~~~~~~~ -!!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. -!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 1e2c13edd15..5a50b9391ba 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -1,19 +1,6 @@ -tests/cases/compiler/promisePermutations2.ts(54,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. - Types of property 'then' are incompatible. - Type '{ (success?: (value: number) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. -tests/cases/compiler/promisePermutations2.ts(55,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. -tests/cases/compiler/promisePermutations2.ts(63,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. - Types of property 'then' are incompatible. - Type '{ (success?: (value: { x: number; }) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. -tests/cases/compiler/promisePermutations2.ts(64,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. -tests/cases/compiler/promisePermutations2.ts(72,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. -tests/cases/compiler/promisePermutations2.ts(73,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(73,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'IPromise'. tests/cases/compiler/promisePermutations2.ts(78,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'x' and 'value' are incompatible. Type 'number' is not assignable to type 'string'. @@ -23,24 +10,17 @@ tests/cases/compiler/promisePermutations2.ts(81,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations2.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. Types of parameters 'x' and 'value' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/promisePermutations2.ts(83,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. - Types of property 'then' are incompatible. - Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. -tests/cases/compiler/promisePermutations2.ts(84,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'Promise'. - Types of property 'then' are incompatible. - Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. +tests/cases/compiler/promisePermutations2.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. + Types of parameters 'x' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations2.ts(87,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(90,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(91,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. -tests/cases/compiler/promisePermutations2.ts(92,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(92,19): error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(96,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(99,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(100,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. -tests/cases/compiler/promisePermutations2.ts(101,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(101,19): error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations2.ts(105,19): error TS2345: Argument of type '(cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type '(a: T) => T' is not assignable to type 'string'. @@ -56,35 +36,24 @@ tests/cases/compiler/promisePermutations2.ts(110,19): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. -tests/cases/compiler/promisePermutations2.ts(121,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. - Types of property 'then' are incompatible. - Type '{ (success?: (value: any) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. +tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(128,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. -tests/cases/compiler/promisePermutations2.ts(133,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(136,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations2.ts(143,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations2.ts(148,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise<{}>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{}>'. - Types of property 'then' are incompatible. - Type '{ (success?: (value: {}) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. -tests/cases/compiler/promisePermutations2.ts(150,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. tests/cases/compiler/promisePermutations2.ts(151,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Types of property 'then' are incompatible. Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. -tests/cases/compiler/promisePermutations2.ts(152,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -94,11 +63,11 @@ tests/cases/compiler/promisePermutations2.ts(157,21): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. Type 'Promise' is not assignable to type 'Promise'. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. +tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. + Type 'Promise' is not assignable to type 'IPromise'. -==== tests/cases/compiler/promisePermutations2.ts (42 errors) ==== +==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== // same as promisePermutations but without the same overloads in Promise interface Promise { @@ -153,15 +122,7 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg var s1a = s1.then(testFunction, testFunction, testFunction); var s1b = s1.then(testFunctionP, testFunctionP, testFunctionP); var s1c = s1.then(testFunctionP, testFunction, testFunction); - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. -!!! error TS2453: Types of property 'then' are incompatible. -!!! error TS2453: Type '{ (success?: (value: number) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s1d = s1.then(testFunctionP, testFunction, testFunction).then(testFunction, testFunction, testFunction); - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var r2: IPromise<{ x: number; }>; var r2a = r2.then(testFunction2, testFunction2, testFunction2); @@ -170,15 +131,7 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg var s2a = s2.then(testFunction2, testFunction2, testFunction2); var s2b = s2.then(testFunction2P, testFunction2P, testFunction2P); var s2c = s2.then(testFunction2P, testFunction2, testFunction2); - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. -!!! error TS2453: Types of property 'then' are incompatible. -!!! error TS2453: Type '{ (success?: (value: { x: number; }) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: { x: number; }) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s2d = s2.then(testFunction2P, testFunction2, testFunction2).then(testFunction2, testFunction2, testFunction2); - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise<{ x: number; }>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{ x: number; }>'. var r3: IPromise; var r3a = r3.then(testFunction3, testFunction3, testFunction3); @@ -187,13 +140,11 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // Should error - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -216,17 +167,11 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg !!! error TS2345: Types of parameters 'x' and 'value' are incompatible. !!! error TS2345: Type 'number' is not assignable to type 'string'. var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. -!!! error TS2453: Types of property 'then' are incompatible. -!!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. +!!! error TS2345: Types of parameters 'x' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'Promise'. -!!! error TS2453: Types of property 'then' are incompatible. -!!! error TS2453: Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -241,9 +186,8 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. var s5c = s5.then(testFunction5P, testFunction5, testFunction5); // error - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number, cb: (a: string) => string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. var s5d = s5.then(sPromise, sPromise, sPromise).then(sIPromise, sIPromise, sIPromise); // ok var r6: IPromise; @@ -259,9 +203,8 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => Promise'. var s6c = s6.then(testFunction6P, testFunction6, testFunction6); // error - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. var s6d = s6.then(sPromise, sPromise, sPromise).then(sIPromise, sIPromise, sIPromise); // ok var r7: IPromise; @@ -304,11 +247,8 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. -!!! error TS2453: Types of property 'then' are incompatible. -!!! error TS2453: Type '{ (success?: (value: any) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s8d = s8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var r9: IPromise; @@ -331,9 +271,8 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error - ~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok var s9f = s9.then(testFunction, sIPromise, nIPromise); // error @@ -357,15 +296,8 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok - ~~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise<{}>' is not a valid type argument because it is not a supertype of candidate 'IPromise<{}>'. -!!! error TS2453: Types of property 'then' are incompatible. -!!! error TS2453: Type '{ (success?: (value: {}) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: {}) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - ~~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~ !!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. @@ -373,9 +305,6 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '(success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void) => Promise'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error @@ -395,9 +324,9 @@ tests/cases/compiler/promisePermutations2.ts(159,12): error TS2453: The type arg !!! error TS2345: Type 'Promise' is not assignable to type 'Promise'. !!! error TS2345: Type 'number' is not assignable to type 'string'. var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok - ~~~~~~~~ -!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'Promise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok From d224286d59554a40e8ded19a25a96b87f97fd1e9 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 29 Jan 2015 14:37:57 -0800 Subject: [PATCH 71/71] Address CR feedback --- src/compiler/checker.ts | 21 +++++++-------------- src/compiler/types.ts | 6 +++--- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2e79bdafe7..ed89032b781 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3453,7 +3453,7 @@ module ts { var errorInfo: DiagnosticMessageChain; var sourceStack: ObjectType[]; var targetStack: ObjectType[]; - var maybeStack: Map[]; + var maybeStack: Map[]; var expandingFlags: number; var depth = 0; var overflow = false; @@ -3471,7 +3471,7 @@ module ts { // where errors were being reported. if (errorInfo.next === undefined) { errorInfo = undefined; - isRelatedTo(source, target, errorNode !== undefined, headMessage, /* mustRecompute */ true); + isRelatedTo(source, target, errorNode !== undefined, headMessage, /* elaborateErrors */ true); } if (containingMessageChain) { errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); @@ -3488,7 +3488,7 @@ module ts { // Ternary.True if they are related with no assumptions, // Ternary.Maybe if they are related with assumptions of other relationships, or // Ternary.False if they are not related. - function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, mustRecompute = false): Ternary { + function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, elaborateErrors = false): Ternary { var result: Ternary; // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; @@ -3555,7 +3555,7 @@ module ts { // identity relation does not use apparent type var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType && - (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, mustRecompute))) { + (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, elaborateErrors))) { errorInfo = saveErrorInfo; return result; } @@ -3681,7 +3681,7 @@ module ts { sourceStack[depth] = source; targetStack[depth] = target; maybeStack[depth] = {}; - maybeStack[depth][id] = true; + maybeStack[depth][id] = RelationComparisonResult.Succeeded; depth++; var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) expandingFlags |= 1; @@ -3709,15 +3709,8 @@ module ts { if (result) { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up - if (result === Ternary.True || depth === 0) { - var key: string; - for (key in maybeCache) { - relation[key] = maybeCache[key] ? RelationComparisonResult.Succeeded : (reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed); - } - } - else { - copyMap(maybeCache, maybeStack[depth - 1]); - } + var destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1]; + copyMap(maybeCache, destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 57266fc5a89..80bdc875177 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -331,9 +331,9 @@ module ts { } export const enum RelationComparisonResult { - Succeeded = 0, - Failed = 1, - FailedAndReported = 2 + Succeeded = 1, // Should be truthy + Failed = 2, + FailedAndReported = 3 } export interface Node extends TextRange {