From 167d318a1375a467877bc6d6672a0015e3e684bd Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 25 Jul 2016 14:48:41 -0700 Subject: [PATCH 01/18] Draft of configuration inheritance --- Jakefile.js | 1 + src/compiler/commandLineParser.ts | 81 +++++- src/compiler/core.ts | 30 ++- src/compiler/diagnosticMessages.json | 9 + src/compiler/types.ts | 2 + src/harness/harness.ts | 3 +- src/harness/projectsRunner.ts | 5 + src/harness/rwcRunner.ts | 1 + src/harness/tsconfig.json | 1 + .../unittests/configurationExtension.ts | 230 ++++++++++++++++++ src/harness/virtualFileSystem.ts | 25 +- 11 files changed, 374 insertions(+), 14 deletions(-) create mode 100644 src/harness/unittests/configurationExtension.ts diff --git a/Jakefile.js b/Jakefile.js index f63275284d0..d6a2f253ac8 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -155,6 +155,7 @@ var harnessSources = harnessCoreSources.concat([ "moduleResolution.ts", "tsconfigParsing.ts", "commandLineParsing.ts", + "configurationExtension.ts", "convertCompilerOptionsFromJson.ts", "convertTypingOptionsFromJson.ts", "tsserverProjectSystem.ts", diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7e2c6eb8d33..41a126f234d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -700,12 +700,54 @@ namespace ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string): ParsedCommandLine { + export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = []): ParsedCommandLine { const errors: Diagnostic[] = []; - const compilerOptions: CompilerOptions = convertCompilerOptionsFromJsonWorker(json["compilerOptions"], basePath, errors, configFileName); - const options = extend(existingOptions, compilerOptions); + const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames); + const resolvedPath = toPath(configFileName || "", basePath, getCanonicalFileName); + if (resolutionStack.indexOf(resolvedPath) >= 0) { + return { + options: {}, + fileNames: [], + typingOptions: {}, + raw: json, + errors: [createCompilerDiagnostic(Diagnostics.Circularity_detected_while_resolving_configuration_Colon_0, [...resolutionStack, resolvedPath].join(" -> "))], + wildcardDirectories: {} + }; + } + + let options: CompilerOptions = convertCompilerOptionsFromJsonWorker(json["compilerOptions"], basePath, errors, configFileName); const typingOptions: TypingOptions = convertTypingOptionsFromJsonWorker(json["typingOptions"], basePath, errors, configFileName); + if (json["extends"]) { + let [include, exclude, files, baseOptions]: [string[], string[], string[], CompilerOptions] = [undefined, undefined, undefined, {}]; + if (typeof json["extends"] === "string") { + [include, exclude, files, baseOptions] = (tryExtendsName(json["extends"]) || [include, exclude, files, baseOptions]); + } + else if (typeof json["extends"] === "object" && json["extends"].length) { + for (const name of json["extends"]) { + const [tempinclude, tempexclude, tempfiles, tempBase]: [string[], string[], string[], CompilerOptions] = (tryExtendsName(name) || [include, exclude, files, baseOptions]); + include = tempinclude || include; + exclude = tempexclude || exclude; + files = tempfiles || files; + baseOptions = assign({}, baseOptions, tempBase); + } + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", "string or string[]")); + } + if (include && !json["include"]) { + json["include"] = include; + } + if (exclude && !json["exclude"]) { + json["exclude"] = exclude; + } + if (files && !json["files"]) { + json["files"] = files; + } + options = assign({}, baseOptions, options); + } + + options = extend(existingOptions, options); options.configFilePath = configFileName; const { fileNames, wildcardDirectories } = getFileNames(errors); @@ -719,6 +761,39 @@ namespace ts { wildcardDirectories }; + function tryExtendsName(extendedConfig: string): [string[], string[], string[], CompilerOptions] { + // If the path isn't a rooted or relative path, don't try to resolve it (we reserve the right to special case module-id like paths in the future) + if (!(isRootedDiskPath(extendedConfig) || startsWith(normalizeSlashes(extendedConfig), "./") || startsWith(normalizeSlashes(extendedConfig), "../"))) { + errors.push(createCompilerDiagnostic(Diagnostics.The_path_in_an_extends_options_must_be_relative_or_rooted)); + return; + } + let extendedConfigPath = toPath(extendedConfig, basePath, getCanonicalFileName); + if (!host.fileExists(extendedConfigPath) && !endsWith(extendedConfigPath, ".json")) { + extendedConfigPath = `${extendedConfigPath}.json` as Path; + if (!host.fileExists(extendedConfigPath)) { + errors.push(createCompilerDiagnostic(Diagnostics.File_0_does_not_exist, extendedConfig)); + return; + } + } + const extendedResult = readConfigFile(extendedConfigPath, path => host.readFile(path)); + if (extendedResult.error) { + errors.push(extendedResult.error); + return; + } + const extendedDirname = getDirectoryPath(extendedConfigPath); + const relativeDifference = convertToRelativePath(extendedDirname, basePath, getCanonicalFileName); + const updatePath: (path: string) => string = path => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path); + // Merge configs (copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios) + const result = parseJsonConfigFileContent(extendedResult.config, host, extendedDirname, /*existingOptions*/undefined, getBaseFileName(extendedConfigPath), resolutionStack.concat([resolvedPath])); + errors.push(...result.errors); + const [include, exclude, files] = map(["include", "exclude", "files"], key => { + if (!json[key] && extendedResult.config[key]) { + return map(extendedResult.config[key], updatePath); + } + }); + return [include, exclude, files, result.options]; + } + function getFileNames(errors: Diagnostic[]): ExpandResult { let fileNames: string[]; if (hasProperty(json, "files")) { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 709a331e022..089ed967515 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -171,6 +171,20 @@ namespace ts { return result; } + export function mapObject(object: Map, f: (key: string, x: T) => [string, U]): Map { + let result: Map = {}; + if (object) { + result = {}; + for (const v of getKeys(object)) { + const [key, value]: [string, U] = f(v, object[v]) || [undefined, undefined]; + if (key !== undefined) { + result[key] = value; + } + } + } + return result; + } + export function concatenate(array1: T[], array2: T[]): T[] { if (!array2 || !array2.length) return array1; if (!array1 || !array1.length) return array2; @@ -357,6 +371,20 @@ namespace ts { return result; } + export function assign, T2, T3>(t: T1, arg1: T2, arg2: T3): T1 & T2 & T3; + export function assign, T2>(t: T1, arg1: T2): T1 & T2; + export function assign>(t: T1, ...args: any[]): any; + export function assign>(t: T1, ...args: any[]) { + for (const arg of args) { + for (const p of getKeys(arg)) { + if (hasProperty(arg, p)) { + t[p] = arg[p]; + } + } + } + return t; + } + export function forEachValue(map: Map, callback: (value: T) => U): U { let result: U; for (const id in map) { @@ -941,7 +969,7 @@ namespace ts { * [^./] # matches everything up to the first . character (excluding directory seperators) * (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension */ - const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; + const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; const singleAsteriskRegexFragmentOther = "[^/]*"; export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8126d5c605e..fedaf02b4a0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3031,5 +3031,14 @@ "Unknown typing option '{0}'.": { "category": "Error", "code": 17010 + }, + + "Circularity detected while resolving configuration: {0}": { + "category": "Error", + "code": 18000 + }, + "The path in an 'extends' options must be relative or rooted.": { + "category": "Error", + "code": 18001 } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 072209aa496..95e2e358e24 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1693,6 +1693,8 @@ namespace ts { * @param path The path to test. */ fileExists(path: string): boolean; + + readFile(path: string): string; } export interface WriteFileCallback { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index f27e7e1c174..6649463edb9 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1540,7 +1540,8 @@ namespace Harness { const parseConfigHost: ts.ParseConfigHost = { useCaseSensitiveFileNames: false, readDirectory: (name) => [], - fileExists: (name) => true + fileExists: (name) => true, + readFile: (name) => ts.forEach(testUnitData, data => data.name.toLowerCase() === name.toLowerCase() ? data.content : undefined) }; // check if project has tsconfig.json in the list of files diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 038b2dbe359..64ed9ff79a4 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -222,6 +222,7 @@ class ProjectRunner extends RunnerBase { useCaseSensitiveFileNames: Harness.IO.useCaseSensitiveFileNames(), fileExists, readDirectory, + readFile }; const configParseResult = ts.parseJsonConfigFileContent(configObject, configParseHost, ts.getDirectoryPath(configFileName), compilerOptions); if (configParseResult.errors.length > 0) { @@ -295,6 +296,10 @@ class ProjectRunner extends RunnerBase { return Harness.IO.fileExists(getFileNameInTheProjectTest(fileName)); } + function readFile(fileName: string): string { + return Harness.IO.readFile(getFileNameInTheProjectTest(fileName)); + } + function getSourceFileText(fileName: string): string { let text: string = undefined; try { diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 1266ffa5d37..57e6705318c 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -79,6 +79,7 @@ namespace RWC { useCaseSensitiveFileNames: Harness.IO.useCaseSensitiveFileNames(), fileExists: Harness.IO.fileExists, readDirectory: Harness.IO.readDirectory, + readFile: Harness.IO.readFile }; const configParseResult = ts.parseJsonConfigFileContent(parsedTsconfigFileContents.config, configParseHost, ts.getDirectoryPath(tsconfigFile.path)); fileNames = configParseResult.fileNames; diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 3b9025c27c3..11824e16d9d 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -86,6 +86,7 @@ "./unittests/moduleResolution.ts", "./unittests/tsconfigParsing.ts", "./unittests/commandLineParsing.ts", + "./unittests/configurationExtension.ts", "./unittests/convertCompilerOptionsFromJson.ts", "./unittests/convertTypingOptionsFromJson.ts", "./unittests/tsserverProjectSystem.ts", diff --git a/src/harness/unittests/configurationExtension.ts b/src/harness/unittests/configurationExtension.ts new file mode 100644 index 00000000000..21584d4b67d --- /dev/null +++ b/src/harness/unittests/configurationExtension.ts @@ -0,0 +1,230 @@ +/// +/// + +namespace ts { + const testContents = { + "/dev/tsconfig.json": `{ + "extends": "./configs/base", + "files": [ + "main.ts", + "supplemental.ts" + ] +}`, + "/dev/tsconfig.nostrictnull.json": `{ + "extends": "./tsconfig", + "compilerOptions": { + "strictNullChecks": false + } +}`, + "/dev/tsconfig.tests.json": `{ + "extends": ["./configs/tests", "./tsconfig"], + "compilerOptions": { + "module": "commonjs" + } +}`, + "/dev/tsconfig.tests.browser.json": `{ + "extends": ["./configs/tests", "./tsconfig"], + "compilerOptions": { + "module": "amd" + } +}`, + "/dev/configs/base.json": `{ + "compilerOptions": { + "allowJs": true, + "noImplicitAny": true, + "strictNullChecks": true + } +}`, + "/dev/configs/tests.json": `{ + "compilerOptions": { + "preserveConstEnums": true, + "removeComments": false, + "sourceMap": true + }, + "exclude": [ + "../tests/baselines", + "../tests/scenarios" + ], + "include": [ + "../tests/**/*.ts" + ] +}`, + "/dev/circular.json": `{ + "extends": "./circular2", + "compilerOptions": { + "module": "amd" + } +}`, + "/dev/circular2.json": `{ + "extends": "./circular", + "compilerOptions": { + "module": "commonjs" + } +}`, + "/dev/missing.json": `{ + "extends": "./missing2", + "compilerOptions": { + "types": [] + } +}`, + "/dev/failure.json": `{ + "extends": "./failure2.json", + "compilerOptions": { + "typeRoots": [] + } +}`, + "/dev/failure2.json": `{ + "excludes": ["*.js"] +}`, + "/dev/multi.json": `{ + "extends": ["./configs/first", "./configs/second"], + "compilerOptions": { + "allowJs": false + } +}`, + "/dev/configs/first.json": `{ + "extends": "./base", + "compilerOptions": { + "module": "commonjs" + }, + "files": ["../main.ts"] +}`, + "/dev/configs/second.json": `{ + "extends": "./base", + "compilerOptions": { + "module": "amd" + }, + "include": ["../supplemental.*"] +}`, + "/dev/extends.json": `{ "extends": 42 }`, + "/dev/extends2.json": `{ "extends": "configs/base" }`, + "/dev/main.ts": "", + "/dev/supplemental.ts": "", + "/dev/tests/unit/spec.ts": "", + "/dev/tests/utils.ts": "", + "/dev/tests/scenarios/first.json": "", + "/dev/tests/baselines/first/output.ts": "" + }; + + const caseInsensitiveBasePath = "c:/dev/"; + const caseInsensitiveHost = new Utils.MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, mapObject(testContents, (key, content) => [`c:${key}`, content])); + + const caseSensitiveBasePath = "/dev/"; + const caseSensitiveHost = new Utils.MockParseConfigHost(caseSensitiveBasePath, /*useCaseSensitiveFileNames*/ true, testContents); + + function verifyDiagnostics(actual: Diagnostic[], expected: {code: number, category: DiagnosticCategory, messageText: string}[]) { + assert.isTrue(expected.length === actual.length, `Expected error: ${JSON.stringify(expected)}. Actual error: ${JSON.stringify(actual)}.`); + for (let i = 0; i < actual.length; i++) { + const actualError = actual[i]; + const expectedError = expected[i]; + assert.equal(actualError.code, expectedError.code, "Error code mismatch"); + assert.equal(actualError.category, expectedError.category, "Category mismatch"); + assert.equal(flattenDiagnosticMessageText(actualError.messageText, "\n"), expectedError.messageText); + } + } + + describe("Configuration Extension", () => { + forEach<[string, string, Utils.MockParseConfigHost], void>([ + ["under a case insensitive host", caseInsensitiveBasePath, caseInsensitiveHost], + ["under a case sensitive host", caseSensitiveBasePath, caseSensitiveHost] + ], ([testName, basePath, host]) => { + function testSuccess(name: string, entry: string, expected: CompilerOptions, expectedFiles: string[]) { + it(name, () => { + const {config, error} = ts.readConfigFile(entry, name => host.readFile(name)); + assert(config && !error, flattenDiagnosticMessageText(error && error.messageText, "\n")); + const parsed = ts.parseJsonConfigFileContent(config, host, basePath, {}, entry); + assert(!parsed.errors.length, flattenDiagnosticMessageText(parsed.errors[0] && parsed.errors[0].messageText, "\n")); + expected.configFilePath = entry; + assert.deepEqual(parsed.options, expected); + assert.deepEqual(parsed.fileNames, expectedFiles); + }); + } + + function testFailure(name: string, entry: string, expectedDiagnostics: {code: number, category: DiagnosticCategory, messageText: string}[]) { + it(name, () => { + const {config, error} = ts.readConfigFile(entry, name => host.readFile(name)); + assert(config && !error, flattenDiagnosticMessageText(error && error.messageText, "\n")); + const parsed = ts.parseJsonConfigFileContent(config, host, basePath, {}, entry); + verifyDiagnostics(parsed.errors, expectedDiagnostics); + }); + } + + describe(testName, () => { + testSuccess("can resolve an extension with a base extension", "tsconfig.json", { + allowJs: true, + noImplicitAny: true, + strictNullChecks: true, + }, [ + combinePaths(basePath, "main.ts"), + combinePaths(basePath, "supplemental.ts"), + ]); + + testSuccess("can resolve an extension with a base extension that overrides options", "tsconfig.nostrictnull.json", { + allowJs: true, + noImplicitAny: true, + strictNullChecks: false, + }, [ + combinePaths(basePath, "main.ts"), + combinePaths(basePath, "supplemental.ts"), + ]); + + testSuccess("can resolve an extension with a multiple base extensions that overrides options", "tsconfig.tests.json", { + allowJs: true, + noImplicitAny: true, + strictNullChecks: true, + preserveConstEnums: true, + removeComments: false, + sourceMap: true, + module: ts.ModuleKind.CommonJS, + }, [ + combinePaths(basePath, "main.ts"), + combinePaths(basePath, "supplemental.ts"), + combinePaths(basePath, "tests/unit/spec.ts"), + combinePaths(basePath, "tests/utils.ts"), + ]); + + testSuccess("can resolve a diamond dependency graph", "multi.json", { + allowJs: false, + noImplicitAny: true, + strictNullChecks: true, + module: ts.ModuleKind.AMD, + }, [ + combinePaths(basePath, "configs/../main.ts"), // Probably should consider resolving these kinds of paths when they appear + combinePaths(basePath, "supplemental.ts"), + ]); + + testFailure("can report errors on circular imports", "circular.json", [ + { + code: 18000, + category: DiagnosticCategory.Error, + messageText: `Circularity detected while resolving configuration: ${[combinePaths(basePath, "circular.json"), combinePaths(basePath, "circular2.json"), combinePaths(basePath, "circular.json")].join(" -> ")}` + } + ]); + + testFailure("can report missing configurations", "missing.json", [{ + code: 6096, + category: DiagnosticCategory.Message, + messageText: `File './missing2' does not exist.` + }]); + + testFailure("can report errors in extended configs", "failure.json", [{ + code: 6114, + category: DiagnosticCategory.Error, + messageText: `Unknown option 'excludes'. Did you mean 'exclude'?` + }]); + + testFailure("can error when 'extends' is neither a string nor a string[]", "extends.json", [{ + code: 5024, + category: DiagnosticCategory.Error, + messageText: `Compiler option 'extends' requires a value of type string or string[].` + }]); + + testFailure("can error when 'extends' is neither relative nor rooted.", "extends2.json", [{ + code: 18001, + category: DiagnosticCategory.Error, + messageText: `The path in an 'extends' options must be relative or rooted.` + }]); + }); + }); + }); +} \ No newline at end of file diff --git a/src/harness/virtualFileSystem.ts b/src/harness/virtualFileSystem.ts index 30192b8b8ec..36b25cfd29b 100644 --- a/src/harness/virtualFileSystem.ts +++ b/src/harness/virtualFileSystem.ts @@ -10,9 +10,9 @@ namespace Utils { this.name = name; } - isDirectory() { return false; } - isFile() { return false; } - isFileSystem() { return false; } + isDirectory(): this is VirtualDirectory { return false; } + isFile(): this is VirtualFile { return false; } + isFileSystem(): this is VirtualFileSystem { return false; } } export class VirtualFile extends VirtualFileSystemEntry { @@ -82,9 +82,8 @@ namespace Utils { return file; } else if (entry.isFile()) { - const file = entry; - file.content = content; - return file; + entry.content = content; + return entry; } else { return undefined; @@ -160,10 +159,18 @@ namespace Utils { } export class MockParseConfigHost extends VirtualFileSystem implements ts.ParseConfigHost { - constructor(currentDirectory: string, ignoreCase: boolean, files: string[]) { + constructor(currentDirectory: string, ignoreCase: boolean, files: ts.Map | string[]) { super(currentDirectory, ignoreCase); - for (const file of files) { - this.addFile(file); + const fileNames = (files instanceof Array) ? files : ts.getKeys(files); + for (const file of fileNames) { + this.addFile(file, (files as any)[file]); + } + } + + readFile(path: string): string { + const value = this.traversePath(path); + if (value && value.isFile()) { + return value.content; } } From f7da7e900683db2924e2edbfff4e7e8d3e92d621 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Sun, 14 Aug 2016 19:27:33 -0400 Subject: [PATCH 02/18] More helpful error messaging when a type is used as a value --- src/compiler/checker.ts | 19 +++++++++++++++++- src/compiler/diagnosticMessages.json | 4 ++++ tests/cases/compiler/typeUsedAsValueError.ts | 21 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/cases/compiler/typeUsedAsValueError.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b7b659e1a6..87569ce83e2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -879,7 +879,8 @@ namespace ts { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && - !checkAndReportErrorForExtendingInterface(errorLocation)) { + !checkAndReportErrorForExtendingInterface(errorLocation) && + !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning, nameNotFoundMessage, nameArg)) { error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); } } @@ -989,6 +990,22 @@ namespace ts { } } + function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: string, meaning: SymbolFlags, nameNotFoundMessage: DiagnosticMessage, nameArg: string | Identifier): boolean { + const strictlyValueMeanings = SymbolFlags.Value & ~SymbolFlags.Type; + const strictlyTypeMeanings = SymbolFlags.Type & ~SymbolFlags.Value; + + if (!(meaning & strictlyValueMeanings)) { + return false; + } + + const nameAsType = resolveName(errorLocation, name, strictlyTypeMeanings, nameNotFoundMessage, nameArg); + if (nameAsType) { + error(errorLocation, Diagnostics.Cannot_find_name_0_A_type_exists_with_this_name_but_no_value, name); + return true; + } + + return false; + } function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void { Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8126d5c605e..3a2fec2ff02 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1951,6 +1951,10 @@ "category": "Error", "code": 2690 }, + "Cannot find name '{0}'. A type exists with this name, but no value.": { + "category": "Error", + "code": 2691 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/cases/compiler/typeUsedAsValueError.ts b/tests/cases/compiler/typeUsedAsValueError.ts new file mode 100644 index 00000000000..0e0eceb6c3b --- /dev/null +++ b/tests/cases/compiler/typeUsedAsValueError.ts @@ -0,0 +1,21 @@ +interface Interface { + +} + +class Class { + +} + +type typeAliasForClass = Class; +type typeAliasForNumber = number; +type objectType = { x: number }; + +function func(a: number) { + +} + +let one = Interface; +let two = typeAliasForClass; +let three = typeAliasForNumber; +let four = objectType; +func(typeAliasForNumber); \ No newline at end of file From affa6db3db721d739e3229609edefe95c3788ec3 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Sun, 14 Aug 2016 22:26:45 -0400 Subject: [PATCH 03/18] Accept baselines --- .../aliasOnMergedModuleInterface.errors.txt | 4 +- .../reference/assignments.errors.txt | 4 +- ...assExtendsInterfaceInExpression.errors.txt | 4 +- .../errorsOnImportedSymbol.errors.txt | 8 +-- .../es6ExportEqualsInterop.errors.txt | 4 +- ...ignmentOfDeclaredExternalModule.errors.txt | 8 +-- ...onstructInvocationWithNoTypeArg.errors.txt | 4 +- ...inheritFromGenericTypeParameter.errors.txt | 4 +- .../reference/intTypeCheck.errors.txt | 32 ++++++------ .../interfaceNameAsIdentifier.errors.txt | 4 +- .../reference/interfaceNaming1.errors.txt | 8 +-- .../invalidImportAliasIdentifiers.errors.txt | 4 +- .../invalidUndefinedAssignments.errors.txt | 4 +- ...singES6ArrayWithOnlyES6ArrayLib.errors.txt | 4 +- .../reference/newOperator.errors.txt | 4 +- .../reservedNamesInAliases.errors.txt | 4 +- .../reference/returnTypeParameter.errors.txt | 4 +- ...eReservedWordInClassDeclaration.errors.txt | 8 +-- .../typeParameterAsBaseClass.errors.txt | 4 +- .../typeParameterAsBaseType.errors.txt | 8 +-- .../reference/typeUsedAsValueError.errors.txt | 50 +++++++++++++++++++ .../reference/typeUsedAsValueError.js | 41 +++++++++++++++ .../reference/typeofSimple.errors.txt | 4 +- .../reference/typeofTypeParameter.errors.txt | 4 +- .../reference/validNullAssignments.errors.txt | 4 +- tests/cases/compiler/typeUsedAsValueError.ts | 20 ++++---- 26 files changed, 172 insertions(+), 79 deletions(-) create mode 100644 tests/baselines/reference/typeUsedAsValueError.errors.txt create mode 100644 tests/baselines/reference/typeUsedAsValueError.js diff --git a/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt b/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt index 009d405c0f5..9361e201edc 100644 --- a/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt +++ b/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/aliasOnMergedModuleInterface_1.ts(5,16): error TS2304: Cannot find name 'foo'. +tests/cases/compiler/aliasOnMergedModuleInterface_1.ts(5,16): error TS2691: Cannot find name 'foo'. A type exists with this name, but no value. ==== tests/cases/compiler/aliasOnMergedModuleInterface_1.ts (1 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/aliasOnMergedModuleInterface_1.ts(5,16): error TS2304: Cann z.bar("hello"); // This should be ok var x: foo.A = foo.bar("hello"); // foo.A should be ok but foo.bar should be error ~~~ -!!! error TS2304: Cannot find name 'foo'. +!!! error TS2691: Cannot find name 'foo'. A type exists with this name, but no value. ==== tests/cases/compiler/aliasOnMergedModuleInterface_0.ts (0 errors) ==== declare module "foo" diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 05bc4ce1794..04a68499690 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): er tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2304: Cannot find name 'I'. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. ==== tests/cases/conformance/expressions/valuesAndReferences/assignments.ts (6 errors) ==== @@ -49,4 +49,4 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er interface I { } I = null; // Error ~ -!!! error TS2304: Cannot find name 'I'. \ No newline at end of file +!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt index 64b160ea766..084933bae6f 100644 --- a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2304: Cannot find name 'A'. +tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2691: Cannot find name 'A'. A type exists with this name, but no value. ==== tests/cases/compiler/classExtendsInterfaceInExpression.ts (1 errors) ==== @@ -10,5 +10,5 @@ tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2304: C class C extends factory(A) {} ~ -!!! error TS2304: Cannot find name 'A'. +!!! error TS2691: Cannot find name 'A'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/errorsOnImportedSymbol.errors.txt b/tests/baselines/reference/errorsOnImportedSymbol.errors.txt index 19839e4e544..f64eb864445 100644 --- a/tests/baselines/reference/errorsOnImportedSymbol.errors.txt +++ b/tests/baselines/reference/errorsOnImportedSymbol.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2304: Cannot find name 'Sammy'. -tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2304: Cannot find name 'Sammy'. +tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. ==== tests/cases/compiler/errorsOnImportedSymbol_1.ts (2 errors) ==== import Sammy = require("./errorsOnImportedSymbol_0"); var x = new Sammy.Sammy(); ~~~~~ -!!! error TS2304: Cannot find name 'Sammy'. +!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. var y = Sammy.Sammy(); ~~~~~ -!!! error TS2304: Cannot find name 'Sammy'. +!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. ==== tests/cases/compiler/errorsOnImportedSymbol_0.ts (0 errors) ==== diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 98e39cf73e7..038449bff1f 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/main.ts(15,1): error TS2304: Cannot find name 'z1'. +tests/cases/compiler/main.ts(15,1): error TS2691: Cannot find name 'z1'. A type exists with this name, but no value. tests/cases/compiler/main.ts(21,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(23,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(27,8): error TS1192: Module '"interface"' has no default export. @@ -49,7 +49,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses z1.a; ~~ -!!! error TS2304: Cannot find name 'z1'. +!!! error TS2691: Cannot find name 'z1'. A type exists with this name, but no value. z2.a; z3.a; z4.a; diff --git a/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt b/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt index b0bfac0adfd..dc4c48e29ea 100644 --- a/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt +++ b/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2304: Cannot find name 'Sammy'. -tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2304: Cannot find name 'Sammy'. +tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. ==== tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts (2 errors) ==== @@ -7,10 +7,10 @@ tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error T import Sammy = require('./exportAssignmentOfDeclaredExternalModule_0'); var x = new Sammy(); // error to use as constructor as there is not constructor symbol ~~~~~ -!!! error TS2304: Cannot find name 'Sammy'. +!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. var y = Sammy(); // error to use interface name as call target ~~~~~ -!!! error TS2304: Cannot find name 'Sammy'. +!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. var z: Sammy; // no error - z is of type interface Sammy from module 'M' var a = new z(); // constructor - no error var b = z(); // call signature - no error diff --git a/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt b/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt index f155140f4dc..208a354619c 100644 --- a/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt +++ b/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2304: Cannot find name 'Foo'. +tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2691: Cannot find name 'Foo'. A type exists with this name, but no value. ==== tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2 } var f2: Foo = new Foo(3); ~~~ -!!! error TS2304: Cannot find name 'Foo'. +!!! error TS2691: Cannot find name 'Foo'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt b/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt index c043e37575c..0b958ddce21 100644 --- a/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt +++ b/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2304: Cannot find name 'T'. +tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An interface may only extend a class or another interface. ==== tests/cases/compiler/inheritFromGenericTypeParameter.ts (2 errors) ==== class C extends T { } ~ -!!! error TS2304: Cannot find name 'T'. +!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. interface I extends T { } ~ !!! error TS2312: An interface may only extend a class or another interface. \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 0d19c6b2b6e..27ee53da1f8 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -10,7 +10,7 @@ tests/cases/compiler/intTypeCheck.ts(103,5): error TS2322: Type '() => void' is Property 'p' is missing in type '() => void'. tests/cases/compiler/intTypeCheck.ts(106,5): error TS2322: Type 'boolean' is not assignable to type 'i1'. 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(106,21): error TS2691: Cannot find name 'i1'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature '(): any' @@ -21,7 +21,7 @@ tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not as Type 'Base' provides no match for the signature '(): any' 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(120,22): error TS2691: Cannot find name 'i2'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature 'new (): any' @@ -33,12 +33,12 @@ tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is Type '() => void' provides no match for the signature 'new (): any' 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(134,22): error TS2691: Cannot find name 'i3'. A type exists with this name, but no value. 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(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. 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(148,22): error TS2691: Cannot find name 'i4'. A type exists with this name, but no value. 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 '{}'. @@ -51,7 +51,7 @@ tests/cases/compiler/intTypeCheck.ts(159,5): error TS2322: Type '() => void' is Property 'p' is missing in type '() => void'. tests/cases/compiler/intTypeCheck.ts(162,5): error TS2322: Type 'boolean' is not assignable to type 'i5'. 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(162,22): error TS2691: Cannot find name 'i5'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature '(): any' @@ -64,7 +64,7 @@ tests/cases/compiler/intTypeCheck.ts(173,5): error TS2322: Type '() => void' is Type 'void' is not assignable to type 'number'. 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(176,22): error TS2691: Cannot find name 'i6'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature 'new (): any' @@ -76,12 +76,12 @@ tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is Type '() => void' provides no match for the signature 'new (): any' 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(190,22): error TS2691: Cannot find name 'i7'. A type exists with this name, but no value. 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(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. 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(204,22): error TS2691: Cannot find name 'i8'. A type exists with this name, but no value. tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -214,7 +214,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i1'. +!!! error TS2691: Cannot find name 'i1'. A type exists with this name, but no value. var obj10: i1 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -247,7 +247,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i2'. +!!! error TS2691: Cannot find name 'i2'. A type exists with this name, but no value. var obj21: i2 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -281,7 +281,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i3'. +!!! error TS2691: Cannot find name 'i3'. A type exists with this name, but no value. var obj32: i3 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -305,7 +305,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i4'. +!!! error TS2691: Cannot find name 'i4'. A type exists with this name, but no value. var obj43: i4 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -341,7 +341,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i5'. +!!! error TS2691: Cannot find name 'i5'. A type exists with this name, but no value. var obj54: i5 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i6'. +!!! error TS2691: Cannot find name 'i6'. A type exists with this name, but no value. var obj65: i6 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -411,7 +411,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i7'. +!!! error TS2691: Cannot find name 'i7'. A type exists with this name, but no value. var obj76: i7 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -435,7 +435,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2304: Cannot find name 'i8'. +!!! error TS2691: Cannot find name 'i8'. A type exists with this name, but no value. var obj87: i8 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt b/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt index 4be4d858d7b..48e55e299a1 100644 --- a/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt +++ b/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2304: Cannot find name 'C'. +tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2691: Cannot find name 'C'. A type exists with this name, but no value. tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot find name 'm2'. @@ -8,7 +8,7 @@ tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot fi } C(); ~ -!!! error TS2304: Cannot find name 'C'. +!!! error TS2691: Cannot find name 'C'. A type exists with this name, but no value. module m2 { export interface C { diff --git a/tests/baselines/reference/interfaceNaming1.errors.txt b/tests/baselines/reference/interfaceNaming1.errors.txt index 99e0b5c02fa..850b458913c 100644 --- a/tests/baselines/reference/interfaceNaming1.errors.txt +++ b/tests/baselines/reference/interfaceNaming1.errors.txt @@ -1,19 +1,19 @@ -tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2304: Cannot find name 'interface'. +tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. tests/cases/compiler/interfaceNaming1.ts(1,11): error TS1005: ';' expected. -tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2304: Cannot find name 'interface'. +tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. tests/cases/compiler/interfaceNaming1.ts(3,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ==== tests/cases/compiler/interfaceNaming1.ts (4 errors) ==== interface { } ~~~~~~~~~ -!!! error TS2304: Cannot find name 'interface'. +!!! error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. ~ !!! error TS1005: ';' expected. interface interface{ } interface & { } ~~~~~~~~~ -!!! error TS2304: Cannot find name 'interface'. +!!! error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. ~~~ !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt index afe7472570d..522799766bb 100644 --- a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt +++ b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2503: Cannot find namespace 'V'. tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2503: Cannot find namespace 'C'. -tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2503: Cannot find namespace 'I'. +tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. ==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (3 errors) ==== @@ -32,5 +32,5 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde import i = I; ~ -!!! error TS2503: Cannot find namespace 'I'. +!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index 5eff2e7ff1a..d04607455fc 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2304: Cannot find name 'I'. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. @@ -28,7 +28,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t g = x; I = x; ~ -!!! error TS2304: Cannot find name 'I'. +!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. module M { export var x = 1; } M = x; diff --git a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt index f796092fb14..48e4d1f9c9f 100644 --- a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt +++ b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt @@ -1,7 +1,7 @@ error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Number'. -tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2304: Cannot find name 'Array'. +tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2691: Cannot find name 'Array'. A type exists with this name, but no value. !!! error TS2318: Cannot find global type 'Boolean'. @@ -13,7 +13,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib function f(x: number, y: number, z: number) { return Array.from(arguments); ~~~~~ -!!! error TS2304: Cannot find name 'Array'. +!!! error TS2691: Cannot find name 'Array'. A type exists with this name, but no value. } f(1, 2, 3); diff --git a/tests/baselines/reference/newOperator.errors.txt b/tests/baselines/reference/newOperator.errors.txt index 7998217f2e5..00d33b13723 100644 --- a/tests/baselines/reference/newOperator.errors.txt +++ b/tests/baselines/reference/newOperator.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/newOperator.ts(3,13): error TS2304: Cannot find name 'ifc'. +tests/cases/compiler/newOperator.ts(3,13): error TS2691: Cannot find name 'ifc'. A type exists with this name, but no value. tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(11,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(12,5): error TS2304: Cannot find name 'string'. @@ -17,7 +17,7 @@ tests/cases/compiler/newOperator.ts(45,23): error TS1150: 'new T[]' cannot be us // Attempting to 'new' an interface yields poor error var i = new ifc(); ~~~ -!!! error TS2304: Cannot find name 'ifc'. +!!! error TS2691: Cannot find name 'ifc'. A type exists with this name, but no value. // Parens are optional var x = new Date; diff --git a/tests/baselines/reference/reservedNamesInAliases.errors.txt b/tests/baselines/reference/reservedNamesInAliases.errors.txt index 5c17158053e..c999841a322 100644 --- a/tests/baselines/reference/reservedNamesInAliases.errors.txt +++ b/tests/baselines/reference/reservedNamesInAliases.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(5,6): error tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,1): error TS2304: Cannot find name 'type'. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1005: ';' expected. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1109: Expression expected. -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2304: Cannot find name 'I'. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. ==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (8 errors) ==== @@ -30,4 +30,4 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error ~ !!! error TS1109: Expression expected. ~ -!!! error TS2304: Cannot find name 'I'. \ No newline at end of file +!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/returnTypeParameter.errors.txt b/tests/baselines/reference/returnTypeParameter.errors.txt index 1bd9f6a63f6..cfb5d4759ca 100644 --- a/tests/baselines/reference/returnTypeParameter.errors.txt +++ b/tests/baselines/reference/returnTypeParameter.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/returnTypeParameter.ts(1,22): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. -tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2304: Cannot find name 'T'. +tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. ==== tests/cases/compiler/returnTypeParameter.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2304: Cannot find nam !!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. function f2(a: T): T { return T; } // bug was that this satisfied the return statement requirement ~ -!!! error TS2304: Cannot find name 'T'. \ No newline at end of file +!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt index 0b868960bed..a1f75152ddf 100644 --- a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt +++ b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt @@ -16,9 +16,9 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,9): error TS tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2503: Cannot find namespace 'public'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2691: Cannot find name 'public'. A type exists with this name, but no value. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2503: Cannot find namespace 'public'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2691: Cannot find name 'public'. A type exists with this name, but no value. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS2304: Cannot find name 'package'. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. @@ -88,12 +88,12 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS2503: Cannot find namespace 'public'. +!!! error TS2691: Cannot find name 'public'. A type exists with this name, but no value. class F1 implements public.private.implements { } ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS2503: Cannot find namespace 'public'. +!!! error TS2691: Cannot find name 'public'. A type exists with this name, but no value. class G extends package { } ~~~~~~~ !!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. diff --git a/tests/baselines/reference/typeParameterAsBaseClass.errors.txt b/tests/baselines/reference/typeParameterAsBaseClass.errors.txt index dec7f7f2a4a..2f4d0dd46b9 100644 --- a/tests/baselines/reference/typeParameterAsBaseClass.errors.txt +++ b/tests/baselines/reference/typeParameterAsBaseClass.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2304: Cannot find name 'T'. +tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class may only implement another class or interface. ==== tests/cases/compiler/typeParameterAsBaseClass.ts (2 errors) ==== class C extends T {} ~ -!!! error TS2304: Cannot find name 'T'. +!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. class C2 implements T {} ~ !!! error TS2422: A class may only implement another class or interface. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterAsBaseType.errors.txt b/tests/baselines/reference/typeParameterAsBaseType.errors.txt index 835b2369948..7f56299bd6e 100644 --- a/tests/baselines/reference/typeParameterAsBaseType.errors.txt +++ b/tests/baselines/reference/typeParameterAsBaseType.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2304: Cannot find name 'T'. -tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2304: Cannot find name 'U'. +tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2691: Cannot find name 'U'. A type exists with this name, but no value. tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(7,24): error TS2312: An interface may only extend a class or another interface. tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): error TS2312: An interface may only extend a class or another interface. @@ -10,10 +10,10 @@ tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): e class C extends T { } ~ -!!! error TS2304: Cannot find name 'T'. +!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. class C2 extends U { } ~ -!!! error TS2304: Cannot find name 'U'. +!!! error TS2691: Cannot find name 'U'. A type exists with this name, but no value. interface I extends T { } ~ diff --git a/tests/baselines/reference/typeUsedAsValueError.errors.txt b/tests/baselines/reference/typeUsedAsValueError.errors.txt new file mode 100644 index 00000000000..af637231585 --- /dev/null +++ b/tests/baselines/reference/typeUsedAsValueError.errors.txt @@ -0,0 +1,50 @@ +tests/cases/compiler/typeUsedAsValueError.ts(16,11): error TS2691: Cannot find name 'Interface'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(17,11): error TS2304: Cannot find name 'InterfaceNotFound'. +tests/cases/compiler/typeUsedAsValueError.ts(18,13): error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(19,16): error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(20,16): error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'. +tests/cases/compiler/typeUsedAsValueError.ts(21,11): error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(22,17): error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(23,17): error TS2304: Cannot find name 'someTypeNotFound'. + + +==== tests/cases/compiler/typeUsedAsValueError.ts (8 errors) ==== + interface Interface { + + } + + class SomeClass { + + } + + type TypeAliasForSomeClass = SomeClass; + type someType = { x: number }; + + function acceptsSomeType(a: someType) { + + } + + let one = Interface; + ~~~~~~~~~ +!!! error TS2691: Cannot find name 'Interface'. A type exists with this name, but no value. + let two = InterfaceNotFound; + ~~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'InterfaceNotFound'. + let three = TypeAliasForSomeClass; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. + let four = new TypeAliasForSomeClass(); + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. + let five = new TypeAliasForSomeClassNotFound(); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'. + let six = someType; + ~~~~~~~~ +!!! error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. + acceptsSomeType(someType); + ~~~~~~~~ +!!! error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. + acceptsSomeType(someTypeNotFound); + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'someTypeNotFound'. \ No newline at end of file diff --git a/tests/baselines/reference/typeUsedAsValueError.js b/tests/baselines/reference/typeUsedAsValueError.js new file mode 100644 index 00000000000..d45299564c0 --- /dev/null +++ b/tests/baselines/reference/typeUsedAsValueError.js @@ -0,0 +1,41 @@ +//// [typeUsedAsValueError.ts] +interface Interface { + +} + +class SomeClass { + +} + +type TypeAliasForSomeClass = SomeClass; +type someType = { x: number }; + +function acceptsSomeType(a: someType) { + +} + +let one = Interface; +let two = InterfaceNotFound; +let three = TypeAliasForSomeClass; +let four = new TypeAliasForSomeClass(); +let five = new TypeAliasForSomeClassNotFound(); +let six = someType; +acceptsSomeType(someType); +acceptsSomeType(someTypeNotFound); + +//// [typeUsedAsValueError.js] +var SomeClass = (function () { + function SomeClass() { + } + return SomeClass; +}()); +function acceptsSomeType(a) { +} +var one = Interface; +var two = InterfaceNotFound; +var three = TypeAliasForSomeClass; +var four = new TypeAliasForSomeClass(); +var five = new TypeAliasForSomeClassNotFound(); +var six = someType; +acceptsSomeType(someType); +acceptsSomeType(someTypeNotFound); diff --git a/tests/baselines/reference/typeofSimple.errors.txt b/tests/baselines/reference/typeofSimple.errors.txt index 845a9fbbce3..08bbb8ff10c 100644 --- a/tests/baselines/reference/typeofSimple.errors.txt +++ b/tests/baselines/reference/typeofSimple.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/typeofSimple.ts(3,5): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/compiler/typeofSimple.ts(8,21): error TS2304: Cannot find name 'J'. +tests/cases/compiler/typeofSimple.ts(8,21): error TS2691: Cannot find name 'J'. A type exists with this name, but no value. ==== tests/cases/compiler/typeofSimple.ts (2 errors) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/typeofSimple.ts(8,21): error TS2304: Cannot find name 'J'. var numberJ: typeof J; //Error, cannot reference type in typeof ~ -!!! error TS2304: Cannot find name 'J'. +!!! error TS2691: Cannot find name 'J'. A type exists with this name, but no value. var numberI: I; var fun: () => I; diff --git a/tests/baselines/reference/typeofTypeParameter.errors.txt b/tests/baselines/reference/typeofTypeParameter.errors.txt index f610b4696ca..7843ee38cc6 100644 --- a/tests/baselines/reference/typeofTypeParameter.errors.txt +++ b/tests/baselines/reference/typeofTypeParameter.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2304: Cannot find name 'T'. +tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. ==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts (1 errors) ==== @@ -6,6 +6,6 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts var a: typeof x; var y: typeof T; ~ -!!! error TS2304: Cannot find name 'T'. +!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. return a; } \ No newline at end of file diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index 057d6ce4791..7cf05cd9f6c 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2304: Cannot find name 'I'. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. @@ -31,7 +31,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err g = null; // ok I = null; // error ~ -!!! error TS2304: Cannot find name 'I'. +!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. module M { export var x = 1; } M = null; // error diff --git a/tests/cases/compiler/typeUsedAsValueError.ts b/tests/cases/compiler/typeUsedAsValueError.ts index 0e0eceb6c3b..16c1e396d70 100644 --- a/tests/cases/compiler/typeUsedAsValueError.ts +++ b/tests/cases/compiler/typeUsedAsValueError.ts @@ -2,20 +2,22 @@ interface Interface { } -class Class { +class SomeClass { } -type typeAliasForClass = Class; -type typeAliasForNumber = number; -type objectType = { x: number }; +type TypeAliasForSomeClass = SomeClass; +type someType = { x: number }; -function func(a: number) { +function acceptsSomeType(a: someType) { } let one = Interface; -let two = typeAliasForClass; -let three = typeAliasForNumber; -let four = objectType; -func(typeAliasForNumber); \ No newline at end of file +let two = InterfaceNotFound; +let three = TypeAliasForSomeClass; +let four = new TypeAliasForSomeClass(); +let five = new TypeAliasForSomeClassNotFound(); +let six = someType; +acceptsSomeType(someType); +acceptsSomeType(someTypeNotFound); \ No newline at end of file From fde0a2898871ff1f7e07766bf8d183e6cdd7911e Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Mon, 15 Aug 2016 02:23:39 -0400 Subject: [PATCH 04/18] Preserve 'Cannot find namespace' errors --- src/compiler/checker.ts | 2 +- .../reference/invalidImportAliasIdentifiers.errors.txt | 4 ++-- .../strictModeReservedWordInClassDeclaration.errors.txt | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 87569ce83e2..18da3916652 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -994,7 +994,7 @@ namespace ts { const strictlyValueMeanings = SymbolFlags.Value & ~SymbolFlags.Type; const strictlyTypeMeanings = SymbolFlags.Type & ~SymbolFlags.Value; - if (!(meaning & strictlyValueMeanings)) { + if (!(meaning & strictlyValueMeanings) || meaning & SymbolFlags.NamespaceModule) { return false; } diff --git a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt index 522799766bb..afe7472570d 100644 --- a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt +++ b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2503: Cannot find namespace 'V'. tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2503: Cannot find namespace 'C'. -tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2503: Cannot find namespace 'I'. ==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (3 errors) ==== @@ -32,5 +32,5 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde import i = I; ~ -!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +!!! error TS2503: Cannot find namespace 'I'. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt index a1f75152ddf..0b868960bed 100644 --- a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt +++ b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt @@ -16,9 +16,9 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,9): error TS tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2691: Cannot find name 'public'. A type exists with this name, but no value. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2503: Cannot find namespace 'public'. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2691: Cannot find name 'public'. A type exists with this name, but no value. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2503: Cannot find namespace 'public'. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS2304: Cannot find name 'package'. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. @@ -88,12 +88,12 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS2691: Cannot find name 'public'. A type exists with this name, but no value. +!!! error TS2503: Cannot find namespace 'public'. class F1 implements public.private.implements { } ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS2691: Cannot find name 'public'. A type exists with this name, but no value. +!!! error TS2503: Cannot find namespace 'public'. class G extends package { } ~~~~~~~ !!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. From 5762519071635bf966d1ab706e77b76f66cb1ff9 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Mon, 15 Aug 2016 03:32:21 -0400 Subject: [PATCH 05/18] Resolve aliases to preserve 'Cannot find name' errors for namespace imports --- src/compiler/checker.ts | 15 ++++++-- .../aliasOnMergedModuleInterface.errors.txt | 4 +- .../typeUsedAsValueError2.errors.txt | 28 ++++++++++++++ .../reference/typeUsedAsValueError2.js | 37 +++++++++++++++++++ tests/cases/compiler/typeUsedAsValueError2.ts | 21 +++++++++++ 5 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/typeUsedAsValueError2.errors.txt create mode 100644 tests/baselines/reference/typeUsedAsValueError2.js create mode 100644 tests/cases/compiler/typeUsedAsValueError2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 18da3916652..dbf84b41f85 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -999,12 +999,19 @@ namespace ts { } const nameAsType = resolveName(errorLocation, name, strictlyTypeMeanings, nameNotFoundMessage, nameArg); - if (nameAsType) { - error(errorLocation, Diagnostics.Cannot_find_name_0_A_type_exists_with_this_name_but_no_value, name); - return true; + if (!nameAsType) { + return false; } - return false; + if (nameAsType.flags & SymbolFlags.Alias) { + const resolvedSymbol = resolveAlias(nameAsType); + if (resolvedSymbol.flags & SymbolFlags.NamespaceModule) { + return false; + } + } + + error(errorLocation, Diagnostics.Cannot_find_name_0_A_type_exists_with_this_name_but_no_value, name); + return true; } function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void { diff --git a/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt b/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt index 9361e201edc..009d405c0f5 100644 --- a/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt +++ b/tests/baselines/reference/aliasOnMergedModuleInterface.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/aliasOnMergedModuleInterface_1.ts(5,16): error TS2691: Cannot find name 'foo'. A type exists with this name, but no value. +tests/cases/compiler/aliasOnMergedModuleInterface_1.ts(5,16): error TS2304: Cannot find name 'foo'. ==== tests/cases/compiler/aliasOnMergedModuleInterface_1.ts (1 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/aliasOnMergedModuleInterface_1.ts(5,16): error TS2691: Cann z.bar("hello"); // This should be ok var x: foo.A = foo.bar("hello"); // foo.A should be ok but foo.bar should be error ~~~ -!!! error TS2691: Cannot find name 'foo'. A type exists with this name, but no value. +!!! error TS2304: Cannot find name 'foo'. ==== tests/cases/compiler/aliasOnMergedModuleInterface_0.ts (0 errors) ==== declare module "foo" diff --git a/tests/baselines/reference/typeUsedAsValueError2.errors.txt b/tests/baselines/reference/typeUsedAsValueError2.errors.txt new file mode 100644 index 00000000000..8849a904bdf --- /dev/null +++ b/tests/baselines/reference/typeUsedAsValueError2.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/world.ts(4,1): error TS2691: Cannot find name 'HelloInterface'. A type exists with this name, but no value. +tests/cases/compiler/world.ts(5,1): error TS2304: Cannot find name 'HelloNamespace'. + + +==== tests/cases/compiler/world.ts (2 errors) ==== + import HelloInterface = require("helloInterface"); + import HelloNamespace = require("helloNamespace"); + + HelloInterface.world; + ~~~~~~~~~~~~~~ +!!! error TS2691: Cannot find name 'HelloInterface'. A type exists with this name, but no value. + HelloNamespace.world; + ~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'HelloNamespace'. +==== tests/cases/compiler/helloInterface.ts (0 errors) ==== + interface HelloInterface { + world: any; + } + + export = HelloInterface; + +==== tests/cases/compiler/helloNamespace.ts (0 errors) ==== + namespace HelloNamespace { + export type world = any; + } + + export = HelloNamespace; + \ No newline at end of file diff --git a/tests/baselines/reference/typeUsedAsValueError2.js b/tests/baselines/reference/typeUsedAsValueError2.js new file mode 100644 index 00000000000..c3bd736cbb7 --- /dev/null +++ b/tests/baselines/reference/typeUsedAsValueError2.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/typeUsedAsValueError2.ts] //// + +//// [helloInterface.ts] +interface HelloInterface { + world: any; +} + +export = HelloInterface; + +//// [helloNamespace.ts] +namespace HelloNamespace { + export type world = any; +} + +export = HelloNamespace; + +//// [world.ts] +import HelloInterface = require("helloInterface"); +import HelloNamespace = require("helloNamespace"); + +HelloInterface.world; +HelloNamespace.world; + +//// [helloInterface.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [helloNamespace.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [world.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + HelloInterface.world; + HelloNamespace.world; +}); diff --git a/tests/cases/compiler/typeUsedAsValueError2.ts b/tests/cases/compiler/typeUsedAsValueError2.ts new file mode 100644 index 00000000000..dd89225ef96 --- /dev/null +++ b/tests/cases/compiler/typeUsedAsValueError2.ts @@ -0,0 +1,21 @@ +// @module: amd +// @filename: helloInterface.ts +interface HelloInterface { + world: any; +} + +export = HelloInterface; + +// @filename: helloNamespace.ts +namespace HelloNamespace { + export type world = any; +} + +export = HelloNamespace; + +// @filename: world.ts +import HelloInterface = require("helloInterface"); +import HelloNamespace = require("helloNamespace"); + +HelloInterface.world; +HelloNamespace.world; \ No newline at end of file From f11fef6b4ced3b602f7b04971bbc08772e1791b8 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Sat, 20 Aug 2016 21:25:49 -0400 Subject: [PATCH 06/18] Update error code number --- src/compiler/diagnosticMessages.json | 4 +++ .../reference/assignments.errors.txt | 4 +-- ...assExtendsInterfaceInExpression.errors.txt | 4 +-- .../errorsOnImportedSymbol.errors.txt | 8 ++--- .../es6ExportEqualsInterop.errors.txt | 4 +-- ...ignmentOfDeclaredExternalModule.errors.txt | 8 ++--- ...onstructInvocationWithNoTypeArg.errors.txt | 4 +-- ...inheritFromGenericTypeParameter.errors.txt | 4 +-- .../reference/intTypeCheck.errors.txt | 32 +++++++++---------- .../interfaceNameAsIdentifier.errors.txt | 4 +-- .../reference/interfaceNaming1.errors.txt | 8 ++--- .../invalidUndefinedAssignments.errors.txt | 4 +-- ...singES6ArrayWithOnlyES6ArrayLib.errors.txt | 4 +-- .../reference/newOperator.errors.txt | 4 +-- .../reservedNamesInAliases.errors.txt | 4 +-- .../reference/returnTypeParameter.errors.txt | 4 +-- .../typeParameterAsBaseClass.errors.txt | 4 +-- .../typeParameterAsBaseType.errors.txt | 8 ++--- .../reference/typeUsedAsValueError.errors.txt | 20 ++++++------ .../typeUsedAsValueError2.errors.txt | 4 +-- .../reference/typeofSimple.errors.txt | 4 +-- .../reference/typeofTypeParameter.errors.txt | 4 +-- .../reference/validNullAssignments.errors.txt | 4 +-- 23 files changed, 78 insertions(+), 74 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6210a20afa6..7e2b429dd9f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1955,6 +1955,10 @@ "category": "Error", "code": 2691 }, + "Cannot find name '{0}'. A type exists with this name, but no value.": { + "category": "Error", + "code": 2692 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 04a68499690..99457ed5837 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): er tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. ==== tests/cases/conformance/expressions/valuesAndReferences/assignments.ts (6 errors) ==== @@ -49,4 +49,4 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er interface I { } I = null; // Error ~ -!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file +!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt index 084933bae6f..3bfaba31113 100644 --- a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2691: Cannot find name 'A'. A type exists with this name, but no value. +tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2692: Cannot find name 'A'. A type exists with this name, but no value. ==== tests/cases/compiler/classExtendsInterfaceInExpression.ts (1 errors) ==== @@ -10,5 +10,5 @@ tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2691: C class C extends factory(A) {} ~ -!!! error TS2691: Cannot find name 'A'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'A'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/errorsOnImportedSymbol.errors.txt b/tests/baselines/reference/errorsOnImportedSymbol.errors.txt index f64eb864445..960e707cfee 100644 --- a/tests/baselines/reference/errorsOnImportedSymbol.errors.txt +++ b/tests/baselines/reference/errorsOnImportedSymbol.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. -tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. ==== tests/cases/compiler/errorsOnImportedSymbol_1.ts (2 errors) ==== import Sammy = require("./errorsOnImportedSymbol_0"); var x = new Sammy.Sammy(); ~~~~~ -!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. var y = Sammy.Sammy(); ~~~~~ -!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. ==== tests/cases/compiler/errorsOnImportedSymbol_0.ts (0 errors) ==== diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 038449bff1f..e5ca006133b 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/main.ts(15,1): error TS2691: Cannot find name 'z1'. A type exists with this name, but no value. +tests/cases/compiler/main.ts(15,1): error TS2692: Cannot find name 'z1'. A type exists with this name, but no value. tests/cases/compiler/main.ts(21,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(23,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(27,8): error TS1192: Module '"interface"' has no default export. @@ -49,7 +49,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses z1.a; ~~ -!!! error TS2691: Cannot find name 'z1'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'z1'. A type exists with this name, but no value. z2.a; z3.a; z4.a; diff --git a/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt b/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt index dc4c48e29ea..2d54bfd7e6d 100644 --- a/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt +++ b/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. -tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. ==== tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts (2 errors) ==== @@ -7,10 +7,10 @@ tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error T import Sammy = require('./exportAssignmentOfDeclaredExternalModule_0'); var x = new Sammy(); // error to use as constructor as there is not constructor symbol ~~~~~ -!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. var y = Sammy(); // error to use interface name as call target ~~~~~ -!!! error TS2691: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. var z: Sammy; // no error - z is of type interface Sammy from module 'M' var a = new z(); // constructor - no error var b = z(); // call signature - no error diff --git a/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt b/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt index 208a354619c..cef121150fb 100644 --- a/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt +++ b/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2691: Cannot find name 'Foo'. A type exists with this name, but no value. +tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2692: Cannot find name 'Foo'. A type exists with this name, but no value. ==== tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2 } var f2: Foo = new Foo(3); ~~~ -!!! error TS2691: Cannot find name 'Foo'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Foo'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt b/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt index 0b958ddce21..86cbc3ac1d6 100644 --- a/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt +++ b/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An interface may only extend a class or another interface. ==== tests/cases/compiler/inheritFromGenericTypeParameter.ts (2 errors) ==== class C extends T { } ~ -!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. interface I extends T { } ~ !!! error TS2312: An interface may only extend a class or another interface. \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 27ee53da1f8..3cd1997dc5a 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -10,7 +10,7 @@ tests/cases/compiler/intTypeCheck.ts(103,5): error TS2322: Type '() => void' is Property 'p' is missing in type '() => void'. tests/cases/compiler/intTypeCheck.ts(106,5): error TS2322: Type 'boolean' is not assignable to type 'i1'. tests/cases/compiler/intTypeCheck.ts(106,20): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(106,21): error TS2691: Cannot find name 'i1'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(106,21): error TS2692: Cannot find name 'i1'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature '(): any' @@ -21,7 +21,7 @@ tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not as Type 'Base' provides no match for the signature '(): any' 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 TS2691: Cannot find name 'i2'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(120,22): error TS2692: Cannot find name 'i2'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature 'new (): any' @@ -33,12 +33,12 @@ tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is Type '() => void' provides no match for the signature 'new (): any' 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 TS2691: Cannot find name 'i3'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(134,22): error TS2692: Cannot find name 'i3'. A type exists with this name, but no value. 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(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(148,22): error TS2691: Cannot find name 'i4'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(148,22): error TS2692: Cannot find name 'i4'. A type exists with this name, but no value. 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 '{}'. @@ -51,7 +51,7 @@ tests/cases/compiler/intTypeCheck.ts(159,5): error TS2322: Type '() => void' is Property 'p' is missing in type '() => void'. tests/cases/compiler/intTypeCheck.ts(162,5): error TS2322: Type 'boolean' is not assignable to type 'i5'. tests/cases/compiler/intTypeCheck.ts(162,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(162,22): error TS2691: Cannot find name 'i5'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(162,22): error TS2692: Cannot find name 'i5'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature '(): any' @@ -64,7 +64,7 @@ tests/cases/compiler/intTypeCheck.ts(173,5): error TS2322: Type '() => void' is Type 'void' is not assignable to type 'number'. 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 TS2691: Cannot find name 'i6'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(176,22): error TS2692: Cannot find name 'i6'. A type exists with this name, but no value. 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'. Type '{}' provides no match for the signature 'new (): any' @@ -76,12 +76,12 @@ tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is Type '() => void' provides no match for the signature 'new (): any' 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 TS2691: Cannot find name 'i7'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(190,22): error TS2692: Cannot find name 'i7'. A type exists with this name, but no value. 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(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(204,22): error TS2691: Cannot find name 'i8'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(204,22): error TS2692: Cannot find name 'i8'. A type exists with this name, but no value. tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -214,7 +214,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i1'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i1'. A type exists with this name, but no value. var obj10: i1 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -247,7 +247,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i2'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i2'. A type exists with this name, but no value. var obj21: i2 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -281,7 +281,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i3'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i3'. A type exists with this name, but no value. var obj32: i3 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -305,7 +305,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i4'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i4'. A type exists with this name, but no value. var obj43: i4 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -341,7 +341,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i5'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i5'. A type exists with this name, but no value. var obj54: i5 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i6'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i6'. A type exists with this name, but no value. var obj65: i6 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -411,7 +411,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i7'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i7'. A type exists with this name, but no value. var obj76: i7 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -435,7 +435,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2691: Cannot find name 'i8'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'i8'. A type exists with this name, but no value. var obj87: i8 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt b/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt index 48e55e299a1..f3ee47573f7 100644 --- a/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt +++ b/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2691: Cannot find name 'C'. A type exists with this name, but no value. +tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2692: Cannot find name 'C'. A type exists with this name, but no value. tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot find name 'm2'. @@ -8,7 +8,7 @@ tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot fi } C(); ~ -!!! error TS2691: Cannot find name 'C'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'C'. A type exists with this name, but no value. module m2 { export interface C { diff --git a/tests/baselines/reference/interfaceNaming1.errors.txt b/tests/baselines/reference/interfaceNaming1.errors.txt index 850b458913c..bdd3ca6c1f8 100644 --- a/tests/baselines/reference/interfaceNaming1.errors.txt +++ b/tests/baselines/reference/interfaceNaming1.errors.txt @@ -1,19 +1,19 @@ -tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. +tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. tests/cases/compiler/interfaceNaming1.ts(1,11): error TS1005: ';' expected. -tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. +tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. tests/cases/compiler/interfaceNaming1.ts(3,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ==== tests/cases/compiler/interfaceNaming1.ts (4 errors) ==== interface { } ~~~~~~~~~ -!!! error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. ~ !!! error TS1005: ';' expected. interface interface{ } interface & { } ~~~~~~~~~ -!!! error TS2691: Cannot find name 'interface'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. ~~~ !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index d04607455fc..2e9f6efb137 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. @@ -28,7 +28,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t g = x; I = x; ~ -!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. module M { export var x = 1; } M = x; diff --git a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt index 48e4d1f9c9f..372d2e797e0 100644 --- a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt +++ b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt @@ -1,7 +1,7 @@ error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Number'. -tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2691: Cannot find name 'Array'. A type exists with this name, but no value. +tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2692: Cannot find name 'Array'. A type exists with this name, but no value. !!! error TS2318: Cannot find global type 'Boolean'. @@ -13,7 +13,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib function f(x: number, y: number, z: number) { return Array.from(arguments); ~~~~~ -!!! error TS2691: Cannot find name 'Array'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Array'. A type exists with this name, but no value. } f(1, 2, 3); diff --git a/tests/baselines/reference/newOperator.errors.txt b/tests/baselines/reference/newOperator.errors.txt index 00d33b13723..e8d834824e5 100644 --- a/tests/baselines/reference/newOperator.errors.txt +++ b/tests/baselines/reference/newOperator.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/newOperator.ts(3,13): error TS2691: Cannot find name 'ifc'. A type exists with this name, but no value. +tests/cases/compiler/newOperator.ts(3,13): error TS2692: Cannot find name 'ifc'. A type exists with this name, but no value. tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(11,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(12,5): error TS2304: Cannot find name 'string'. @@ -17,7 +17,7 @@ tests/cases/compiler/newOperator.ts(45,23): error TS1150: 'new T[]' cannot be us // Attempting to 'new' an interface yields poor error var i = new ifc(); ~~~ -!!! error TS2691: Cannot find name 'ifc'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'ifc'. A type exists with this name, but no value. // Parens are optional var x = new Date; diff --git a/tests/baselines/reference/reservedNamesInAliases.errors.txt b/tests/baselines/reference/reservedNamesInAliases.errors.txt index c999841a322..99dc5137714 100644 --- a/tests/baselines/reference/reservedNamesInAliases.errors.txt +++ b/tests/baselines/reference/reservedNamesInAliases.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(5,6): error tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,1): error TS2304: Cannot find name 'type'. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1005: ';' expected. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1109: Expression expected. -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. ==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (8 errors) ==== @@ -30,4 +30,4 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error ~ !!! error TS1109: Expression expected. ~ -!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file +!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/returnTypeParameter.errors.txt b/tests/baselines/reference/returnTypeParameter.errors.txt index cfb5d4759ca..7b762f0938a 100644 --- a/tests/baselines/reference/returnTypeParameter.errors.txt +++ b/tests/baselines/reference/returnTypeParameter.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/returnTypeParameter.ts(1,22): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. -tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. ==== tests/cases/compiler/returnTypeParameter.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2691: Cannot find nam !!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. function f2(a: T): T { return T; } // bug was that this satisfied the return statement requirement ~ -!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. \ No newline at end of file +!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterAsBaseClass.errors.txt b/tests/baselines/reference/typeParameterAsBaseClass.errors.txt index 2f4d0dd46b9..8254f12cb1c 100644 --- a/tests/baselines/reference/typeParameterAsBaseClass.errors.txt +++ b/tests/baselines/reference/typeParameterAsBaseClass.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class may only implement another class or interface. ==== tests/cases/compiler/typeParameterAsBaseClass.ts (2 errors) ==== class C extends T {} ~ -!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. class C2 implements T {} ~ !!! error TS2422: A class may only implement another class or interface. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterAsBaseType.errors.txt b/tests/baselines/reference/typeParameterAsBaseType.errors.txt index 7f56299bd6e..f6b82a85681 100644 --- a/tests/baselines/reference/typeParameterAsBaseType.errors.txt +++ b/tests/baselines/reference/typeParameterAsBaseType.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. -tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2691: Cannot find name 'U'. A type exists with this name, but no value. +tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2692: Cannot find name 'U'. A type exists with this name, but no value. tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(7,24): error TS2312: An interface may only extend a class or another interface. tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): error TS2312: An interface may only extend a class or another interface. @@ -10,10 +10,10 @@ tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): e class C extends T { } ~ -!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. class C2 extends U { } ~ -!!! error TS2691: Cannot find name 'U'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'U'. A type exists with this name, but no value. interface I extends T { } ~ diff --git a/tests/baselines/reference/typeUsedAsValueError.errors.txt b/tests/baselines/reference/typeUsedAsValueError.errors.txt index af637231585..75a83134162 100644 --- a/tests/baselines/reference/typeUsedAsValueError.errors.txt +++ b/tests/baselines/reference/typeUsedAsValueError.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/typeUsedAsValueError.ts(16,11): error TS2691: Cannot find name 'Interface'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(16,11): error TS2692: Cannot find name 'Interface'. A type exists with this name, but no value. tests/cases/compiler/typeUsedAsValueError.ts(17,11): error TS2304: Cannot find name 'InterfaceNotFound'. -tests/cases/compiler/typeUsedAsValueError.ts(18,13): error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. -tests/cases/compiler/typeUsedAsValueError.ts(19,16): error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(18,13): error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(19,16): error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. tests/cases/compiler/typeUsedAsValueError.ts(20,16): error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'. -tests/cases/compiler/typeUsedAsValueError.ts(21,11): error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. -tests/cases/compiler/typeUsedAsValueError.ts(22,17): error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(21,11): error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(22,17): error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. tests/cases/compiler/typeUsedAsValueError.ts(23,17): error TS2304: Cannot find name 'someTypeNotFound'. @@ -26,25 +26,25 @@ tests/cases/compiler/typeUsedAsValueError.ts(23,17): error TS2304: Cannot find n let one = Interface; ~~~~~~~~~ -!!! error TS2691: Cannot find name 'Interface'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'Interface'. A type exists with this name, but no value. let two = InterfaceNotFound; ~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'InterfaceNotFound'. let three = TypeAliasForSomeClass; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. let four = new TypeAliasForSomeClass(); ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2691: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. let five = new TypeAliasForSomeClassNotFound(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'. let six = someType; ~~~~~~~~ -!!! error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. acceptsSomeType(someType); ~~~~~~~~ -!!! error TS2691: Cannot find name 'someType'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. acceptsSomeType(someTypeNotFound); ~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'someTypeNotFound'. \ No newline at end of file diff --git a/tests/baselines/reference/typeUsedAsValueError2.errors.txt b/tests/baselines/reference/typeUsedAsValueError2.errors.txt index 8849a904bdf..8707ffaaafb 100644 --- a/tests/baselines/reference/typeUsedAsValueError2.errors.txt +++ b/tests/baselines/reference/typeUsedAsValueError2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/world.ts(4,1): error TS2691: Cannot find name 'HelloInterface'. A type exists with this name, but no value. +tests/cases/compiler/world.ts(4,1): error TS2692: Cannot find name 'HelloInterface'. A type exists with this name, but no value. tests/cases/compiler/world.ts(5,1): error TS2304: Cannot find name 'HelloNamespace'. @@ -8,7 +8,7 @@ tests/cases/compiler/world.ts(5,1): error TS2304: Cannot find name 'HelloNamespa HelloInterface.world; ~~~~~~~~~~~~~~ -!!! error TS2691: Cannot find name 'HelloInterface'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'HelloInterface'. A type exists with this name, but no value. HelloNamespace.world; ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'HelloNamespace'. diff --git a/tests/baselines/reference/typeofSimple.errors.txt b/tests/baselines/reference/typeofSimple.errors.txt index 08bbb8ff10c..977a8b34d45 100644 --- a/tests/baselines/reference/typeofSimple.errors.txt +++ b/tests/baselines/reference/typeofSimple.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/typeofSimple.ts(3,5): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/compiler/typeofSimple.ts(8,21): error TS2691: Cannot find name 'J'. A type exists with this name, but no value. +tests/cases/compiler/typeofSimple.ts(8,21): error TS2692: Cannot find name 'J'. A type exists with this name, but no value. ==== tests/cases/compiler/typeofSimple.ts (2 errors) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/typeofSimple.ts(8,21): error TS2691: Cannot find name 'J'. var numberJ: typeof J; //Error, cannot reference type in typeof ~ -!!! error TS2691: Cannot find name 'J'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'J'. A type exists with this name, but no value. var numberI: I; var fun: () => I; diff --git a/tests/baselines/reference/typeofTypeParameter.errors.txt b/tests/baselines/reference/typeofTypeParameter.errors.txt index 7843ee38cc6..a4fc868197d 100644 --- a/tests/baselines/reference/typeofTypeParameter.errors.txt +++ b/tests/baselines/reference/typeofTypeParameter.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. ==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts (1 errors) ==== @@ -6,6 +6,6 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts var a: typeof x; var y: typeof T; ~ -!!! error TS2691: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. return a; } \ No newline at end of file diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index 7cf05cd9f6c..d3c403b4ae4 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. @@ -31,7 +31,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err g = null; // ok I = null; // error ~ -!!! error TS2691: Cannot find name 'I'. A type exists with this name, but no value. +!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. module M { export var x = 1; } M = null; // error From 03182bfec58d29973df46b0c95074995b14c768d Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Wed, 24 Aug 2016 21:08:50 -0400 Subject: [PATCH 07/18] Update error message + refactor --- src/compiler/checker.ts | 29 +++++------------ src/compiler/diagnosticMessages.json | 4 +++ .../reference/assignments.errors.txt | 4 +-- ...assExtendsInterfaceInExpression.errors.txt | 4 +-- .../errorsOnImportedSymbol.errors.txt | 8 ++--- .../es6ExportEqualsInterop.errors.txt | 4 +-- ...ignmentOfDeclaredExternalModule.errors.txt | 8 ++--- ...onstructInvocationWithNoTypeArg.errors.txt | 4 +-- ...inheritFromGenericTypeParameter.errors.txt | 4 +-- .../reference/intTypeCheck.errors.txt | 32 +++++++++---------- .../interfaceNameAsIdentifier.errors.txt | 4 +-- .../reference/interfaceNaming1.errors.txt | 8 ++--- .../invalidUndefinedAssignments.errors.txt | 4 +-- ...singES6ArrayWithOnlyES6ArrayLib.errors.txt | 4 +-- .../reference/newOperator.errors.txt | 4 +-- .../reservedNamesInAliases.errors.txt | 4 +-- .../reference/returnTypeParameter.errors.txt | 4 +-- .../typeParameterAsBaseClass.errors.txt | 4 +-- .../typeParameterAsBaseType.errors.txt | 8 ++--- .../reference/typeUsedAsValueError.errors.txt | 20 ++++++------ .../typeUsedAsValueError2.errors.txt | 4 +-- .../reference/typeofSimple.errors.txt | 4 +-- .../reference/typeofTypeParameter.errors.txt | 4 +-- .../reference/validNullAssignments.errors.txt | 4 +-- 24 files changed, 86 insertions(+), 95 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5b89c185822..d5e4f35d60b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -872,7 +872,7 @@ namespace ts { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && - !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning, nameNotFoundMessage, nameArg)) { + !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); } } @@ -982,28 +982,15 @@ namespace ts { } } - function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: string, meaning: SymbolFlags, nameNotFoundMessage: DiagnosticMessage, nameArg: string | Identifier): boolean { - const strictlyValueMeanings = SymbolFlags.Value & ~SymbolFlags.Type; - const strictlyTypeMeanings = SymbolFlags.Type & ~SymbolFlags.Value; - - if (!(meaning & strictlyValueMeanings) || meaning & SymbolFlags.NamespaceModule) { - return false; - } - - const nameAsType = resolveName(errorLocation, name, strictlyTypeMeanings, nameNotFoundMessage, nameArg); - if (!nameAsType) { - return false; - } - - if (nameAsType.flags & SymbolFlags.Alias) { - const resolvedSymbol = resolveAlias(nameAsType); - if (resolvedSymbol.flags & SymbolFlags.NamespaceModule) { - return false; + function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: string, meaning: SymbolFlags): boolean { + if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) { + const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined)); + if (symbol && !(symbol.flags & SymbolFlags.NamespaceModule)) { + error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, name); + return true; } } - - error(errorLocation, Diagnostics.Cannot_find_name_0_A_type_exists_with_this_name_but_no_value, name); - return true; + return false; } function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b8978b32571..645728dab4a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1959,6 +1959,10 @@ "category": "Error", "code": 2692 }, + "'{0}' only refers to a type, but is being used as a value here.": { + "category": "Error", + "code": 2693 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/assignments.errors.txt b/tests/baselines/reference/assignments.errors.txt index 99457ed5837..2e637a6c720 100644 --- a/tests/baselines/reference/assignments.errors.txt +++ b/tests/baselines/reference/assignments.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): er tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2693: 'I' only refers to a type, but is being used as a value here. ==== tests/cases/conformance/expressions/valuesAndReferences/assignments.ts (6 errors) ==== @@ -49,4 +49,4 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er interface I { } I = null; // Error ~ -!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file +!!! error TS2693: 'I' only refers to a type, but is being used as a value here. \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt index 3bfaba31113..754f7a57f6a 100644 --- a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2692: Cannot find name 'A'. A type exists with this name, but no value. +tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2693: 'A' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/classExtendsInterfaceInExpression.ts (1 errors) ==== @@ -10,5 +10,5 @@ tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2692: C class C extends factory(A) {} ~ -!!! error TS2692: Cannot find name 'A'. A type exists with this name, but no value. +!!! error TS2693: 'A' only refers to a type, but is being used as a value here. \ No newline at end of file diff --git a/tests/baselines/reference/errorsOnImportedSymbol.errors.txt b/tests/baselines/reference/errorsOnImportedSymbol.errors.txt index 960e707cfee..127026a8e2c 100644 --- a/tests/baselines/reference/errorsOnImportedSymbol.errors.txt +++ b/tests/baselines/reference/errorsOnImportedSymbol.errors.txt @@ -1,15 +1,15 @@ -tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. -tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2693: 'Sammy' only refers to a type, but is being used as a value here. +tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2693: 'Sammy' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/errorsOnImportedSymbol_1.ts (2 errors) ==== import Sammy = require("./errorsOnImportedSymbol_0"); var x = new Sammy.Sammy(); ~~~~~ -!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here. var y = Sammy.Sammy(); ~~~~~ -!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/errorsOnImportedSymbol_0.ts (0 errors) ==== diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index e5ca006133b..be9aaf35fc4 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/main.ts(15,1): error TS2692: Cannot find name 'z1'. A type exists with this name, but no value. +tests/cases/compiler/main.ts(15,1): error TS2693: 'z1' only refers to a type, but is being used as a value here. tests/cases/compiler/main.ts(21,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(23,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(27,8): error TS1192: Module '"interface"' has no default export. @@ -49,7 +49,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses z1.a; ~~ -!!! error TS2692: Cannot find name 'z1'. A type exists with this name, but no value. +!!! error TS2693: 'z1' only refers to a type, but is being used as a value here. z2.a; z3.a; z4.a; diff --git a/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt b/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt index 2d54bfd7e6d..a82be89da4e 100644 --- a/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt +++ b/tests/baselines/reference/exportAssignmentOfDeclaredExternalModule.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. -tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2693: 'Sammy' only refers to a type, but is being used as a value here. +tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2693: 'Sammy' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts (2 errors) ==== @@ -7,10 +7,10 @@ tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error T import Sammy = require('./exportAssignmentOfDeclaredExternalModule_0'); var x = new Sammy(); // error to use as constructor as there is not constructor symbol ~~~~~ -!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here. var y = Sammy(); // error to use interface name as call target ~~~~~ -!!! error TS2692: Cannot find name 'Sammy'. A type exists with this name, but no value. +!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here. var z: Sammy; // no error - z is of type interface Sammy from module 'M' var a = new z(); // constructor - no error var b = z(); // call signature - no error diff --git a/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt b/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt index cef121150fb..5a4f710ed6d 100644 --- a/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt +++ b/tests/baselines/reference/genericConstructInvocationWithNoTypeArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2692: Cannot find name 'Foo'. A type exists with this name, but no value. +tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2693: 'Foo' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2 } var f2: Foo = new Foo(3); ~~~ -!!! error TS2692: Cannot find name 'Foo'. A type exists with this name, but no value. +!!! error TS2693: 'Foo' only refers to a type, but is being used as a value here. \ No newline at end of file diff --git a/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt b/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt index 86cbc3ac1d6..08d138f2e5d 100644 --- a/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt +++ b/tests/baselines/reference/inheritFromGenericTypeParameter.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2693: 'T' only refers to a type, but is being used as a value here. tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An interface may only extend a class or another interface. ==== tests/cases/compiler/inheritFromGenericTypeParameter.ts (2 errors) ==== class C extends T { } ~ -!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2693: 'T' only refers to a type, but is being used as a value here. interface I extends T { } ~ !!! error TS2312: An interface may only extend a class or another interface. \ No newline at end of file diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 3cd1997dc5a..2214c685956 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -10,7 +10,7 @@ tests/cases/compiler/intTypeCheck.ts(103,5): error TS2322: Type '() => void' is Property 'p' is missing in type '() => void'. tests/cases/compiler/intTypeCheck.ts(106,5): error TS2322: Type 'boolean' is not assignable to type 'i1'. tests/cases/compiler/intTypeCheck.ts(106,20): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(106,21): error TS2692: Cannot find name 'i1'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(106,21): error TS2693: 'i1' only refers to a type, but is being used as a value here. 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'. Type '{}' provides no match for the signature '(): any' @@ -21,7 +21,7 @@ tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not as Type 'Base' provides no match for the signature '(): any' 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 TS2692: Cannot find name 'i2'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(120,22): error TS2693: 'i2' only refers to a type, but is being used as a value here. 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'. Type '{}' provides no match for the signature 'new (): any' @@ -33,12 +33,12 @@ tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is Type '() => void' provides no match for the signature 'new (): any' 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 TS2692: Cannot find name 'i3'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(134,22): error TS2693: 'i3' only refers to a type, but is being used as a value here. 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(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(148,22): error TS2692: Cannot find name 'i4'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(148,22): error TS2693: 'i4' only refers to a type, but is being used as a value here. 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 '{}'. @@ -51,7 +51,7 @@ tests/cases/compiler/intTypeCheck.ts(159,5): error TS2322: Type '() => void' is Property 'p' is missing in type '() => void'. tests/cases/compiler/intTypeCheck.ts(162,5): error TS2322: Type 'boolean' is not assignable to type 'i5'. tests/cases/compiler/intTypeCheck.ts(162,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(162,22): error TS2692: Cannot find name 'i5'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(162,22): error TS2693: 'i5' only refers to a type, but is being used as a value here. 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'. Type '{}' provides no match for the signature '(): any' @@ -64,7 +64,7 @@ tests/cases/compiler/intTypeCheck.ts(173,5): error TS2322: Type '() => void' is Type 'void' is not assignable to type 'number'. 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 TS2692: Cannot find name 'i6'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(176,22): error TS2693: 'i6' only refers to a type, but is being used as a value here. 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'. Type '{}' provides no match for the signature 'new (): any' @@ -76,12 +76,12 @@ tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is Type '() => void' provides no match for the signature 'new (): any' 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 TS2692: Cannot find name 'i7'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(190,22): error TS2693: 'i7' only refers to a type, but is being used as a value here. 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(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected. -tests/cases/compiler/intTypeCheck.ts(204,22): error TS2692: Cannot find name 'i8'. A type exists with this name, but no value. +tests/cases/compiler/intTypeCheck.ts(204,22): error TS2693: 'i8' only refers to a type, but is being used as a value here. tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -214,7 +214,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i1'. A type exists with this name, but no value. +!!! error TS2693: 'i1' only refers to a type, but is being used as a value here. var obj10: i1 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -247,7 +247,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i2'. A type exists with this name, but no value. +!!! error TS2693: 'i2' only refers to a type, but is being used as a value here. var obj21: i2 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -281,7 +281,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i3'. A type exists with this name, but no value. +!!! error TS2693: 'i3' only refers to a type, but is being used as a value here. var obj32: i3 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -305,7 +305,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i4'. A type exists with this name, but no value. +!!! error TS2693: 'i4' only refers to a type, but is being used as a value here. var obj43: i4 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -341,7 +341,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i5'. A type exists with this name, but no value. +!!! error TS2693: 'i5' only refers to a type, but is being used as a value here. var obj54: i5 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i6'. A type exists with this name, but no value. +!!! error TS2693: 'i6' only refers to a type, but is being used as a value here. var obj65: i6 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -411,7 +411,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i7'. A type exists with this name, but no value. +!!! error TS2693: 'i7' only refers to a type, but is being used as a value here. var obj76: i7 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -435,7 +435,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit ~ !!! error TS1109: Expression expected. ~~ -!!! error TS2692: Cannot find name 'i8'. A type exists with this name, but no value. +!!! error TS2693: 'i8' only refers to a type, but is being used as a value here. var obj87: i8 = new {}; ~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt b/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt index f3ee47573f7..5be40b5b7b6 100644 --- a/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt +++ b/tests/baselines/reference/interfaceNameAsIdentifier.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2692: Cannot find name 'C'. A type exists with this name, but no value. +tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2693: 'C' only refers to a type, but is being used as a value here. tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot find name 'm2'. @@ -8,7 +8,7 @@ tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot fi } C(); ~ -!!! error TS2692: Cannot find name 'C'. A type exists with this name, but no value. +!!! error TS2693: 'C' only refers to a type, but is being used as a value here. module m2 { export interface C { diff --git a/tests/baselines/reference/interfaceNaming1.errors.txt b/tests/baselines/reference/interfaceNaming1.errors.txt index bdd3ca6c1f8..5efeea8c5e9 100644 --- a/tests/baselines/reference/interfaceNaming1.errors.txt +++ b/tests/baselines/reference/interfaceNaming1.errors.txt @@ -1,19 +1,19 @@ -tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. +tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2693: 'interface' only refers to a type, but is being used as a value here. tests/cases/compiler/interfaceNaming1.ts(1,11): error TS1005: ';' expected. -tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. +tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2693: 'interface' only refers to a type, but is being used as a value here. tests/cases/compiler/interfaceNaming1.ts(3,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ==== tests/cases/compiler/interfaceNaming1.ts (4 errors) ==== interface { } ~~~~~~~~~ -!!! error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. +!!! error TS2693: 'interface' only refers to a type, but is being used as a value here. ~ !!! error TS1005: ';' expected. interface interface{ } interface & { } ~~~~~~~~~ -!!! error TS2692: Cannot find name 'interface'. A type exists with this name, but no value. +!!! error TS2693: 'interface' only refers to a type, but is being used as a value here. ~~~ !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt index 2e9f6efb137..05921e9433f 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.errors.txt +++ b/tests/baselines/reference/invalidUndefinedAssignments.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2693: 'I' only refers to a type, but is being used as a value here. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression. @@ -28,7 +28,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t g = x; I = x; ~ -!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. +!!! error TS2693: 'I' only refers to a type, but is being used as a value here. module M { export var x = 1; } M = x; diff --git a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt index 372d2e797e0..3668e7080fd 100644 --- a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt +++ b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt @@ -1,7 +1,7 @@ error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Number'. -tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2692: Cannot find name 'Array'. A type exists with this name, but no value. +tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2693: 'Array' only refers to a type, but is being used as a value here. !!! error TS2318: Cannot find global type 'Boolean'. @@ -13,7 +13,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib function f(x: number, y: number, z: number) { return Array.from(arguments); ~~~~~ -!!! error TS2692: Cannot find name 'Array'. A type exists with this name, but no value. +!!! error TS2693: 'Array' only refers to a type, but is being used as a value here. } f(1, 2, 3); diff --git a/tests/baselines/reference/newOperator.errors.txt b/tests/baselines/reference/newOperator.errors.txt index e8d834824e5..fc6f22d9eac 100644 --- a/tests/baselines/reference/newOperator.errors.txt +++ b/tests/baselines/reference/newOperator.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/newOperator.ts(3,13): error TS2692: Cannot find name 'ifc'. A type exists with this name, but no value. +tests/cases/compiler/newOperator.ts(3,13): error TS2693: 'ifc' only refers to a type, but is being used as a value here. tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(11,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/newOperator.ts(12,5): error TS2304: Cannot find name 'string'. @@ -17,7 +17,7 @@ tests/cases/compiler/newOperator.ts(45,23): error TS1150: 'new T[]' cannot be us // Attempting to 'new' an interface yields poor error var i = new ifc(); ~~~ -!!! error TS2692: Cannot find name 'ifc'. A type exists with this name, but no value. +!!! error TS2693: 'ifc' only refers to a type, but is being used as a value here. // Parens are optional var x = new Date; diff --git a/tests/baselines/reference/reservedNamesInAliases.errors.txt b/tests/baselines/reference/reservedNamesInAliases.errors.txt index 99dc5137714..b6565427395 100644 --- a/tests/baselines/reference/reservedNamesInAliases.errors.txt +++ b/tests/baselines/reference/reservedNamesInAliases.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(5,6): error tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,1): error TS2304: Cannot find name 'type'. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1005: ';' expected. tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1109: Expression expected. -tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2693: 'I' only refers to a type, but is being used as a value here. ==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (8 errors) ==== @@ -30,4 +30,4 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error ~ !!! error TS1109: Expression expected. ~ -!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. \ No newline at end of file +!!! error TS2693: 'I' only refers to a type, but is being used as a value here. \ No newline at end of file diff --git a/tests/baselines/reference/returnTypeParameter.errors.txt b/tests/baselines/reference/returnTypeParameter.errors.txt index 7b762f0938a..24b9e725de8 100644 --- a/tests/baselines/reference/returnTypeParameter.errors.txt +++ b/tests/baselines/reference/returnTypeParameter.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/returnTypeParameter.ts(1,22): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. -tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2693: 'T' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/returnTypeParameter.ts (2 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2692: Cannot find nam !!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. function f2(a: T): T { return T; } // bug was that this satisfied the return statement requirement ~ -!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. \ No newline at end of file +!!! error TS2693: 'T' only refers to a type, but is being used as a value here. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterAsBaseClass.errors.txt b/tests/baselines/reference/typeParameterAsBaseClass.errors.txt index 8254f12cb1c..e633a6dd396 100644 --- a/tests/baselines/reference/typeParameterAsBaseClass.errors.txt +++ b/tests/baselines/reference/typeParameterAsBaseClass.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2693: 'T' only refers to a type, but is being used as a value here. tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class may only implement another class or interface. ==== tests/cases/compiler/typeParameterAsBaseClass.ts (2 errors) ==== class C extends T {} ~ -!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2693: 'T' only refers to a type, but is being used as a value here. class C2 implements T {} ~ !!! error TS2422: A class may only implement another class or interface. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterAsBaseType.errors.txt b/tests/baselines/reference/typeParameterAsBaseType.errors.txt index f6b82a85681..c16b16d0b1a 100644 --- a/tests/baselines/reference/typeParameterAsBaseType.errors.txt +++ b/tests/baselines/reference/typeParameterAsBaseType.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. -tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2692: Cannot find name 'U'. A type exists with this name, but no value. +tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2693: 'T' only refers to a type, but is being used as a value here. +tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2693: 'U' only refers to a type, but is being used as a value here. tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(7,24): error TS2312: An interface may only extend a class or another interface. tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): error TS2312: An interface may only extend a class or another interface. @@ -10,10 +10,10 @@ tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): e class C extends T { } ~ -!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2693: 'T' only refers to a type, but is being used as a value here. class C2 extends U { } ~ -!!! error TS2692: Cannot find name 'U'. A type exists with this name, but no value. +!!! error TS2693: 'U' only refers to a type, but is being used as a value here. interface I extends T { } ~ diff --git a/tests/baselines/reference/typeUsedAsValueError.errors.txt b/tests/baselines/reference/typeUsedAsValueError.errors.txt index 75a83134162..89459235c53 100644 --- a/tests/baselines/reference/typeUsedAsValueError.errors.txt +++ b/tests/baselines/reference/typeUsedAsValueError.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/typeUsedAsValueError.ts(16,11): error TS2692: Cannot find name 'Interface'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(16,11): error TS2693: 'Interface' only refers to a type, but is being used as a value here. tests/cases/compiler/typeUsedAsValueError.ts(17,11): error TS2304: Cannot find name 'InterfaceNotFound'. -tests/cases/compiler/typeUsedAsValueError.ts(18,13): error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. -tests/cases/compiler/typeUsedAsValueError.ts(19,16): error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(18,13): error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here. +tests/cases/compiler/typeUsedAsValueError.ts(19,16): error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here. tests/cases/compiler/typeUsedAsValueError.ts(20,16): error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'. -tests/cases/compiler/typeUsedAsValueError.ts(21,11): error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. -tests/cases/compiler/typeUsedAsValueError.ts(22,17): error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. +tests/cases/compiler/typeUsedAsValueError.ts(21,11): error TS2693: 'someType' only refers to a type, but is being used as a value here. +tests/cases/compiler/typeUsedAsValueError.ts(22,17): error TS2693: 'someType' only refers to a type, but is being used as a value here. tests/cases/compiler/typeUsedAsValueError.ts(23,17): error TS2304: Cannot find name 'someTypeNotFound'. @@ -26,25 +26,25 @@ tests/cases/compiler/typeUsedAsValueError.ts(23,17): error TS2304: Cannot find n let one = Interface; ~~~~~~~~~ -!!! error TS2692: Cannot find name 'Interface'. A type exists with this name, but no value. +!!! error TS2693: 'Interface' only refers to a type, but is being used as a value here. let two = InterfaceNotFound; ~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'InterfaceNotFound'. let three = TypeAliasForSomeClass; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +!!! error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here. let four = new TypeAliasForSomeClass(); ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2692: Cannot find name 'TypeAliasForSomeClass'. A type exists with this name, but no value. +!!! error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here. let five = new TypeAliasForSomeClassNotFound(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'. let six = someType; ~~~~~~~~ -!!! error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. +!!! error TS2693: 'someType' only refers to a type, but is being used as a value here. acceptsSomeType(someType); ~~~~~~~~ -!!! error TS2692: Cannot find name 'someType'. A type exists with this name, but no value. +!!! error TS2693: 'someType' only refers to a type, but is being used as a value here. acceptsSomeType(someTypeNotFound); ~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'someTypeNotFound'. \ No newline at end of file diff --git a/tests/baselines/reference/typeUsedAsValueError2.errors.txt b/tests/baselines/reference/typeUsedAsValueError2.errors.txt index 8707ffaaafb..3027abb0e6b 100644 --- a/tests/baselines/reference/typeUsedAsValueError2.errors.txt +++ b/tests/baselines/reference/typeUsedAsValueError2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/world.ts(4,1): error TS2692: Cannot find name 'HelloInterface'. A type exists with this name, but no value. +tests/cases/compiler/world.ts(4,1): error TS2693: 'HelloInterface' only refers to a type, but is being used as a value here. tests/cases/compiler/world.ts(5,1): error TS2304: Cannot find name 'HelloNamespace'. @@ -8,7 +8,7 @@ tests/cases/compiler/world.ts(5,1): error TS2304: Cannot find name 'HelloNamespa HelloInterface.world; ~~~~~~~~~~~~~~ -!!! error TS2692: Cannot find name 'HelloInterface'. A type exists with this name, but no value. +!!! error TS2693: 'HelloInterface' only refers to a type, but is being used as a value here. HelloNamespace.world; ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'HelloNamespace'. diff --git a/tests/baselines/reference/typeofSimple.errors.txt b/tests/baselines/reference/typeofSimple.errors.txt index 977a8b34d45..ad498563c57 100644 --- a/tests/baselines/reference/typeofSimple.errors.txt +++ b/tests/baselines/reference/typeofSimple.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/typeofSimple.ts(3,5): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/compiler/typeofSimple.ts(8,21): error TS2692: Cannot find name 'J'. A type exists with this name, but no value. +tests/cases/compiler/typeofSimple.ts(8,21): error TS2693: 'J' only refers to a type, but is being used as a value here. ==== tests/cases/compiler/typeofSimple.ts (2 errors) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/typeofSimple.ts(8,21): error TS2692: Cannot find name 'J'. var numberJ: typeof J; //Error, cannot reference type in typeof ~ -!!! error TS2692: Cannot find name 'J'. A type exists with this name, but no value. +!!! error TS2693: 'J' only refers to a type, but is being used as a value here. var numberI: I; var fun: () => I; diff --git a/tests/baselines/reference/typeofTypeParameter.errors.txt b/tests/baselines/reference/typeofTypeParameter.errors.txt index a4fc868197d..cdaeecaafb6 100644 --- a/tests/baselines/reference/typeofTypeParameter.errors.txt +++ b/tests/baselines/reference/typeofTypeParameter.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2693: 'T' only refers to a type, but is being used as a value here. ==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts (1 errors) ==== @@ -6,6 +6,6 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts var a: typeof x; var y: typeof T; ~ -!!! error TS2692: Cannot find name 'T'. A type exists with this name, but no value. +!!! error TS2693: 'T' only refers to a type, but is being used as a value here. return a; } \ No newline at end of file diff --git a/tests/baselines/reference/validNullAssignments.errors.txt b/tests/baselines/reference/validNullAssignments.errors.txt index d3c403b4ae4..1fcebdcbaa9 100644 --- a/tests/baselines/reference/validNullAssignments.errors.txt +++ b/tests/baselines/reference/validNullAssignments.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. -tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2692: Cannot find name 'I'. A type exists with this name, but no value. +tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2693: 'I' only refers to a type, but is being used as a value here. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2364: Invalid left-hand side of assignment expression. @@ -31,7 +31,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err g = null; // ok I = null; // error ~ -!!! error TS2692: Cannot find name 'I'. A type exists with this name, but no value. +!!! error TS2693: 'I' only refers to a type, but is being used as a value here. module M { export var x = 1; } M = null; // error From 03308777cab4b0e1ac5d14abbfafa996db63a459 Mon Sep 17 00:00:00 2001 From: Justin Bay Date: Wed, 24 Aug 2016 23:47:52 -0400 Subject: [PATCH 08/18] Accept new baselines per refactor --- .../reference/invalidImportAliasIdentifiers.errors.txt | 4 ++-- .../strictModeReservedWordInClassDeclaration.errors.txt | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt index afe7472570d..bf5cf5c0f12 100644 --- a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt +++ b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2503: Cannot find namespace 'V'. tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2503: Cannot find namespace 'C'. -tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2503: Cannot find namespace 'I'. +tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2693: 'I' only refers to a type, but is being used as a value here. ==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (3 errors) ==== @@ -32,5 +32,5 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde import i = I; ~ -!!! error TS2503: Cannot find namespace 'I'. +!!! error TS2693: 'I' only refers to a type, but is being used as a value here. \ No newline at end of file diff --git a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt index 0b868960bed..0dff64c9a31 100644 --- a/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt +++ b/tests/baselines/reference/strictModeReservedWordInClassDeclaration.errors.txt @@ -16,9 +16,9 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,9): error TS tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2503: Cannot find namespace 'public'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2693: 'public' only refers to a type, but is being used as a value here. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. -tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2503: Cannot find namespace 'public'. +tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2693: 'public' only refers to a type, but is being used as a value here. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS2304: Cannot find name 'package'. tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. @@ -88,12 +88,12 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS2503: Cannot find namespace 'public'. +!!! error TS2693: 'public' only refers to a type, but is being used as a value here. class F1 implements public.private.implements { } ~~~~~~ !!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode. ~~~~~~ -!!! error TS2503: Cannot find namespace 'public'. +!!! error TS2693: 'public' only refers to a type, but is being used as a value here. class G extends package { } ~~~~~~~ !!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode. From d7376aa8f13c7805c1bc6eae486370a29e01a146 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Thu, 25 Aug 2016 20:30:17 -0400 Subject: [PATCH 09/18] Allow undefined from ProxyHandler.getOwnPropertyDescriptor https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/getOwnPropertyDescriptor --- lib/lib.es2015.proxy.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lib.es2015.proxy.d.ts b/lib/lib.es2015.proxy.d.ts index 3908e97c17c..fa7527ef1c4 100644 --- a/lib/lib.es2015.proxy.d.ts +++ b/lib/lib.es2015.proxy.d.ts @@ -19,7 +19,7 @@ interface ProxyHandler { setPrototypeOf? (target: T, v: any): boolean; isExtensible? (target: T): boolean; preventExtensions? (target: T): boolean; - getOwnPropertyDescriptor? (target: T, p: PropertyKey): PropertyDescriptor; + getOwnPropertyDescriptor? (target: T, p: PropertyKey): PropertyDescriptor | undefined; has? (target: T, p: PropertyKey): boolean; get? (target: T, p: PropertyKey, receiver: any): any; set? (target: T, p: PropertyKey, value: any, receiver: any): boolean; @@ -35,4 +35,4 @@ interface ProxyConstructor { revocable(target: T, handler: ProxyHandler): { proxy: T; revoke: () => void; }; new (target: T, handler: ProxyHandler): T } -declare var Proxy: ProxyConstructor; \ No newline at end of file +declare var Proxy: ProxyConstructor; From 59d027b49bf1aae2541238f5693cfe560dde75a2 Mon Sep 17 00:00:00 2001 From: Omer Sheikh Date: Sun, 28 Aug 2016 12:29:05 +0500 Subject: [PATCH 10/18] Show elaboration for property not existing in union Fixes #10256. Accessing a non-existant property on union types should now show an elaboration in the error message specifying the first constituent type that lacks the property. --- src/compiler/checker.ts | 16 +++++++++++++++- .../reference/propertyAccess3.errors.txt | 4 +++- .../reference/typeGuardsWithAny.errors.txt | 2 ++ ...thInstanceOfByConstructorSignature.errors.txt | 12 ++++++++++++ .../reference/unionTypeMembers.errors.txt | 10 +++++++++- .../reference/unionTypeReadonly.errors.txt | 2 ++ 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8c1e401912d..16633d2dbe1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10773,7 +10773,7 @@ namespace ts { const prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text && !checkAndReportErrorForExtendingInterface(node)) { - error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type.flags & TypeFlags.ThisType ? apparentType : type)); + reportNonexistantProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type); } return unknownType; } @@ -10810,6 +10810,20 @@ namespace ts { return propType; } return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined); + + function reportNonexistantProperty(propNode: Identifier, containingType: Type) { + let errorInfo: DiagnosticMessageChain; + if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Enum)) { + for (const subtype of (containingType as UnionType).types) { + if (!getPropertyOfType(subtype, propNode.text)) { + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); + break; + } + } + } + errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType)); + diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo)); + } } function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { diff --git a/tests/baselines/reference/propertyAccess3.errors.txt b/tests/baselines/reference/propertyAccess3.errors.txt index dd09b7147f7..ab3661d5232 100644 --- a/tests/baselines/reference/propertyAccess3.errors.txt +++ b/tests/baselines/reference/propertyAccess3.errors.txt @@ -1,8 +1,10 @@ tests/cases/compiler/propertyAccess3.ts(2,5): error TS2339: Property 'toBAZ' does not exist on type 'boolean'. + Property 'toBAZ' does not exist on type 'true'. ==== tests/cases/compiler/propertyAccess3.ts (1 errors) ==== var foo: boolean; foo.toBAZ(); ~~~~~ -!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'. \ No newline at end of file +!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'. +!!! error TS2339: Property 'toBAZ' does not exist on type 'true'. \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithAny.errors.txt b/tests/baselines/reference/typeGuardsWithAny.errors.txt index 653c89c7554..2444cb88012 100644 --- a/tests/baselines/reference/typeGuardsWithAny.errors.txt +++ b/tests/baselines/reference/typeGuardsWithAny.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(11,7): error TS2339: Property 'p' does not exist on type 'string'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(18,7): error TS2339: Property 'p' does not exist on type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error TS2339: Property 'p' does not exist on type 'boolean'. + Property 'p' does not exist on type 'true'. ==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts (3 errors) ==== @@ -35,6 +36,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error x.p; // Error, type any narrowed by primitive type check ~ !!! error TS2339: Property 'p' does not exist on type 'boolean'. +!!! error TS2339: Property 'p' does not exist on type 'true'. } else { x.p; // No error, type unaffected in this branch diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index b67f7328856..36aa370df25 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -5,14 +5,20 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(41,10): error TS2339: Property 'bar' does not exist on type 'B'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(72,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. + Property 'bar1' does not exist on type 'C2'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(73,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. + Property 'bar2' does not exist on type 'C1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(85,10): error TS2339: Property 'bar' does not exist on type 'D'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(91,10): error TS2339: Property 'bar' does not exist on type 'D'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(118,11): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. + Property 'bar1' does not exist on type 'E2'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(119,11): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. + Property 'bar2' does not exist on type 'E1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'string | F'. + Property 'foo' does not exist on type 'string'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'string | F'. + Property 'bar' does not exist on type 'string'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2339: Property 'foo2' does not exist on type 'G1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(166,11): error TS2339: Property 'foo2' does not exist on type 'G1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(182,11): error TS2339: Property 'bar' does not exist on type 'H'. @@ -107,9 +113,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj6.bar1; ~~~~ !!! error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. +!!! error TS2339: Property 'bar1' does not exist on type 'C2'. obj6.bar2; ~~~~ !!! error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. +!!! error TS2339: Property 'bar2' does not exist on type 'C1'. } // with object type literal @@ -163,9 +171,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj10.bar1; ~~~~ !!! error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. +!!! error TS2339: Property 'bar1' does not exist on type 'E2'. obj10.bar2; ~~~~ !!! error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. +!!! error TS2339: Property 'bar2' does not exist on type 'E1'. } // a construct signature that returns any @@ -183,9 +193,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj11.foo; ~~~ !!! error TS2339: Property 'foo' does not exist on type 'string | F'. +!!! error TS2339: Property 'foo' does not exist on type 'string'. obj11.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type 'string | F'. +!!! error TS2339: Property 'bar' does not exist on type 'string'. } var obj12: any; diff --git a/tests/baselines/reference/unionTypeMembers.errors.txt b/tests/baselines/reference/unionTypeMembers.errors.txt index 21f1204ac6d..e4f73a51f77 100644 --- a/tests/baselines/reference/unionTypeMembers.errors.txt +++ b/tests/baselines/reference/unionTypeMembers.errors.txt @@ -1,8 +1,12 @@ tests/cases/conformance/types/union/unionTypeMembers.ts(44,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. tests/cases/conformance/types/union/unionTypeMembers.ts(51,3): error TS2339: Property 'propertyOnlyInI1' does not exist on type 'I1 | I2'. + Property 'propertyOnlyInI1' does not exist on type 'I2'. tests/cases/conformance/types/union/unionTypeMembers.ts(52,3): error TS2339: Property 'propertyOnlyInI2' does not exist on type 'I1 | I2'. + Property 'propertyOnlyInI2' does not exist on type 'I1'. tests/cases/conformance/types/union/unionTypeMembers.ts(53,3): error TS2339: Property 'methodOnlyInI1' does not exist on type 'I1 | I2'. + Property 'methodOnlyInI1' does not exist on type 'I2'. tests/cases/conformance/types/union/unionTypeMembers.ts(54,3): error TS2339: Property 'methodOnlyInI2' does not exist on type 'I1 | I2'. + Property 'methodOnlyInI2' does not exist on type 'I1'. ==== tests/cases/conformance/types/union/unionTypeMembers.ts (5 errors) ==== @@ -61,12 +65,16 @@ tests/cases/conformance/types/union/unionTypeMembers.ts(54,3): error TS2339: Pro x.propertyOnlyInI1; // error ~~~~~~~~~~~~~~~~ !!! error TS2339: Property 'propertyOnlyInI1' does not exist on type 'I1 | I2'. +!!! error TS2339: Property 'propertyOnlyInI1' does not exist on type 'I2'. x.propertyOnlyInI2; // error ~~~~~~~~~~~~~~~~ !!! error TS2339: Property 'propertyOnlyInI2' does not exist on type 'I1 | I2'. +!!! error TS2339: Property 'propertyOnlyInI2' does not exist on type 'I1'. x.methodOnlyInI1("hello"); // error ~~~~~~~~~~~~~~ !!! error TS2339: Property 'methodOnlyInI1' does not exist on type 'I1 | I2'. +!!! error TS2339: Property 'methodOnlyInI1' does not exist on type 'I2'. x.methodOnlyInI2(10); // error ~~~~~~~~~~~~~~ -!!! error TS2339: Property 'methodOnlyInI2' does not exist on type 'I1 | I2'. \ No newline at end of file +!!! error TS2339: Property 'methodOnlyInI2' does not exist on type 'I1 | I2'. +!!! error TS2339: Property 'methodOnlyInI2' does not exist on type 'I1'. \ No newline at end of file diff --git a/tests/baselines/reference/unionTypeReadonly.errors.txt b/tests/baselines/reference/unionTypeReadonly.errors.txt index 0875b2b5af3..ec660fc3a81 100644 --- a/tests/baselines/reference/unionTypeReadonly.errors.txt +++ b/tests/baselines/reference/unionTypeReadonly.errors.txt @@ -3,6 +3,7 @@ tests/cases/conformance/types/union/unionTypeReadonly.ts(19,1): error TS2450: Le tests/cases/conformance/types/union/unionTypeReadonly.ts(21,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/union/unionTypeReadonly.ts(23,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. tests/cases/conformance/types/union/unionTypeReadonly.ts(25,15): error TS2339: Property 'value' does not exist on type 'Base | DifferentName'. + Property 'value' does not exist on type 'DifferentName'. ==== tests/cases/conformance/types/union/unionTypeReadonly.ts (5 errors) ==== @@ -41,5 +42,6 @@ tests/cases/conformance/types/union/unionTypeReadonly.ts(25,15): error TS2339: P differentName.value = 12; // error, property 'value' doesn't exist ~~~~~ !!! error TS2339: Property 'value' does not exist on type 'Base | DifferentName'. +!!! error TS2339: Property 'value' does not exist on type 'DifferentName'. \ No newline at end of file From 4eaee735644b2a013b542ada4b50351277f38937 Mon Sep 17 00:00:00 2001 From: Omer Sheikh Date: Mon, 29 Aug 2016 01:07:10 +0500 Subject: [PATCH 11/18] Add test for invalid property access in unions --- .../unionPropertyExistance.errors.txt | 60 +++++++++++++++++++ .../reference/unionPropertyExistance.js | 44 ++++++++++++++ .../cases/compiler/unionPropertyExistance.ts | 32 ++++++++++ 3 files changed, 136 insertions(+) create mode 100644 tests/baselines/reference/unionPropertyExistance.errors.txt create mode 100644 tests/baselines/reference/unionPropertyExistance.js create mode 100644 tests/cases/compiler/unionPropertyExistance.ts diff --git a/tests/baselines/reference/unionPropertyExistance.errors.txt b/tests/baselines/reference/unionPropertyExistance.errors.txt new file mode 100644 index 00000000000..5dcb6b4d6c3 --- /dev/null +++ b/tests/baselines/reference/unionPropertyExistance.errors.txt @@ -0,0 +1,60 @@ +tests/cases/compiler/unionPropertyExistance.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'. + Property 'onlyInB' does not exist on type 'A'. +tests/cases/compiler/unionPropertyExistance.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'. + Property 'notInC' does not exist on type 'C'. +tests/cases/compiler/unionPropertyExistance.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'. + Property 'notInB' does not exist on type 'B'. +tests/cases/compiler/unionPropertyExistance.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'. + Property 'notInB' does not exist on type 'B'. +tests/cases/compiler/unionPropertyExistance.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'. + Property 'inNone' does not exist on type 'A'. + + +==== tests/cases/compiler/unionPropertyExistance.ts (5 errors) ==== + interface A { + inAll: string; + notInB: string; + notInC: string; + } + + interface B { + inAll: boolean; + onlyInB: number; + notInC: string; + } + + interface C { + inAll: number; + notInB: string; + } + + type AB = A | B; + type ABC = C | AB; + + var ab: AB; + var abc: ABC; + + ab.onlyInB; + ~~~~~~~ +!!! error TS2339: Property 'onlyInB' does not exist on type 'AB'. +!!! error TS2339: Property 'onlyInB' does not exist on type 'A'. + + ab.notInC; // Ok + abc.notInC; + ~~~~~~ +!!! error TS2339: Property 'notInC' does not exist on type 'ABC'. +!!! error TS2339: Property 'notInC' does not exist on type 'C'. + ab.notInB; + ~~~~~~ +!!! error TS2339: Property 'notInB' does not exist on type 'AB'. +!!! error TS2339: Property 'notInB' does not exist on type 'B'. + abc.notInB; + ~~~~~~ +!!! error TS2339: Property 'notInB' does not exist on type 'ABC'. +!!! error TS2339: Property 'notInB' does not exist on type 'B'. + + abc.inAll; // Ok + abc.inNone; + ~~~~~~ +!!! error TS2339: Property 'inNone' does not exist on type 'ABC'. +!!! error TS2339: Property 'inNone' does not exist on type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/unionPropertyExistance.js b/tests/baselines/reference/unionPropertyExistance.js new file mode 100644 index 00000000000..0836032c6db --- /dev/null +++ b/tests/baselines/reference/unionPropertyExistance.js @@ -0,0 +1,44 @@ +//// [unionPropertyExistance.ts] +interface A { + inAll: string; + notInB: string; + notInC: string; +} + +interface B { + inAll: boolean; + onlyInB: number; + notInC: string; +} + +interface C { + inAll: number; + notInB: string; +} + +type AB = A | B; +type ABC = C | AB; + +var ab: AB; +var abc: ABC; + +ab.onlyInB; + +ab.notInC; // Ok +abc.notInC; +ab.notInB; +abc.notInB; + +abc.inAll; // Ok +abc.inNone; + +//// [unionPropertyExistance.js] +var ab; +var abc; +ab.onlyInB; +ab.notInC; // Ok +abc.notInC; +ab.notInB; +abc.notInB; +abc.inAll; // Ok +abc.inNone; diff --git a/tests/cases/compiler/unionPropertyExistance.ts b/tests/cases/compiler/unionPropertyExistance.ts new file mode 100644 index 00000000000..d0bee2fb829 --- /dev/null +++ b/tests/cases/compiler/unionPropertyExistance.ts @@ -0,0 +1,32 @@ +interface A { + inAll: string; + notInB: string; + notInC: string; +} + +interface B { + inAll: boolean; + onlyInB: number; + notInC: string; +} + +interface C { + inAll: number; + notInB: string; +} + +type AB = A | B; +type ABC = C | AB; + +var ab: AB; +var abc: ABC; + +ab.onlyInB; + +ab.notInC; // Ok +abc.notInC; +ab.notInB; +abc.notInB; + +abc.inAll; // Ok +abc.inNone; \ No newline at end of file From fe570ba764b011543ae6485de01ce82f3b490487 Mon Sep 17 00:00:00 2001 From: Omer Sheikh Date: Mon, 29 Aug 2016 09:34:46 +0500 Subject: [PATCH 12/18] Do not elaborate on primitive type unions --- src/compiler/checker.ts | 6 +++--- tests/baselines/reference/propertyAccess3.errors.txt | 4 +--- .../baselines/reference/typeGuardsWithAny.errors.txt | 2 -- ....errors.txt => unionPropertyExistence.errors.txt} | 12 ++++++------ ...ropertyExistance.js => unionPropertyExistence.js} | 4 ++-- ...ropertyExistance.ts => unionPropertyExistence.ts} | 0 6 files changed, 12 insertions(+), 16 deletions(-) rename tests/baselines/reference/{unionPropertyExistance.errors.txt => unionPropertyExistence.errors.txt} (82%) rename tests/baselines/reference/{unionPropertyExistance.js => unionPropertyExistence.js} (85%) rename tests/cases/compiler/{unionPropertyExistance.ts => unionPropertyExistence.ts} (100%) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 16633d2dbe1..919ba02998e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10773,7 +10773,7 @@ namespace ts { const prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text && !checkAndReportErrorForExtendingInterface(node)) { - reportNonexistantProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type); + reportNonexistentProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type); } return unknownType; } @@ -10811,9 +10811,9 @@ namespace ts { } return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*flowContainer*/ undefined); - function reportNonexistantProperty(propNode: Identifier, containingType: Type) { + function reportNonexistentProperty(propNode: Identifier, containingType: Type) { let errorInfo: DiagnosticMessageChain; - if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Enum)) { + if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) { for (const subtype of (containingType as UnionType).types) { if (!getPropertyOfType(subtype, propNode.text)) { errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); diff --git a/tests/baselines/reference/propertyAccess3.errors.txt b/tests/baselines/reference/propertyAccess3.errors.txt index ab3661d5232..dd09b7147f7 100644 --- a/tests/baselines/reference/propertyAccess3.errors.txt +++ b/tests/baselines/reference/propertyAccess3.errors.txt @@ -1,10 +1,8 @@ tests/cases/compiler/propertyAccess3.ts(2,5): error TS2339: Property 'toBAZ' does not exist on type 'boolean'. - Property 'toBAZ' does not exist on type 'true'. ==== tests/cases/compiler/propertyAccess3.ts (1 errors) ==== var foo: boolean; foo.toBAZ(); ~~~~~ -!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'. -!!! error TS2339: Property 'toBAZ' does not exist on type 'true'. \ No newline at end of file +!!! error TS2339: Property 'toBAZ' does not exist on type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithAny.errors.txt b/tests/baselines/reference/typeGuardsWithAny.errors.txt index 2444cb88012..653c89c7554 100644 --- a/tests/baselines/reference/typeGuardsWithAny.errors.txt +++ b/tests/baselines/reference/typeGuardsWithAny.errors.txt @@ -1,7 +1,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(11,7): error TS2339: Property 'p' does not exist on type 'string'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(18,7): error TS2339: Property 'p' does not exist on type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error TS2339: Property 'p' does not exist on type 'boolean'. - Property 'p' does not exist on type 'true'. ==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts (3 errors) ==== @@ -36,7 +35,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts(25,7): error x.p; // Error, type any narrowed by primitive type check ~ !!! error TS2339: Property 'p' does not exist on type 'boolean'. -!!! error TS2339: Property 'p' does not exist on type 'true'. } else { x.p; // No error, type unaffected in this branch diff --git a/tests/baselines/reference/unionPropertyExistance.errors.txt b/tests/baselines/reference/unionPropertyExistence.errors.txt similarity index 82% rename from tests/baselines/reference/unionPropertyExistance.errors.txt rename to tests/baselines/reference/unionPropertyExistence.errors.txt index 5dcb6b4d6c3..1fbaa790bd6 100644 --- a/tests/baselines/reference/unionPropertyExistance.errors.txt +++ b/tests/baselines/reference/unionPropertyExistence.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/unionPropertyExistance.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'. +tests/cases/compiler/unionPropertyExistence.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'. Property 'onlyInB' does not exist on type 'A'. -tests/cases/compiler/unionPropertyExistance.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'. +tests/cases/compiler/unionPropertyExistence.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'. Property 'notInC' does not exist on type 'C'. -tests/cases/compiler/unionPropertyExistance.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'. +tests/cases/compiler/unionPropertyExistence.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'. Property 'notInB' does not exist on type 'B'. -tests/cases/compiler/unionPropertyExistance.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'. +tests/cases/compiler/unionPropertyExistence.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'. Property 'notInB' does not exist on type 'B'. -tests/cases/compiler/unionPropertyExistance.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'. +tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'. Property 'inNone' does not exist on type 'A'. -==== tests/cases/compiler/unionPropertyExistance.ts (5 errors) ==== +==== tests/cases/compiler/unionPropertyExistence.ts (5 errors) ==== interface A { inAll: string; notInB: string; diff --git a/tests/baselines/reference/unionPropertyExistance.js b/tests/baselines/reference/unionPropertyExistence.js similarity index 85% rename from tests/baselines/reference/unionPropertyExistance.js rename to tests/baselines/reference/unionPropertyExistence.js index 0836032c6db..22931f151f5 100644 --- a/tests/baselines/reference/unionPropertyExistance.js +++ b/tests/baselines/reference/unionPropertyExistence.js @@ -1,4 +1,4 @@ -//// [unionPropertyExistance.ts] +//// [unionPropertyExistence.ts] interface A { inAll: string; notInB: string; @@ -32,7 +32,7 @@ abc.notInB; abc.inAll; // Ok abc.inNone; -//// [unionPropertyExistance.js] +//// [unionPropertyExistence.js] var ab; var abc; ab.onlyInB; diff --git a/tests/cases/compiler/unionPropertyExistance.ts b/tests/cases/compiler/unionPropertyExistence.ts similarity index 100% rename from tests/cases/compiler/unionPropertyExistance.ts rename to tests/cases/compiler/unionPropertyExistence.ts From f825b9c0f3ae4c89e5d8a8da7b1ba1ff7728028d Mon Sep 17 00:00:00 2001 From: Omer Sheikh Date: Mon, 29 Aug 2016 09:48:17 +0500 Subject: [PATCH 13/18] Add additional tests to unionPropertyExistence --- .../unionPropertyExistence.errors.txt | 38 +++++++++++++++---- .../reference/unionPropertyExistence.js | 15 +++++++- .../cases/compiler/unionPropertyExistence.ts | 10 ++++- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/tests/baselines/reference/unionPropertyExistence.errors.txt b/tests/baselines/reference/unionPropertyExistence.errors.txt index 1fbaa790bd6..c13aa7d4d15 100644 --- a/tests/baselines/reference/unionPropertyExistence.errors.txt +++ b/tests/baselines/reference/unionPropertyExistence.errors.txt @@ -1,16 +1,22 @@ -tests/cases/compiler/unionPropertyExistence.ts(24,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'. +tests/cases/compiler/unionPropertyExistence.ts(27,3): error TS2339: Property 'nope' does not exist on type '"foo" | "bar"'. + Property 'nope' does not exist on type '"foo"'. +tests/cases/compiler/unionPropertyExistence.ts(28,6): error TS2339: Property 'onlyInB' does not exist on type 'B | "foo"'. + Property 'onlyInB' does not exist on type '"foo"'. +tests/cases/compiler/unionPropertyExistence.ts(30,6): error TS2339: Property 'length' does not exist on type 'B | "foo"'. + Property 'length' does not exist on type 'B'. +tests/cases/compiler/unionPropertyExistence.ts(32,4): error TS2339: Property 'onlyInB' does not exist on type 'AB'. Property 'onlyInB' does not exist on type 'A'. -tests/cases/compiler/unionPropertyExistence.ts(27,5): error TS2339: Property 'notInC' does not exist on type 'ABC'. +tests/cases/compiler/unionPropertyExistence.ts(35,5): error TS2339: Property 'notInC' does not exist on type 'ABC'. Property 'notInC' does not exist on type 'C'. -tests/cases/compiler/unionPropertyExistence.ts(28,4): error TS2339: Property 'notInB' does not exist on type 'AB'. +tests/cases/compiler/unionPropertyExistence.ts(36,4): error TS2339: Property 'notInB' does not exist on type 'AB'. Property 'notInB' does not exist on type 'B'. -tests/cases/compiler/unionPropertyExistence.ts(29,5): error TS2339: Property 'notInB' does not exist on type 'ABC'. +tests/cases/compiler/unionPropertyExistence.ts(37,5): error TS2339: Property 'notInB' does not exist on type 'ABC'. Property 'notInB' does not exist on type 'B'. -tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'inNone' does not exist on type 'ABC'. +tests/cases/compiler/unionPropertyExistence.ts(40,5): error TS2339: Property 'inNone' does not exist on type 'ABC'. Property 'inNone' does not exist on type 'A'. -==== tests/cases/compiler/unionPropertyExistence.ts (5 errors) ==== +==== tests/cases/compiler/unionPropertyExistence.ts (8 errors) ==== interface A { inAll: string; notInB: string; @@ -34,6 +40,23 @@ tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'in var ab: AB; var abc: ABC; + declare const x: "foo" | "bar"; + declare const bFoo: B | "foo"; + + x.nope(); + ~~~~ +!!! error TS2339: Property 'nope' does not exist on type '"foo" | "bar"'. +!!! error TS2339: Property 'nope' does not exist on type '"foo"'. + bFoo.onlyInB; + ~~~~~~~ +!!! error TS2339: Property 'onlyInB' does not exist on type 'B | "foo"'. +!!! error TS2339: Property 'onlyInB' does not exist on type '"foo"'. + x.length; // Ok + bFoo.length; + ~~~~~~ +!!! error TS2339: Property 'length' does not exist on type 'B | "foo"'. +!!! error TS2339: Property 'length' does not exist on type 'B'. + ab.onlyInB; ~~~~~~~ !!! error TS2339: Property 'onlyInB' does not exist on type 'AB'. @@ -57,4 +80,5 @@ tests/cases/compiler/unionPropertyExistence.ts(32,5): error TS2339: Property 'in abc.inNone; ~~~~~~ !!! error TS2339: Property 'inNone' does not exist on type 'ABC'. -!!! error TS2339: Property 'inNone' does not exist on type 'A'. \ No newline at end of file +!!! error TS2339: Property 'inNone' does not exist on type 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/unionPropertyExistence.js b/tests/baselines/reference/unionPropertyExistence.js index 22931f151f5..80174a3d363 100644 --- a/tests/baselines/reference/unionPropertyExistence.js +++ b/tests/baselines/reference/unionPropertyExistence.js @@ -22,6 +22,14 @@ type ABC = C | AB; var ab: AB; var abc: ABC; +declare const x: "foo" | "bar"; +declare const bFoo: B | "foo"; + +x.nope(); +bFoo.onlyInB; +x.length; // Ok +bFoo.length; + ab.onlyInB; ab.notInC; // Ok @@ -30,11 +38,16 @@ ab.notInB; abc.notInB; abc.inAll; // Ok -abc.inNone; +abc.inNone; + //// [unionPropertyExistence.js] var ab; var abc; +x.nope(); +bFoo.onlyInB; +x.length; // Ok +bFoo.length; ab.onlyInB; ab.notInC; // Ok abc.notInC; diff --git a/tests/cases/compiler/unionPropertyExistence.ts b/tests/cases/compiler/unionPropertyExistence.ts index d0bee2fb829..65937088898 100644 --- a/tests/cases/compiler/unionPropertyExistence.ts +++ b/tests/cases/compiler/unionPropertyExistence.ts @@ -21,6 +21,14 @@ type ABC = C | AB; var ab: AB; var abc: ABC; +declare const x: "foo" | "bar"; +declare const bFoo: B | "foo"; + +x.nope(); +bFoo.onlyInB; +x.length; // Ok +bFoo.length; + ab.onlyInB; ab.notInC; // Ok @@ -29,4 +37,4 @@ ab.notInB; abc.notInB; abc.inAll; // Ok -abc.inNone; \ No newline at end of file +abc.inNone; From d8ff546512f3c27384a70239d73fc6be3d5dccbc Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 29 Aug 2016 17:18:04 -0700 Subject: [PATCH 14/18] Remove handling for multiple inheritance for config files --- src/compiler/commandLineParser.ts | 11 +---- .../unittests/configurationExtension.ts | 47 +------------------ 2 files changed, 3 insertions(+), 55 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 559ec8da2f4..7acf6eb9018 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -822,17 +822,8 @@ namespace ts { if (typeof json["extends"] === "string") { [include, exclude, files, baseOptions] = (tryExtendsName(json["extends"]) || [include, exclude, files, baseOptions]); } - else if (typeof json["extends"] === "object" && json["extends"].length) { - for (const name of json["extends"]) { - const [tempinclude, tempexclude, tempfiles, tempBase]: [string[], string[], string[], CompilerOptions] = (tryExtendsName(name) || [include, exclude, files, baseOptions]); - include = tempinclude || include; - exclude = tempexclude || exclude; - files = tempfiles || files; - baseOptions = assign({}, baseOptions, tempBase); - } - } else { - errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", "string or string[]")); + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", "string")); } if (include && !json["include"]) { json["include"] = include; diff --git a/src/harness/unittests/configurationExtension.ts b/src/harness/unittests/configurationExtension.ts index 21584d4b67d..4537dc77576 100644 --- a/src/harness/unittests/configurationExtension.ts +++ b/src/harness/unittests/configurationExtension.ts @@ -15,18 +15,6 @@ namespace ts { "compilerOptions": { "strictNullChecks": false } -}`, - "/dev/tsconfig.tests.json": `{ - "extends": ["./configs/tests", "./tsconfig"], - "compilerOptions": { - "module": "commonjs" - } -}`, - "/dev/tsconfig.tests.browser.json": `{ - "extends": ["./configs/tests", "./tsconfig"], - "compilerOptions": { - "module": "amd" - } }`, "/dev/configs/base.json": `{ "compilerOptions": { @@ -75,12 +63,6 @@ namespace ts { }`, "/dev/failure2.json": `{ "excludes": ["*.js"] -}`, - "/dev/multi.json": `{ - "extends": ["./configs/first", "./configs/second"], - "compilerOptions": { - "allowJs": false - } }`, "/dev/configs/first.json": `{ "extends": "./base", @@ -168,31 +150,6 @@ namespace ts { combinePaths(basePath, "supplemental.ts"), ]); - testSuccess("can resolve an extension with a multiple base extensions that overrides options", "tsconfig.tests.json", { - allowJs: true, - noImplicitAny: true, - strictNullChecks: true, - preserveConstEnums: true, - removeComments: false, - sourceMap: true, - module: ts.ModuleKind.CommonJS, - }, [ - combinePaths(basePath, "main.ts"), - combinePaths(basePath, "supplemental.ts"), - combinePaths(basePath, "tests/unit/spec.ts"), - combinePaths(basePath, "tests/utils.ts"), - ]); - - testSuccess("can resolve a diamond dependency graph", "multi.json", { - allowJs: false, - noImplicitAny: true, - strictNullChecks: true, - module: ts.ModuleKind.AMD, - }, [ - combinePaths(basePath, "configs/../main.ts"), // Probably should consider resolving these kinds of paths when they appear - combinePaths(basePath, "supplemental.ts"), - ]); - testFailure("can report errors on circular imports", "circular.json", [ { code: 18000, @@ -213,10 +170,10 @@ namespace ts { messageText: `Unknown option 'excludes'. Did you mean 'exclude'?` }]); - testFailure("can error when 'extends' is neither a string nor a string[]", "extends.json", [{ + testFailure("can error when 'extends' is not a string", "extends.json", [{ code: 5024, category: DiagnosticCategory.Error, - messageText: `Compiler option 'extends' requires a value of type string or string[].` + messageText: `Compiler option 'extends' requires a value of type string.` }]); testFailure("can error when 'extends' is neither relative nor rooted.", "extends2.json", [{ From f6f7a78d89981d85cd9f4da41f9d715b106fa04f Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 7 Sep 2016 09:29:38 -0700 Subject: [PATCH 15/18] Optimize 'getSourceFile' to only get the source file once. --- src/services/services.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index eaba4779a52..778687557b2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -127,7 +127,10 @@ namespace ts { } public getText(sourceFile?: SourceFile): string { - return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + if (!sourceFile) { + sourceFile = this.getSourceFile(); + } + return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); } private addSyntheticNodes(nodes: Node[], pos: number, end: number, useJSDocScanner?: boolean): number { @@ -192,8 +195,8 @@ namespace ts { } } // For syntactic classifications, all trivia are classcified together, including jsdoc comments. - // For that to work, the jsdoc comments should still be the leading trivia of the first child. - // Restoring the scanner position ensures that. + // For that to work, the jsdoc comments should still be the leading trivia of the first child. + // Restoring the scanner position ensures that. pos = this.pos; forEachChild(this, processNode, processNodes); if (pos < this.end) { From 48a610c34f6c4910cae2f3805bd34a936a7bc00e Mon Sep 17 00:00:00 2001 From: Jeffrey Morlan Date: Sat, 10 Sep 2016 11:39:50 -0700 Subject: [PATCH 16/18] Fix ECMA-402 declarations (issue #10618) 1. Make String.prototype.localeCompare's `locales` parameter optional, so `undefined` is allowed. 2. Declare the `locales` parameter as a `string | string[]` union instead of using overloads. Having separate overloads for `string` and `string[]` unnecessarily prevents passing a `string | string[]`. (These overloads predate the introduction of union types.) --- src/lib/es5.d.ts | 85 +++++-------------- .../library_DatePrototypeProperties.symbols | 12 +-- .../library_DatePrototypeProperties.types | 12 +-- 3 files changed, 32 insertions(+), 77 deletions(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index a91ad4b126e..59053aaa540 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -3949,12 +3949,9 @@ declare module Intl { resolvedOptions(): ResolvedCollatorOptions; } var Collator: { - new (locales?: string[], options?: CollatorOptions): Collator; - new (locale?: string, options?: CollatorOptions): Collator; - (locales?: string[], options?: CollatorOptions): Collator; - (locale?: string, options?: CollatorOptions): Collator; - supportedLocalesOf(locales: string[], options?: CollatorOptions): string[]; - supportedLocalesOf(locale: string, options?: CollatorOptions): string[]; + new (locales?: string | string[], options?: CollatorOptions): Collator; + (locales?: string | string[], options?: CollatorOptions): Collator; + supportedLocalesOf(locales: string | string[], options?: CollatorOptions): string[]; } interface NumberFormatOptions { @@ -3989,12 +3986,9 @@ declare module Intl { resolvedOptions(): ResolvedNumberFormatOptions; } var NumberFormat: { - new (locales?: string[], options?: NumberFormatOptions): NumberFormat; - new (locale?: string, options?: NumberFormatOptions): NumberFormat; - (locales?: string[], options?: NumberFormatOptions): NumberFormat; - (locale?: string, options?: NumberFormatOptions): NumberFormat; - supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[]; - supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; + new (locales?: string | string[], options?: NumberFormatOptions): NumberFormat; + (locales?: string | string[], options?: NumberFormatOptions): NumberFormat; + supportedLocalesOf(locales: string | string[], options?: NumberFormatOptions): string[]; } interface DateTimeFormatOptions { @@ -4035,88 +4029,49 @@ declare module Intl { resolvedOptions(): ResolvedDateTimeFormatOptions; } var DateTimeFormat: { - new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; - new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; - (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; - (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; - supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[]; - supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[]; + new (locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat; + (locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat; + supportedLocalesOf(locales: string | string[], options?: DateTimeFormatOptions): string[]; } } interface String { /** - * Determines whether two strings are equivalent in the current locale. + * Determines whether two strings are equivalent in the current or specified locale. * @param that String to compare to target string - * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details. * @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details. */ - localeCompare(that: string, locales: string[], options?: Intl.CollatorOptions): number; - - /** - * Determines whether two strings are equivalent in the current locale. - * @param that String to compare to target string - * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details. - * @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details. - */ - localeCompare(that: string, locale: string, options?: Intl.CollatorOptions): number; + localeCompare(that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; } interface Number { /** * Converts a number to a string by using the current or specified locale. - * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleString(locales?: string[], options?: Intl.NumberFormatOptions): string; - - /** - * Converts a number to a string by using the current or specified locale. - * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. - * @param options An object that contains one or more properties that specify comparison options. - */ - toLocaleString(locale?: string, options?: Intl.NumberFormatOptions): string; + toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): string; } interface Date { /** * Converts a date and time to a string by using the current or specified locale. - * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; /** * Converts a date to a string by using the current or specified locale. - * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + toLocaleDateString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; /** * Converts a time to a string by using the current or specified locale. - * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string; - - /** - * Converts a date and time to a string by using the current or specified locale. - * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. - * @param options An object that contains one or more properties that specify comparison options. - */ - toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; - - /** - * Converts a date to a string by using the current or specified locale. - * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. - * @param options An object that contains one or more properties that specify comparison options. - */ - toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string; - - /** - * Converts a time to a string by using the current or specified locale. - * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. - * @param options An object that contains one or more properties that specify comparison options. - */ - toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + toLocaleTimeString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } diff --git a/tests/baselines/reference/library_DatePrototypeProperties.symbols b/tests/baselines/reference/library_DatePrototypeProperties.symbols index 4601adcde18..1b725fbf84c 100644 --- a/tests/baselines/reference/library_DatePrototypeProperties.symbols +++ b/tests/baselines/reference/library_DatePrototypeProperties.symbols @@ -30,25 +30,25 @@ Date.prototype.toTimeString(); >toTimeString : Symbol(Date.toTimeString, Decl(lib.d.ts, --, --)) Date.prototype.toLocaleString(); ->Date.prototype.toLocaleString : Symbol(Date.toLocaleString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Date.prototype.toLocaleString : Symbol(Date.toLocaleString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >Date.prototype : Symbol(DateConstructor.prototype, Decl(lib.d.ts, --, --)) >Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prototype : Symbol(DateConstructor.prototype, Decl(lib.d.ts, --, --)) ->toLocaleString : Symbol(Date.toLocaleString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toLocaleString : Symbol(Date.toLocaleString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) Date.prototype.toLocaleDateString(); ->Date.prototype.toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Date.prototype.toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >Date.prototype : Symbol(DateConstructor.prototype, Decl(lib.d.ts, --, --)) >Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prototype : Symbol(DateConstructor.prototype, Decl(lib.d.ts, --, --)) ->toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) Date.prototype.toLocaleTimeString(); ->Date.prototype.toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Date.prototype.toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >Date.prototype : Symbol(DateConstructor.prototype, Decl(lib.d.ts, --, --)) >Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) >prototype : Symbol(DateConstructor.prototype, Decl(lib.d.ts, --, --)) ->toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) Date.prototype.valueOf(); >Date.prototype.valueOf : Symbol(Date.valueOf, Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/library_DatePrototypeProperties.types b/tests/baselines/reference/library_DatePrototypeProperties.types index c048b9833d6..3240a5e9351 100644 --- a/tests/baselines/reference/library_DatePrototypeProperties.types +++ b/tests/baselines/reference/library_DatePrototypeProperties.types @@ -34,27 +34,27 @@ Date.prototype.toTimeString(); Date.prototype.toLocaleString(); >Date.prototype.toLocaleString() : string ->Date.prototype.toLocaleString : { (): string; (locales?: string[], options?: Intl.DateTimeFormatOptions): string; (locale?: string, options?: Intl.DateTimeFormatOptions): string; } +>Date.prototype.toLocaleString : { (): string; (locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } >Date.prototype : Date >Date : DateConstructor >prototype : Date ->toLocaleString : { (): string; (locales?: string[], options?: Intl.DateTimeFormatOptions): string; (locale?: string, options?: Intl.DateTimeFormatOptions): string; } +>toLocaleString : { (): string; (locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } Date.prototype.toLocaleDateString(); >Date.prototype.toLocaleDateString() : string ->Date.prototype.toLocaleDateString : { (): string; (locales?: string[], options?: Intl.DateTimeFormatOptions): string; (locale?: string, options?: Intl.DateTimeFormatOptions): string; } +>Date.prototype.toLocaleDateString : { (): string; (locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } >Date.prototype : Date >Date : DateConstructor >prototype : Date ->toLocaleDateString : { (): string; (locales?: string[], options?: Intl.DateTimeFormatOptions): string; (locale?: string, options?: Intl.DateTimeFormatOptions): string; } +>toLocaleDateString : { (): string; (locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } Date.prototype.toLocaleTimeString(); >Date.prototype.toLocaleTimeString() : string ->Date.prototype.toLocaleTimeString : { (): string; (locale?: string[], options?: Intl.DateTimeFormatOptions): string; (locale?: string, options?: Intl.DateTimeFormatOptions): string; } +>Date.prototype.toLocaleTimeString : { (): string; (locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } >Date.prototype : Date >Date : DateConstructor >prototype : Date ->toLocaleTimeString : { (): string; (locale?: string[], options?: Intl.DateTimeFormatOptions): string; (locale?: string, options?: Intl.DateTimeFormatOptions): string; } +>toLocaleTimeString : { (): string; (locales?: string | string[], options?: Intl.DateTimeFormatOptions): string; } Date.prototype.valueOf(); >Date.prototype.valueOf() : number From 24b802e51329147b4e8b55817dffbcb9f84fb313 Mon Sep 17 00:00:00 2001 From: rbuckton Date: Mon, 12 Sep 2016 20:58:41 -0700 Subject: [PATCH 17/18] Fix captured block scope variables in downlevel async. Fixes #10889 --- src/compiler/emitter.ts | 16 +- src/compiler/transformers/es6.ts | 39 +++- src/compiler/transformers/generators.ts | 21 +- .../asyncAwaitIsolatedModules_es5.js | 16 +- .../asyncAwaitWithCapturedBlockScopeVar.js | 182 ++++++++++++++++++ ...syncAwaitWithCapturedBlockScopeVar.symbols | 88 +++++++++ .../asyncAwaitWithCapturedBlockScopeVar.types | 129 +++++++++++++ tests/baselines/reference/asyncAwait_es5.js | 16 +- .../reference/asyncFunctionNoReturnType.js | 16 +- .../reference/asyncImportedPromise_es5.js | 16 +- .../baselines/reference/asyncMultiFile_es5.js | 16 +- .../baselines/reference/es5-asyncFunction.js | 16 +- .../es5-importHelpersAsyncFunctions.js | 16 +- .../asyncAwaitWithCapturedBlockScopeVar.ts | 37 ++++ 14 files changed, 572 insertions(+), 52 deletions(-) create mode 100644 tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.js create mode 100644 tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.symbols create mode 100644 tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.types create mode 100644 tests/cases/compiler/asyncAwaitWithCapturedBlockScopeVar.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6ef6912d650..76a547b11e4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -73,7 +73,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge const generatorHelper = ` var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -83,12 +83,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -99,8 +105,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 9cb759027e6..44deac04279 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -2055,9 +2055,24 @@ namespace ts { if (!isBlock(loopBody)) { loopBody = createBlock([loopBody], /*location*/ undefined, /*multiline*/ true); } + + const isAsyncBlockContainingAwait = + containingNonArrowFunction + && (containingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody) !== 0 + && (node.statement.transformFlags & TransformFlags.ContainsYield) !== 0; + + let loopBodyFlags: NodeEmitFlags = 0; + if (currentState.containsLexicalThis) { + loopBodyFlags |= NodeEmitFlags.CapturesThis; + } + + if (isAsyncBlockContainingAwait) { + loopBodyFlags |= NodeEmitFlags.AsyncFunctionBody; + } + const convertedLoopVariable = createVariableStatement( - /*modifiers*/ undefined, + /*modifiers*/ undefined, createVariableDeclarationList( [ createVariableDeclaration( @@ -2065,16 +2080,14 @@ namespace ts { /*type*/ undefined, setNodeEmitFlags( createFunctionExpression( - /*asteriskToken*/ undefined, + isAsyncBlockContainingAwait ? createToken(SyntaxKind.AsteriskToken) : undefined, /*name*/ undefined, /*typeParameters*/ undefined, loopParameters, /*type*/ undefined, loopBody ), - currentState.containsLexicalThis - ? NodeEmitFlags.CapturesThis - : 0 + loopBodyFlags ) ) ] @@ -2160,7 +2173,7 @@ namespace ts { )); } - const convertedLoopBodyStatements = generateCallToConvertedLoop(functionName, loopParameters, currentState); + const convertedLoopBodyStatements = generateCallToConvertedLoop(functionName, loopParameters, currentState, isAsyncBlockContainingAwait); let loop: IterationStatement; if (convert) { loop = convert(node, convertedLoopBodyStatements); @@ -2173,12 +2186,17 @@ namespace ts { loop = visitEachChild(loop, visitor, context); // set loop statement loop.statement = createBlock( - generateCallToConvertedLoop(functionName, loopParameters, currentState), + convertedLoopBodyStatements, /*location*/ undefined, /*multiline*/ true ); + + // reset and re-aggregate the transform flags + loop.transformFlags = 0; + aggregateTransformFlags(loop); } + statements.push( currentParent.kind === SyntaxKind.LabeledStatement ? createLabel((currentParent).label, loop) @@ -2199,7 +2217,7 @@ namespace ts { } } - function generateCallToConvertedLoop(loopFunctionExpressionName: Identifier, parameters: ParameterDeclaration[], state: ConvertedLoopState): Statement[] { + function generateCallToConvertedLoop(loopFunctionExpressionName: Identifier, parameters: ParameterDeclaration[], state: ConvertedLoopState, isAsyncBlockContainingAwait: boolean): Statement[] { const outerConvertedLoopState = convertedLoopState; const statements: Statement[] = []; @@ -2212,8 +2230,9 @@ namespace ts { !state.labeledNonLocalContinues; const call = createCall(loopFunctionExpressionName, /*typeArguments*/ undefined, map(parameters, p => p.name)); + const callResult = isAsyncBlockContainingAwait ? createYield(createToken(SyntaxKind.AsteriskToken), call) : call; if (isSimpleLoop) { - statements.push(createStatement(call)); + statements.push(createStatement(callResult)); copyOutParameters(state.loopOutParameters, CopyDirection.ToOriginal, statements); } else { @@ -2221,7 +2240,7 @@ namespace ts { const stateVariable = createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList( - [createVariableDeclaration(loopResultName, /*type*/ undefined, call)] + [createVariableDeclaration(loopResultName, /*type*/ undefined, callResult)] ) ); statements.push(stateVariable); diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 9a4b567cb80..60e4a0cb546 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -906,7 +906,7 @@ namespace ts { * * @param node The node to visit. */ - function visitYieldExpression(node: YieldExpression) { + function visitYieldExpression(node: YieldExpression): LeftHandSideExpression { // [source] // x = yield a(); // @@ -917,7 +917,14 @@ namespace ts { // NOTE: we are explicitly not handling YieldStar at this time. const resumeLabel = defineLabel(); - emitYield(visitNode(node.expression, visitor, isExpression), /*location*/ node); + const expression = visitNode(node.expression, visitor, isExpression); + if (node.asteriskToken) { + emitYieldStar(expression, /*location*/ node); + } + else { + emitYield(expression, /*location*/ node); + } + markLabel(resumeLabel); return createGeneratorResume(); } @@ -2480,6 +2487,16 @@ namespace ts { emitWorker(OpCode.BreakWhenFalse, [label, condition], location); } + /** + * Emits a YieldStar operation for the provided expression. + * + * @param expression An optional value for the yield operation. + * @param location An optional source map location for the assignment. + */ + function emitYieldStar(expression?: Expression, location?: TextRange): void { + emitWorker(OpCode.YieldStar, [expression], location); + } + /** * Emits a Yield operation for the provided expression. * diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js index 95416f3aaa2..02da40c6c23 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js @@ -50,7 +50,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -60,12 +60,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -76,8 +82,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.js b/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.js new file mode 100644 index 00000000000..49566904ae1 --- /dev/null +++ b/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.js @@ -0,0 +1,182 @@ +//// [asyncAwaitWithCapturedBlockScopeVar.ts] +async function fn1() { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + } +} + +async function fn2() { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + break; + } +} + +async function fn3() { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + continue; + } +} + +async function fn4(): Promise { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + return 1; + } +} + + +//// [asyncAwaitWithCapturedBlockScopeVar.js] +function fn1() { + return __awaiter(this, void 0, void 0, function () { + var ar, _loop_1, i; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + ar = []; + _loop_1 = function (i) { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + ar.push(function () { return i; }); + return [2 /*return*/]; + } + }); + }; + i = 0; + _a.label = 1; + case 1: + if (!(i < 1)) + return [3 /*break*/, 4]; + return [5 /*yield**/, _loop_1(i)]; + case 2: + _a.sent(); + _a.label = 3; + case 3: + i++; + return [3 /*break*/, 1]; + case 4: return [2 /*return*/]; + } + }); + }); +} +function fn2() { + return __awaiter(this, void 0, void 0, function () { + var ar, _loop_2, i, state_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + ar = []; + _loop_2 = function (i) { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + ar.push(function () { return i; }); + return [2 /*return*/, "break"]; + } + }); + }; + i = 0; + _a.label = 1; + case 1: + if (!(i < 1)) + return [3 /*break*/, 4]; + return [5 /*yield**/, _loop_2(i)]; + case 2: + state_1 = _a.sent(); + if (state_1 === "break") + return [3 /*break*/, 4]; + _a.label = 3; + case 3: + i++; + return [3 /*break*/, 1]; + case 4: return [2 /*return*/]; + } + }); + }); +} +function fn3() { + return __awaiter(this, void 0, void 0, function () { + var ar, _loop_3, i; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + ar = []; + _loop_3 = function (i) { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + ar.push(function () { return i; }); + return [2 /*return*/, "continue"]; + } + }); + }; + i = 0; + _a.label = 1; + case 1: + if (!(i < 1)) + return [3 /*break*/, 4]; + return [5 /*yield**/, _loop_3(i)]; + case 2: + _a.sent(); + _a.label = 3; + case 3: + i++; + return [3 /*break*/, 1]; + case 4: return [2 /*return*/]; + } + }); + }); +} +function fn4() { + return __awaiter(this, void 0, void 0, function () { + var ar, _loop_4, i, state_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + ar = []; + _loop_4 = function (i) { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + ar.push(function () { return i; }); + return [2 /*return*/, { value: 1 }]; + } + }); + }; + i = 0; + _a.label = 1; + case 1: + if (!(i < 1)) + return [3 /*break*/, 4]; + return [5 /*yield**/, _loop_4(i)]; + case 2: + state_2 = _a.sent(); + if (typeof state_2 === "object") + return [2 /*return*/, state_2.value]; + _a.label = 3; + case 3: + i++; + return [3 /*break*/, 1]; + case 4: return [2 /*return*/]; + } + }); + }); +} diff --git a/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.symbols b/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.symbols new file mode 100644 index 00000000000..12a60509f4f --- /dev/null +++ b/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.symbols @@ -0,0 +1,88 @@ +=== tests/cases/compiler/asyncAwaitWithCapturedBlockScopeVar.ts === +async function fn1() { +>fn1 : Symbol(fn1, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 0, 0)) + + let ar = []; +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 1, 7)) + + for (let i = 0; i < 1; i++) { +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 2, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 2, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 2, 12)) + + await 1; + ar.push(() => i); +>ar.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 1, 7)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 2, 12)) + } +} + +async function fn2() { +>fn2 : Symbol(fn2, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 6, 1)) + + let ar = []; +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 9, 7)) + + for (let i = 0; i < 1; i++) { +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 10, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 10, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 10, 12)) + + await 1; + ar.push(() => i); +>ar.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 9, 7)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 10, 12)) + + break; + } +} + +async function fn3() { +>fn3 : Symbol(fn3, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 15, 1)) + + let ar = []; +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 18, 7)) + + for (let i = 0; i < 1; i++) { +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 19, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 19, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 19, 12)) + + await 1; + ar.push(() => i); +>ar.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 18, 7)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 19, 12)) + + continue; + } +} + +async function fn4(): Promise { +>fn4 : Symbol(fn4, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 24, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + let ar = []; +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 27, 7)) + + for (let i = 0; i < 1; i++) { +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 28, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 28, 12)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 28, 12)) + + await 1; + ar.push(() => i); +>ar.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>ar : Symbol(ar, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 27, 7)) +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(asyncAwaitWithCapturedBlockScopeVar.ts, 28, 12)) + + return 1; + } +} + diff --git a/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.types b/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.types new file mode 100644 index 00000000000..424959ddb22 --- /dev/null +++ b/tests/baselines/reference/asyncAwaitWithCapturedBlockScopeVar.types @@ -0,0 +1,129 @@ +=== tests/cases/compiler/asyncAwaitWithCapturedBlockScopeVar.ts === +async function fn1() { +>fn1 : () => Promise + + let ar = []; +>ar : any[] +>[] : undefined[] + + for (let i = 0; i < 1; i++) { +>i : number +>0 : 0 +>i < 1 : boolean +>i : number +>1 : 1 +>i++ : number +>i : number + + await 1; +>await 1 : 1 +>1 : 1 + + ar.push(() => i); +>ar.push(() => i) : number +>ar.push : (...items: any[]) => number +>ar : any[] +>push : (...items: any[]) => number +>() => i : () => number +>i : number + } +} + +async function fn2() { +>fn2 : () => Promise + + let ar = []; +>ar : any[] +>[] : undefined[] + + for (let i = 0; i < 1; i++) { +>i : number +>0 : 0 +>i < 1 : boolean +>i : number +>1 : 1 +>i++ : number +>i : number + + await 1; +>await 1 : 1 +>1 : 1 + + ar.push(() => i); +>ar.push(() => i) : number +>ar.push : (...items: any[]) => number +>ar : any[] +>push : (...items: any[]) => number +>() => i : () => number +>i : number + + break; + } +} + +async function fn3() { +>fn3 : () => Promise + + let ar = []; +>ar : any[] +>[] : undefined[] + + for (let i = 0; i < 1; i++) { +>i : number +>0 : 0 +>i < 1 : boolean +>i : number +>1 : 1 +>i++ : number +>i : number + + await 1; +>await 1 : 1 +>1 : 1 + + ar.push(() => i); +>ar.push(() => i) : number +>ar.push : (...items: any[]) => number +>ar : any[] +>push : (...items: any[]) => number +>() => i : () => number +>i : number + + continue; + } +} + +async function fn4(): Promise { +>fn4 : () => Promise +>Promise : Promise + + let ar = []; +>ar : any[] +>[] : undefined[] + + for (let i = 0; i < 1; i++) { +>i : number +>0 : 0 +>i < 1 : boolean +>i : number +>1 : 1 +>i++ : number +>i : number + + await 1; +>await 1 : 1 +>1 : 1 + + ar.push(() => i); +>ar.push(() => i) : number +>ar.push : (...items: any[]) => number +>ar : any[] +>push : (...items: any[]) => number +>() => i : () => number +>i : number + + return 1; +>1 : 1 + } +} + diff --git a/tests/baselines/reference/asyncAwait_es5.js b/tests/baselines/reference/asyncAwait_es5.js index e148de70ad2..aff57260248 100644 --- a/tests/baselines/reference/asyncAwait_es5.js +++ b/tests/baselines/reference/asyncAwait_es5.js @@ -49,7 +49,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -59,12 +59,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -75,8 +81,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/baselines/reference/asyncFunctionNoReturnType.js b/tests/baselines/reference/asyncFunctionNoReturnType.js index a3635b85a09..50f9526ea58 100644 --- a/tests/baselines/reference/asyncFunctionNoReturnType.js +++ b/tests/baselines/reference/asyncFunctionNoReturnType.js @@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -25,12 +25,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -41,8 +47,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/baselines/reference/asyncImportedPromise_es5.js b/tests/baselines/reference/asyncImportedPromise_es5.js index 54d1b0fdac8..e96e55b7b97 100644 --- a/tests/baselines/reference/asyncImportedPromise_es5.js +++ b/tests/baselines/reference/asyncImportedPromise_es5.js @@ -35,7 +35,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -45,12 +45,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -61,8 +67,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/baselines/reference/asyncMultiFile_es5.js b/tests/baselines/reference/asyncMultiFile_es5.js index 197127c5f10..75473908a75 100644 --- a/tests/baselines/reference/asyncMultiFile_es5.js +++ b/tests/baselines/reference/asyncMultiFile_es5.js @@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -25,12 +25,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -41,8 +47,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/baselines/reference/es5-asyncFunction.js b/tests/baselines/reference/es5-asyncFunction.js index 9cb6f1d3674..35080dda75b 100644 --- a/tests/baselines/reference/es5-asyncFunction.js +++ b/tests/baselines/reference/es5-asyncFunction.js @@ -18,7 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -28,12 +28,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -44,8 +50,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/baselines/reference/es5-importHelpersAsyncFunctions.js b/tests/baselines/reference/es5-importHelpersAsyncFunctions.js index 0fcd8897018..11a8b1d9d29 100644 --- a/tests/baselines/reference/es5-importHelpersAsyncFunctions.js +++ b/tests/baselines/reference/es5-importHelpersAsyncFunctions.js @@ -38,7 +38,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f; + var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; function step(op) { if (f) throw new TypeError("Generator is already executing."); while (1) { @@ -48,12 +48,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) { case 2: return { value: op[1], done: true }; } try { - switch (f = 1, op[0]) { + if (f = 1, y) { + v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; + if (v && !(v = v.call(y, op[1])).done) return v; + if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; + } + switch (op[0]) { case 0: case 1: sent = op; break; case 4: return _.label++, { value: op[1], done: false }; + case 5: _.label++, y = op[1], op = [0]; continue; case 7: op = _.stack.pop(), _.trys.pop(); continue; default: - var r = _.trys.length > 0 && _.trys[_.trys.length - 1]; + r = _.trys.length > 0 && _.trys[_.trys.length - 1]; if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } @@ -64,8 +70,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } op = body.call(thisArg, _); } - catch (e) { op = [6, e]; } - finally { f = 0, sent = void 0; } + catch (e) { op = [6, e], y = void 0; } + finally { f = 0, sent = v = r = void 0; } } } return { diff --git a/tests/cases/compiler/asyncAwaitWithCapturedBlockScopeVar.ts b/tests/cases/compiler/asyncAwaitWithCapturedBlockScopeVar.ts new file mode 100644 index 00000000000..6db92f0273d --- /dev/null +++ b/tests/cases/compiler/asyncAwaitWithCapturedBlockScopeVar.ts @@ -0,0 +1,37 @@ +// @target: es5 +// @lib: es6 +// @noEmitHelpers: true +async function fn1() { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + } +} + +async function fn2() { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + break; + } +} + +async function fn3() { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + continue; + } +} + +async function fn4(): Promise { + let ar = []; + for (let i = 0; i < 1; i++) { + await 1; + ar.push(() => i); + return 1; + } +} From 094cb6d6d709cb086519e8e2d7eb6b2eb6e2ee00 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 13 Sep 2016 12:58:53 -0700 Subject: [PATCH 18/18] Added comments for __generator, reduced overall size of helper --- src/compiler/emitter.ts | 117 ++++++++++++------ src/compiler/transformers/generators.ts | 19 +-- .../asyncAwaitIsolatedModules_es5.js | 58 ++++----- tests/baselines/reference/asyncAwait_es5.js | 58 ++++----- .../reference/asyncFunctionNoReturnType.js | 58 ++++----- .../reference/asyncImportedPromise_es5.js | 58 ++++----- .../baselines/reference/asyncMultiFile_es5.js | 58 ++++----- .../baselines/reference/es5-asyncFunction.js | 58 ++++----- .../es5-importHelpersAsyncFunctions.js | 58 ++++----- 9 files changed, 237 insertions(+), 305 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 76a547b11e4..14e743cf59f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -71,49 +71,92 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); };`; + // The __generator helper is used by down-level transformations to emulate the runtime + // semantics of an ES2015 generator function. When called, this helper returns an + // object that implements the Iterator protocol, in that it has `next`, `return`, and + // `throw` methods that step through the generator when invoked. + // + // parameters: + // thisArg The value to use as the `this` binding for the transformed generator body. + // body A function that acts as the transformed generator body. + // + // variables: + // _ Persistent state for the generator that is shared between the helper and the + // generator body. The state object has the following members: + // sent() - A method that returns or throws the current completion value. + // label - The next point at which to resume evaluation of the generator body. + // trys - A stack of protected regions (try/catch/finally blocks). + // ops - A stack of pending instructions when inside of a finally block. + // f A value indicating whether the generator is executing. + // y An iterator to delegate for a yield*. + // t A temporary variable that holds one of the following values (note that these + // cases do not overlap): + // - The completion value when resuming from a `yield` or `yield*`. + // - The error value for a catch block. + // - The current protected region (array of try/catch/finally/end labels). + // - The verb (`next`, `throw`, or `return` method) to delegate to the expression + // of a `yield*`. + // - The result of evaluating the verb delegated to the expression of a `yield*`. + // + // functions: + // verb(n) Creates a bound callback to the `step` function for opcode `n`. + // step(op) Evaluates opcodes in a generator body until execution is suspended or + // completed. + // + // The __generator helper understands a limited set of instructions: + // 0: next(value?) - Start or resume the generator with the specified value. + // 1: throw(error) - Resume the generator with an exception. If the generator is + // suspended inside of one or more protected regions, evaluates + // any intervening finally blocks between the current label and + // the nearest catch block or function boundary. If uncaught, the + // exception is thrown to the caller. + // 2: return(value?) - Resume the generator as if with a return. If the generator is + // suspended inside of one or more protected regions, evaluates any + // intervening finally blocks. + // 3: break(label) - Jump to the specified label. If the label is outside of the + // current protected region, evaluates any intervening finally + // blocks. + // 4: yield(value?) - Yield execution to the caller with an optional value. When + // resumed, the generator will continue at the next label. + // 5: yield*(value) - Delegates evaluation to the supplied iterator. When + // delegation completes, the generator will continue at the next + // label. + // 6: catch(error) - Handles an exception thrown from within the generator body. If + // the current label is inside of one or more protected regions, + // evaluates any intervening finally blocks between the current + // label and the nearest catch block or function boundary. If + // uncaught, the exception is thrown to the caller. + // 7: endfinally - Ends a finally block, resuming the last instruction prior to + // entering a finally block. + // + // For examples of how these are used, see the comments in ./transformers/generators.ts const generatorHelper = ` var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; };`; // emit output for the __export helper function diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 60e4a0cb546..76ecdac26f9 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -21,10 +21,11 @@ // .brfalse LABEL, (x) - Jump to a label IIF the expression `x` is falsey. // If jumping out of a protected region, all .finally // blocks are executed. -// .yield RESUME, (x) - Yield the value of the optional expression `x`. -// Resume at the label RESUME. -// .yieldstar RESUME, (x) - Delegate yield to the value of the optional -// expression `x`. Resume at the label RESUME. +// .yield (x) - Yield the value of the optional expression `x`. +// Resume at the next label. +// .yieldstar (x) - Delegate yield to the value of the optional +// expression `x`. Resume at the next label. +// NOTE: `x` must be an Iterator, not an Iterable. // .loop CONTINUE, BREAK - Marks the beginning of a loop. Any "continue" or // "break" abrupt completions jump to the CONTINUE or // BREAK labels, respectively. @@ -80,13 +81,13 @@ // -------------------------------|---------------------------------------------- // .brfalse LABEL, (x) | if (!(x)) return [3, /*break*/, LABEL]; // -------------------------------|---------------------------------------------- -// .yield RESUME, (x) | return [4 /*yield*/, x]; +// .yield (x) | return [4 /*yield*/, x]; // .mark RESUME | case RESUME: -// a = %sent%; | a = state.sent(); +// a = %sent%; | a = state.sent(); // -------------------------------|---------------------------------------------- -// .yieldstar RESUME, (X) | return [5 /*yield**/, x]; +// .yieldstar (x) | return [5 /*yield**/, x]; // .mark RESUME | case RESUME: -// a = %sent%; | a = state.sent(); +// a = %sent%; | a = state.sent(); // -------------------------------|---------------------------------------------- // .with (_a) | with (_a) { // a(); | a(); @@ -109,7 +110,7 @@ // .br END | return [3 /*break*/, END]; // .catch (e) | // .mark CATCH | case CATCH: -// | e = state.error; +// | e = state.sent(); // b(); | b(); // .br END | return [3 /*break*/, END]; // .finally | diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js index 02da40c6c23..7eb2157c026 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es5.js @@ -50,47 +50,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; var _this = this; function f0() { diff --git a/tests/baselines/reference/asyncAwait_es5.js b/tests/baselines/reference/asyncAwait_es5.js index aff57260248..67f7d000351 100644 --- a/tests/baselines/reference/asyncAwait_es5.js +++ b/tests/baselines/reference/asyncAwait_es5.js @@ -49,47 +49,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; var _this = this; function f0() { diff --git a/tests/baselines/reference/asyncFunctionNoReturnType.js b/tests/baselines/reference/asyncFunctionNoReturnType.js index 50f9526ea58..fc7b0b52f1c 100644 --- a/tests/baselines/reference/asyncFunctionNoReturnType.js +++ b/tests/baselines/reference/asyncFunctionNoReturnType.js @@ -15,47 +15,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; var _this = this; (function () { return __awaiter(_this, void 0, void 0, function () { diff --git a/tests/baselines/reference/asyncImportedPromise_es5.js b/tests/baselines/reference/asyncImportedPromise_es5.js index e96e55b7b97..0e6e8d51501 100644 --- a/tests/baselines/reference/asyncImportedPromise_es5.js +++ b/tests/baselines/reference/asyncImportedPromise_es5.js @@ -35,47 +35,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; var task_1 = require("./task"); var Test = (function () { diff --git a/tests/baselines/reference/asyncMultiFile_es5.js b/tests/baselines/reference/asyncMultiFile_es5.js index 75473908a75..cfc3cb235b0 100644 --- a/tests/baselines/reference/asyncMultiFile_es5.js +++ b/tests/baselines/reference/asyncMultiFile_es5.js @@ -15,47 +15,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; function f() { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { diff --git a/tests/baselines/reference/es5-asyncFunction.js b/tests/baselines/reference/es5-asyncFunction.js index 35080dda75b..d6cd770e454 100644 --- a/tests/baselines/reference/es5-asyncFunction.js +++ b/tests/baselines/reference/es5-asyncFunction.js @@ -18,47 +18,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; function empty() { return __awaiter(this, void 0, void 0, function () { diff --git a/tests/baselines/reference/es5-importHelpersAsyncFunctions.js b/tests/baselines/reference/es5-importHelpersAsyncFunctions.js index 11a8b1d9d29..6c9a16b546f 100644 --- a/tests/baselines/reference/es5-importHelpersAsyncFunctions.js +++ b/tests/baselines/reference/es5-importHelpersAsyncFunctions.js @@ -38,47 +38,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, y, f, v, r; + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; + return { next: verb(0), "throw": verb(1), "return": verb(2) }; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); - while (1) { - if (_.done) switch (op[0]) { - case 0: return { value: void 0, done: true }; - case 1: case 6: throw op[1]; - case 2: return { value: op[1], done: true }; + while (_) try { + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [0, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; } - try { - if (f = 1, y) { - v = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]; - if (v && !(v = v.call(y, op[1])).done) return v; - if (y = void 0, v) op[0] = 0, op[1] = v.value; continue; - } - switch (op[0]) { - case 0: case 1: sent = op; break; - case 4: return _.label++, { value: op[1], done: false }; - case 5: _.label++, y = op[1], op = [0]; continue; - case 7: op = _.stack.pop(), _.trys.pop(); continue; - default: - r = _.trys.length > 0 && _.trys[_.trys.length - 1]; - if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; } - if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; } - if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; } - if (r[2]) { _.stack.pop(); } - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } - catch (e) { op = [6, e], y = void 0; } - finally { f = 0, sent = v = r = void 0; } - } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - return { - next: function (v) { return step([0, v]); }, - "throw": function (v) { return step([1, v]); }, - "return": function (v) { return step([2, v]); } - }; }; function foo() { return __awaiter(this, void 0, void 0, function () {