From bb8cf903b585b1f65759c5a713137383ab1db11b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 12 Sep 2022 16:23:21 -0700 Subject: [PATCH 1/8] Handle more places where package direcroy is converted to canonical file path (#50740) (#50747) * Add test for node16 resolution with package json lookup making casing incorrect * Handle more places where package direcroy is converted to canonical file path --- src/compiler/checker.ts | 2 +- src/compiler/moduleNameResolver.ts | 82 +++++++------ src/compiler/moduleSpecifiers.ts | 2 +- src/compiler/program.ts | 6 +- src/compiler/watch.ts | 2 +- src/server/session.ts | 2 +- .../forceConsistentCasingInFileNames.ts | 31 +++++ .../reactJsxReactResolvedNodeNext.trace.json | 6 +- ...eactJsxReactResolvedNodeNextEsm.trace.json | 6 +- .../package-json-is-looked-up-for-file.js | 116 ++++++++++++++++++ .../self-name-package-reference.js | 4 +- .../with-nodeNext-resolution.js | 24 ++-- ...it.multiFileBackReferenceToSelf.trace.json | 6 +- 13 files changed, 220 insertions(+), 69 deletions(-) create mode 100644 tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 194f51256860b..f5d366aa445a9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3627,7 +3627,7 @@ namespace ts { if (ext === Extension.Ts || ext === Extension.Js || ext === Extension.Tsx || ext === Extension.Jsx) { const scope = currentSourceFile.packageJsonScope; const targetExt = ext === Extension.Ts ? Extension.Mts : ext === Extension.Js ? Extension.Mjs : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = chainDiagnosticMessages( /*details*/ undefined, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 9e3b15f09580c..3e46edbec46c1 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -13,7 +13,7 @@ namespace ts { function withPackageId(packageInfo: PackageJsonInfo | undefined, r: PathAndExtension | undefined): Resolved | undefined { let packageId: PackageId | undefined; if (r && packageInfo) { - const packageJsonContent = packageInfo.packageJsonContent as PackageJson; + const packageJsonContent = packageInfo.contents.packageJsonContent as PackageJson; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -1679,8 +1679,8 @@ namespace ts { function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState, considerPackageJson = true) { const packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - const packageJsonContent = packageInfo && packageInfo.packageJsonContent; - const versionPaths = packageInfo && packageInfo.versionPaths; + const packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + const versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } @@ -1692,10 +1692,10 @@ namespace ts { cache: ModuleResolutionCache | undefined, resolveJs?: boolean, ): string[] | false { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } let entrypoints: string[] | undefined; @@ -1709,16 +1709,16 @@ namespace ts { packageJsonInfo.packageDirectory, /*onlyRecordFailures*/ false, requireState, - packageJsonInfo.packageJsonContent, - packageJsonInfo.versionPaths); + packageJsonInfo.contents.packageJsonContent, + packageJsonInfo.contents.versionPaths); entrypoints = append(entrypoints, requireResolution?.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (const conditions of [["node", "import", "types"], ["node", "require", "types"]]) { const exportState = { ...requireState, failedLookupLocations: [], conditions }; const exportResolutions = loadEntrypointsFromExportMap( packageJsonInfo, - packageJsonInfo.packageJsonContent.exports, + packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { @@ -1729,7 +1729,7 @@ namespace ts { } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } function loadEntrypointsFromExportMap( @@ -1808,6 +1808,10 @@ namespace ts { /*@internal*/ export interface PackageJsonInfo { packageDirectory: string; + contents: PackageJsonInfoContents; + } + /*@internal*/ + export interface PackageJsonInfoContents { packageJsonContent: PackageJsonPathFields; versionPaths: VersionPaths | undefined; /** false: resolved to nothing. undefined: not yet resolved */ @@ -1818,7 +1822,7 @@ namespace ts { * A function for locating the package.json scope for a given path */ /*@internal*/ - export function getPackageScopeForPath(fileName: Path, state: ModuleResolutionState): PackageJsonInfo | undefined { + export function getPackageScopeForPath(fileName: string, state: ModuleResolutionState): PackageJsonInfo | undefined { const parts = getPathComponents(fileName); parts.pop(); while (parts.length > 0) { @@ -1845,7 +1849,9 @@ namespace ts { if (typeof existing !== "boolean") { if (traceEnabled) trace(host, Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) trace(host, Diagnostics.File_0_does_not_exist_according_to_earlier_cached_lookups, packageJsonPath); @@ -1860,7 +1866,7 @@ namespace ts { trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath); } const versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - const result = { packageDirectory, packageJsonContent, versionPaths, resolvedEntrypoints: undefined }; + const result: PackageJsonInfo = { packageDirectory, contents: { packageJsonContent, versionPaths, resolvedEntrypoints: undefined } }; state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -1994,17 +2000,16 @@ namespace ts { } function loadModuleFromSelfNameReference(extensions: Extensions, moduleName: string, directory: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { - const useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - const directoryPath = toPath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.(), createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.()); const scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } const parts = getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - const nameParts = getPathComponents(scope.packageJsonContent.name); + const nameParts = getPathComponents(scope.contents.packageJsonContent.name); if (!every(nameParts, (p, i) => parts[i] === p)) { return undefined; } @@ -2013,31 +2018,31 @@ namespace ts { } function loadModuleFromExports(scope: PackageJsonInfo, extensions: Extensions, subpath: string, state: ModuleResolutionState, cache: ModuleResolutionCache | undefined, redirectedReference: ResolvedProjectReference | undefined): SearchResult { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { let mainExport; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports as MapLike))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports as MapLike))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (hasProperty(scope.packageJsonContent.exports as MapLike, ".")) { - mainExport = (scope.packageJsonContent.exports as MapLike)["."]; + else if (hasProperty(scope.contents.packageJsonContent.exports as MapLike, ".")) { + mainExport = (scope.contents.packageJsonContent.exports as MapLike)["."]; } if (mainExport) { const loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports as MapLike)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports as MapLike)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -2056,8 +2061,7 @@ namespace ts { } return toSearchResult(/*value*/ undefined); } - const useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - const directoryPath = toPath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.(), createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + const directoryPath = getNormalizedAbsolutePath(combinePaths(directory, "dummy"), state.host.getCurrentDirectory?.()); const scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -2065,14 +2069,14 @@ namespace ts { } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + const result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -2426,8 +2430,8 @@ namespace ts { candidate, !nodeModulesDirectoryExists, state, - packageInfo.packageJsonContent, - packageInfo.versionPaths + packageInfo.contents.packageJsonContent, + packageInfo.contents.versionPaths ); return withPackageId(packageInfo, fromDirectory); } @@ -2436,7 +2440,7 @@ namespace ts { const { packageName, rest } = parsePackageName(moduleName); const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => { // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value; } let pathAndExtension = @@ -2446,13 +2450,13 @@ namespace ts { candidate, onlyRecordFailures, state, - packageInfo && packageInfo.packageJsonContent, - packageInfo && packageInfo.versionPaths + packageInfo && packageInfo.contents.packageJsonContent, + packageInfo && packageInfo.contents.versionPaths ); if ( !pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode ) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume @@ -2467,12 +2471,12 @@ namespace ts { // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, version, rest); + trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, version, rest); } const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host); - const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index e38dd46598587..32640fcb81579 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -807,7 +807,7 @@ namespace ts.moduleSpecifiers { let maybeBlockedByTypesVersions = false; const cachedPackageJson = host.getPackageJsonInfoCache?.()?.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - const packageJsonContent = cachedPackageJson?.packageJsonContent || JSON.parse(host.readFile!(packageJsonPath)!); + const packageJsonContent = cachedPackageJson?.contents.packageJsonContent || JSON.parse(host.readFile!(packageJsonPath)!); const importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node16 || getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) { const conditions = ["node", importMode === ModuleKind.ESNext ? "import" : "require", "types"]; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e7c0f363ea8df..09732d4a81b62 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -849,7 +849,7 @@ namespace ts { /*@internal*/ export function getImpliedNodeFormatForFileWorker( - fileName: Path, + fileName: string, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions, @@ -870,7 +870,7 @@ namespace ts { state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; const packageJsonScope = getPackageScopeForPath(fileName, state); - const impliedNodeFormat = packageJsonScope?.packageJsonContent.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS; + const impliedNodeFormat = packageJsonScope?.contents.packageJsonContent.type === "module" ? ModuleKind.ESNext : ModuleKind.CommonJS; return { impliedNodeFormat, packageJsonLocations, packageJsonScope }; } } @@ -2828,7 +2828,7 @@ namespace ts { // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - const result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache?.getPackageJsonInfoCache(), host, options); + const result = getImpliedNodeFormatForFileWorker(getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache?.getPackageJsonInfoCache(), host, options); const languageVersion = getEmitScriptTarget(options); const setExternalModuleIndicator = getSetExternalModuleIndicator(options); return typeof result === "object" ? diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 23e9da91c6243..d1851cd02cd08 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -262,7 +262,7 @@ namespace ts { if (file.packageJsonScope) { (result ??= []).push(chainDiagnosticMessages( /*details*/ undefined, - file.packageJsonScope.packageJsonContent.type ? + file.packageJsonScope.contents.packageJsonContent.type ? Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(last(file.packageJsonLocations!), fileNameConvertor) diff --git a/src/server/session.ts b/src/server/session.ts index a541463063c5c..c6350971b5141 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1378,7 +1378,7 @@ namespace ts.server { const packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex); const packageJsonCache = project.getModuleResolutionCache()?.getPackageJsonInfoCache(); const compilerOptions = project.getCompilationSettings(); - const packageJson = getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); + const packageJson = getPackageScopeForPath(getNormalizedAbsolutePath(packageDirectory + "/package.json", project.getCurrentDirectory()), getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); if (!packageJson) return undefined; // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext - // Mapping from an export map entry across packages is out of scope for now. Returned entrypoints will only be what can be diff --git a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts index 584b32c33535c..d00ea144ea9d4 100644 --- a/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts +++ b/src/testRunner/unittests/tscWatch/forceConsistentCasingInFileNames.ts @@ -326,5 +326,36 @@ a;b; }, { currentDirectory: "/Users/name/projects/web" }), changes: emptyArray, }); + + + verifyTscWatch({ + scenario: "forceConsistentCasingInFileNames", + subScenario: "package json is looked up for file", + commandLineArgs: ["-w", "--explainFiles"], + sys: () => createWatchedSystem({ + "/Users/name/projects/lib-boilerplate/package.json": JSON.stringify({ + name: "lib-boilerplate", + version: "0.0.2", + type: "module", + exports: "./src/index.ts", + }), + "/Users/name/projects/lib-boilerplate/src/index.ts": Utils.dedent` + export function thing(): void {} + `, + "/Users/name/projects/lib-boilerplate/test/basic.spec.ts": Utils.dedent` + import { thing } from 'lib-boilerplate' + `, + "/Users/name/projects/lib-boilerplate/tsconfig.json": JSON.stringify({ + compilerOptions: { + module: "node16", + target: "es2021", + forceConsistentCasingInFileNames: true, + traceResolution: true, + } + }), + "/a/lib/lib.es2021.full.d.ts": libFile.content, + }, { currentDirectory: "/Users/name/projects/lib-boilerplate" }), + changes: emptyArray, + }); }); } diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json b/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json index ac5303a7910d3..889f6175f8e30 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNext.trace.json @@ -25,15 +25,15 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index.d.ts' that references 'tests/cases/compiler/node_modules/@types/react/index.d.ts'.", "File 'tests/cases/compiler/node_modules/@types/react/index.d.ts' exist - use it as a name resolution result.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'package.json' does not exist.", "File '/package.json' does not exist according to earlier cached lookups.", "File 'package.json' does not exist according to earlier cached lookups.", diff --git a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json index ec1743f45c7a2..f6d41335975a1 100644 --- a/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json +++ b/tests/baselines/reference/reactJsxReactResolvedNodeNextEsm.trace.json @@ -19,15 +19,15 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index.d.ts' that references 'tests/cases/compiler/node_modules/@types/react/index.d.ts'.", "File 'tests/cases/compiler/node_modules/@types/react/index.d.ts' exist - use it as a name resolution result.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'tests/cases/compiler/node_modules/@types/react/package.json' exists according to earlier cached lookups.", "======== Resolving module './' from 'tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts'. ========", "Resolution for module './' was found in cache from location 'tests/cases/compiler/node_modules/@types/react'.", - "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/index.d.ts@0.0.1'. ========", + "======== Module name './' was successfully resolved to 'tests/cases/compiler/node_modules/@types/react/index.d.ts' with Package ID '@types/react/ndex.d.ts@0.0.1'. ========", "File 'package.json' does not exist.", "File '/package.json' does not exist.", "File 'package.json' does not exist according to earlier cached lookups.", diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js new file mode 100644 index 0000000000000..a08892695f0a5 --- /dev/null +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js @@ -0,0 +1,116 @@ +Input:: +//// [/Users/name/projects/lib-boilerplate/package.json] +{"name":"lib-boilerplate","version":"0.0.2","type":"module","exports":"./src/index.ts"} + +//// [/Users/name/projects/lib-boilerplate/src/index.ts] +export function thing(): void {} + + +//// [/Users/name/projects/lib-boilerplate/test/basic.spec.ts] +import { thing } from 'lib-boilerplate' + + +//// [/Users/name/projects/lib-boilerplate/tsconfig.json] +{"compilerOptions":{"module":"node16","target":"es2021","forceConsistentCasingInFileNames":true,"traceResolution":true}} + +//// [/a/lib/lib.es2021.full.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + + +/a/lib/tsc.js -w --explainFiles +Output:: +>> Screen clear +[12:00:29 AM] Starting compilation in watch mode... + +File '/Users/name/projects/lib-boilerplate/src/package.json' does not exist. +Found 'package.json' at '/Users/name/projects/lib-boilerplate/package.json'. +'package.json' does not have a 'typesVersions' field. +File '/Users/name/projects/lib-boilerplate/test/package.json' does not exist. +File '/Users/name/projects/lib-boilerplate/package.json' exists according to earlier cached lookups. +======== Resolving module 'lib-boilerplate' from '/Users/name/projects/lib-boilerplate/test/basic.spec.ts'. ======== +Module resolution kind is not specified, using 'Node16'. +File '/Users/name/projects/lib-boilerplate/test/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/lib-boilerplate/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/lib-boilerplate/src/index.ts' exist - use it as a name resolution result. +Resolving real path for '/Users/name/projects/lib-boilerplate/src/index.ts', result '/Users/name/projects/lib-boilerplate/src/index.ts'. +======== Module name 'lib-boilerplate' was successfully resolved to '/Users/name/projects/lib-boilerplate/src/index.ts' with Package ID 'lib-boilerplate/src/index.ts@0.0.2'. ======== +File '/a/lib/package.json' does not exist. +File '/a/package.json' does not exist. +File '/package.json' does not exist. +../../../../a/lib/lib.es2021.full.d.ts + Default library for target 'es2021' +src/index.ts + Matched by default include pattern '**/*' + Imported via 'lib-boilerplate' from file 'test/basic.spec.ts' with packageId 'lib-boilerplate/src/index.ts@0.0.2' + File is ECMAScript module because 'package.json' has field "type" with value "module" +test/basic.spec.ts + Matched by default include pattern '**/*' + File is ECMAScript module because 'package.json' has field "type" with value "module" +[12:00:34 AM] Found 0 errors. Watching for file changes. + + + +Program root files: ["/Users/name/projects/lib-boilerplate/src/index.ts","/Users/name/projects/lib-boilerplate/test/basic.spec.ts"] +Program options: {"module":100,"target":8,"forceConsistentCasingInFileNames":true,"traceResolution":true,"watch":true,"explainFiles":true,"configFilePath":"/Users/name/projects/lib-boilerplate/tsconfig.json"} +Program structureReused: Not +Program files:: +/a/lib/lib.es2021.full.d.ts +/Users/name/projects/lib-boilerplate/src/index.ts +/Users/name/projects/lib-boilerplate/test/basic.spec.ts + +Semantic diagnostics in builder refreshed for:: +/a/lib/lib.es2021.full.d.ts +/Users/name/projects/lib-boilerplate/src/index.ts +/Users/name/projects/lib-boilerplate/test/basic.spec.ts + +Shape signatures in builder refreshed for:: +/a/lib/lib.es2021.full.d.ts (used version) +/users/name/projects/lib-boilerplate/src/index.ts (used version) +/users/name/projects/lib-boilerplate/test/basic.spec.ts (used version) + +WatchedFiles:: +/users/name/projects/lib-boilerplate/tsconfig.json: + {"fileName":"/Users/name/projects/lib-boilerplate/tsconfig.json","pollingInterval":250} +/users/name/projects/lib-boilerplate/src/index.ts: + {"fileName":"/Users/name/projects/lib-boilerplate/src/index.ts","pollingInterval":250} +/users/name/projects/lib-boilerplate/test/basic.spec.ts: + {"fileName":"/Users/name/projects/lib-boilerplate/test/basic.spec.ts","pollingInterval":250} +/a/lib/lib.es2021.full.d.ts: + {"fileName":"/a/lib/lib.es2021.full.d.ts","pollingInterval":250} +/users/name/projects/lib-boilerplate/package.json: + {"fileName":"/Users/name/projects/lib-boilerplate/package.json","pollingInterval":250} +/users/name/projects/lib-boilerplate/src/package.json: + {"fileName":"/Users/name/projects/lib-boilerplate/src/package.json","pollingInterval":250} +/users/name/projects/lib-boilerplate/test/package.json: + {"fileName":"/Users/name/projects/lib-boilerplate/test/package.json","pollingInterval":250} +/users/name/projects/lib-boilerplate/node_modules/@types: + {"fileName":"/Users/name/projects/lib-boilerplate/node_modules/@types","pollingInterval":500} + +FsWatches:: + +FsWatchesRecursive:: +/users/name/projects/lib-boilerplate/test: + {"directoryName":"/Users/name/projects/lib-boilerplate/test"} +/users/name/projects/lib-boilerplate: + {"directoryName":"/users/name/projects/lib-boilerplate"} + +exitCode:: ExitStatus.undefined + +//// [/Users/name/projects/lib-boilerplate/src/index.js] +export function thing() { } + + +//// [/Users/name/projects/lib-boilerplate/test/basic.spec.js] +export {}; + + diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js index 02b1358e97ad7..009f8ee29cba5 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js @@ -30,11 +30,11 @@ Output:: >> Screen clear [12:00:23 AM] Starting compilation in watch mode... -Found 'package.json' at '/users/name/projects/web/package.json'. +Found 'package.json' at '/Users/name/projects/web/package.json'. 'package.json' does not have a 'typesVersions' field. ======== Resolving module '@this/package' from '/Users/name/projects/web/index.ts'. ======== Module resolution kind is not specified, using 'NodeNext'. -File '/users/name/projects/web/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/web/package.json' exists according to earlier cached lookups. File '/Users/name/projects/web/index.ts' exist - use it as a name resolution result. Resolving real path for '/Users/name/projects/web/index.ts', result '/Users/name/projects/web/index.ts'. ======== Module name '@this/package' was successfully resolved to '/Users/name/projects/web/index.ts'. ======== diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js index efcf899a34ffa..39ddc54f4443d 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js @@ -33,19 +33,19 @@ Output:: >> Screen clear [12:00:35 AM] Starting compilation in watch mode... -File '/users/name/projects/web/src/package.json' does not exist. -File '/users/name/projects/web/package.json' does not exist. -File '/users/name/projects/package.json' does not exist. -File '/users/name/package.json' does not exist. -File '/users/package.json' does not exist. +File '/Users/name/projects/web/src/package.json' does not exist. +File '/Users/name/projects/web/package.json' does not exist. +File '/Users/name/projects/package.json' does not exist. +File '/Users/name/package.json' does not exist. +File '/Users/package.json' does not exist. File '/package.json' does not exist. ======== Resolving module 'yargs' from '/Users/name/projects/web/src/bin.ts'. ======== Explicitly specified module resolution kind: 'NodeNext'. -File '/users/name/projects/web/src/package.json' does not exist according to earlier cached lookups. -File '/users/name/projects/web/package.json' does not exist according to earlier cached lookups. -File '/users/name/projects/package.json' does not exist according to earlier cached lookups. -File '/users/name/package.json' does not exist according to earlier cached lookups. -File '/users/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/web/src/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/web/package.json' does not exist according to earlier cached lookups. +File '/Users/name/projects/package.json' does not exist according to earlier cached lookups. +File '/Users/name/package.json' does not exist according to earlier cached lookups. +File '/Users/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'yargs' from 'node_modules' folder, target file type 'TypeScript'. Directory '/Users/name/projects/web/src/node_modules' does not exist, skipping all lookups in it. @@ -57,7 +57,7 @@ Found 'package.json' at '/Users/name/projects/web/node_modules/@types/yargs/pack File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. ======== Module name 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12'. ======== -File '/users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. +File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. ======== Resolving type reference directive 'yargs', containing file '/Users/name/projects/web/__inferred type names__.ts', root directory '/Users/name/projects/web/node_modules/@types'. ======== Resolving with primary search path '/Users/name/projects/web/node_modules/@types'. File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. @@ -124,7 +124,7 @@ FsWatches:: FsWatchesRecursive:: /users/name/projects/web/src: - {"directoryName":"/users/name/projects/web/src"} + {"directoryName":"/Users/name/projects/web/src"} /users/name/projects/web/node_modules: {"directoryName":"/Users/name/projects/web/node_modules"} /users/name/projects/web/node_modules/@types: diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json index a487a795006e0..64f195b78e58f 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json @@ -22,7 +22,7 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json' exists according to earlier cached lookups.", - "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/ther.d.ts@1.0.0'. ========", + "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========", "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", @@ -41,7 +41,7 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/s3.1/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", @@ -53,5 +53,5 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/s3.1/other.d.ts@1.0.0'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/ts3.1/other.d.ts@1.0.0'. ========" ] \ No newline at end of file From a3b355508657c6b4864fa2d72167956a9bdef52c Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 16 Sep 2022 09:44:11 -0700 Subject: [PATCH 2/8] Cherry-pick PR #50797 into release-4.8 (#50798) Component commits: 23a1dd4d74 Fix bounds check 23784d711e Add regression test Co-authored-by: Anders Hejlsberg --- src/compiler/checker.ts | 4 +- ...rTypeConstraintInstantiationCircularity.js | 21 +++++++- ...ConstraintInstantiationCircularity.symbols | 48 +++++++++++++++++++ ...peConstraintInstantiationCircularity.types | 31 ++++++++++++ ...rTypeConstraintInstantiationCircularity.ts | 20 +++++++- 5 files changed, 120 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f5d366aa445a9..8a0622cff450f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35931,8 +35931,8 @@ namespace ts { } function getEffectiveTypeArgumentAtIndex(node: TypeReferenceNode | ExpressionWithTypeArguments, typeParameters: readonly TypeParameter[], index: number): Type { - if (index < typeParameters.length) { - return getTypeFromTypeNode(node.typeArguments![index]); + if (node.typeArguments && index < node.typeArguments.length) { + return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; } diff --git a/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.js b/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.js index ca1488ed98615..e47b01ff47753 100644 --- a/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.js +++ b/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.js @@ -70,7 +70,26 @@ type MyObject = T extends ZodObject ? U extends ZodRawShape ? U : never - : never; + : never; + +// Repro from #50479 + +type Cell = { + id: string +} + +type Items = { + type: Type + name: string +} + +type InferIOItemToJSType = + T extends { type: infer U } + ? U extends Cell + ? V + : never + : never + //// [inferTypeConstraintInstantiationCircularity.js] "use strict"; diff --git a/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.symbols b/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.symbols index 4feca7bdc5e0f..10837383c8843 100644 --- a/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.symbols +++ b/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.symbols @@ -204,3 +204,51 @@ type MyObject = T extends ZodObject : never : never; + +// Repro from #50479 + +type Cell = { +>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10)) +>Value : Symbol(Value, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 10)) +>BaseValue : Symbol(BaseValue, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 40)) +>BaseValue : Symbol(BaseValue, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 40)) + + id: string +>id : Symbol(id, Decl(inferTypeConstraintInstantiationCircularity.ts, 75, 65)) +} + +type Items = { +>Items : Symbol(Items, Decl(inferTypeConstraintInstantiationCircularity.ts, 77, 1)) +>Type : Symbol(Type, Decl(inferTypeConstraintInstantiationCircularity.ts, 79, 11)) +>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10)) +>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10)) + + type: Type +>type : Symbol(type, Decl(inferTypeConstraintInstantiationCircularity.ts, 79, 40)) +>Type : Symbol(Type, Decl(inferTypeConstraintInstantiationCircularity.ts, 79, 11)) + + name: string +>name : Symbol(name, Decl(inferTypeConstraintInstantiationCircularity.ts, 80, 12)) +} + +type InferIOItemToJSType = +>InferIOItemToJSType : Symbol(InferIOItemToJSType, Decl(inferTypeConstraintInstantiationCircularity.ts, 82, 1)) +>T : Symbol(T, Decl(inferTypeConstraintInstantiationCircularity.ts, 84, 25)) +>Items : Symbol(Items, Decl(inferTypeConstraintInstantiationCircularity.ts, 77, 1)) + + T extends { type: infer U } +>T : Symbol(T, Decl(inferTypeConstraintInstantiationCircularity.ts, 84, 25)) +>type : Symbol(type, Decl(inferTypeConstraintInstantiationCircularity.ts, 85, 13)) +>U : Symbol(U, Decl(inferTypeConstraintInstantiationCircularity.ts, 85, 25)) + + ? U extends Cell +>U : Symbol(U, Decl(inferTypeConstraintInstantiationCircularity.ts, 85, 25)) +>Cell : Symbol(Cell, Decl(inferTypeConstraintInstantiationCircularity.ts, 71, 10)) +>V : Symbol(V, Decl(inferTypeConstraintInstantiationCircularity.ts, 86, 26)) + + ? V +>V : Symbol(V, Decl(inferTypeConstraintInstantiationCircularity.ts, 86, 26)) + + : never + : never + diff --git a/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.types b/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.types index 4571ec23357eb..ffdc2752dca62 100644 --- a/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.types +++ b/tests/baselines/reference/inferTypeConstraintInstantiationCircularity.types @@ -101,3 +101,34 @@ type MyObject = T extends ZodObject ? U : never : never; + +// Repro from #50479 + +type Cell = { +>Cell : Cell + + id: string +>id : string +} + +type Items = { +>Items : Items + + type: Type +>type : Type + + name: string +>name : string +} + +type InferIOItemToJSType = +>InferIOItemToJSType : InferIOItemToJSType + + T extends { type: infer U } +>type : U + + ? U extends Cell + ? V + : never + : never + diff --git a/tests/cases/compiler/inferTypeConstraintInstantiationCircularity.ts b/tests/cases/compiler/inferTypeConstraintInstantiationCircularity.ts index ad489da708312..6adf71624e28c 100644 --- a/tests/cases/compiler/inferTypeConstraintInstantiationCircularity.ts +++ b/tests/cases/compiler/inferTypeConstraintInstantiationCircularity.ts @@ -70,4 +70,22 @@ type MyObject = T extends ZodObject ? U extends ZodRawShape ? U : never - : never; \ No newline at end of file + : never; + +// Repro from #50479 + +type Cell = { + id: string +} + +type Items = { + type: Type + name: string +} + +type InferIOItemToJSType = + T extends { type: infer U } + ? U extends Cell + ? V + : never + : never From 57737235d6d375be881f5284467af556a2bbfb07 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Sep 2022 17:21:19 -0700 Subject: [PATCH 3/8] Cherry-pick #50724 to release-4.8 (#50760) Co-authored-by: Oleksandr T --- src/compiler/parser.ts | 1 + src/services/goToDefinition.ts | 2 +- tests/baselines/reference/jsdocLinkTag6.js | 45 +++++++++++++++++++ .../baselines/reference/jsdocLinkTag6.symbols | 18 ++++++++ tests/baselines/reference/jsdocLinkTag6.types | 18 ++++++++ .../cases/conformance/jsdoc/jsdocLinkTag6.ts | 10 +++++ .../goToDefinitionOverriddenMember11.ts | 2 +- 7 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/jsdocLinkTag6.js create mode 100644 tests/baselines/reference/jsdocLinkTag6.symbols create mode 100644 tests/baselines/reference/jsdocLinkTag6.types create mode 100644 tests/cases/conformance/jsdoc/jsdocLinkTag6.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6913a31b0d18..349b313104cfb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -662,6 +662,7 @@ namespace ts { case SyntaxKind.JSDocProtectedTag: case SyntaxKind.JSDocReadonlyTag: case SyntaxKind.JSDocDeprecatedTag: + case SyntaxKind.JSDocOverrideTag: return visitNode(cbNode, (node as JSDocTag).tagName) || (typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray | undefined)); case SyntaxKind.PartiallyEmittedExpression: diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 15ecb41bb4357..40cac0a916d41 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -16,7 +16,7 @@ namespace ts.GoToDefinition { const { parent } = node; const typeChecker = program.getTypeChecker(); - if (node.kind === SyntaxKind.OverrideKeyword || (isJSDocOverrideTag(node) && rangeContainsPosition(node.tagName, position))) { + if (node.kind === SyntaxKind.OverrideKeyword || (isIdentifier(node) && isJSDocOverrideTag(parent) && parent.tagName === node)) { return getDefinitionFromOverriddenMember(typeChecker, node) || emptyArray; } diff --git a/tests/baselines/reference/jsdocLinkTag6.js b/tests/baselines/reference/jsdocLinkTag6.js new file mode 100644 index 0000000000000..d73280635ce7d --- /dev/null +++ b/tests/baselines/reference/jsdocLinkTag6.js @@ -0,0 +1,45 @@ +//// [a.ts] +class A { + foo() {} +} +class B extends A { + /** + * @override {@link A.foo} + */ + foo() {} +} + + +//// [a.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var A = /** @class */ (function () { + function A() { + } + A.prototype.foo = function () { }; + return A; +}()); +var B = /** @class */ (function (_super) { + __extends(B, _super); + function B() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + * @override {@link A.foo} + */ + B.prototype.foo = function () { }; + return B; +}(A)); diff --git a/tests/baselines/reference/jsdocLinkTag6.symbols b/tests/baselines/reference/jsdocLinkTag6.symbols new file mode 100644 index 0000000000000..3b8f067337242 --- /dev/null +++ b/tests/baselines/reference/jsdocLinkTag6.symbols @@ -0,0 +1,18 @@ +=== /a.ts === +class A { +>A : Symbol(A, Decl(a.ts, 0, 0)) + + foo() {} +>foo : Symbol(A.foo, Decl(a.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(a.ts, 2, 1)) +>A : Symbol(A, Decl(a.ts, 0, 0)) + + /** + * @override {@link A.foo} + */ + foo() {} +>foo : Symbol(B.foo, Decl(a.ts, 3, 19)) +} + diff --git a/tests/baselines/reference/jsdocLinkTag6.types b/tests/baselines/reference/jsdocLinkTag6.types new file mode 100644 index 0000000000000..d3a71dc80f104 --- /dev/null +++ b/tests/baselines/reference/jsdocLinkTag6.types @@ -0,0 +1,18 @@ +=== /a.ts === +class A { +>A : A + + foo() {} +>foo : () => void +} +class B extends A { +>B : B +>A : A + + /** + * @override {@link A.foo} + */ + foo() {} +>foo : () => void +} + diff --git a/tests/cases/conformance/jsdoc/jsdocLinkTag6.ts b/tests/cases/conformance/jsdoc/jsdocLinkTag6.ts new file mode 100644 index 0000000000000..5dcb70ddedfdf --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocLinkTag6.ts @@ -0,0 +1,10 @@ +// @filename: /a.ts +class A { + foo() {} +} +class B extends A { + /** + * @override {@link A.foo} + */ + foo() {} +} diff --git a/tests/cases/fourslash/goToDefinitionOverriddenMember11.ts b/tests/cases/fourslash/goToDefinitionOverriddenMember11.ts index 48eae54dd9f78..ec028630b4c83 100644 --- a/tests/cases/fourslash/goToDefinitionOverriddenMember11.ts +++ b/tests/cases/fourslash/goToDefinitionOverriddenMember11.ts @@ -10,7 +10,7 @@ //// /*Foo_m*/m() {} ////} ////class Bar extends Foo { -//// /** [|@over{|"name": "1"|}ride[| se{|"name": "2"|}e {@li{|"name": "3"|}nk https://test.c{|"name": "4"|}om} {|"name": "5"|}description |]|]*/ +//// /** @[|over{|"name": "1"|}ride|][| se{|"name": "2"|}e {@li{|"name": "3"|}nk https://test.c{|"name": "4"|}om} {|"name": "5"|}description |]*/ //// m() {} ////} From 39576e6f5c373a86415cc48e8e46ddbe58d59cc7 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 22 Sep 2022 14:25:50 -0700 Subject: [PATCH 4/8] Cherry-pick PR #50673 into release-4.8 (#50742) Component commits: 3d0e834041 Remove error message in node16 Co-authored-by: Wesley Wigham --- src/compiler/checker.ts | 2 +- .../nodeModulesImportAssertions(module=node16).errors.txt | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8a0622cff450f..c8a6ce2a9b121 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -45658,7 +45658,7 @@ namespace ts { } const nodeArguments = node.arguments; - if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext) { + if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext && moduleKind !== ModuleKind.Node16) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); diff --git a/tests/baselines/reference/nodeModulesImportAssertions(module=node16).errors.txt b/tests/baselines/reference/nodeModulesImportAssertions(module=node16).errors.txt index 5730914f8677d..aa5cae15aeee3 100644 --- a/tests/baselines/reference/nodeModulesImportAssertions(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesImportAssertions(module=node16).errors.txt @@ -1,19 +1,16 @@ tests/cases/conformance/node/index.ts(1,35): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. tests/cases/conformance/node/otherc.cts(1,35): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -tests/cases/conformance/node/otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'. ==== tests/cases/conformance/node/index.ts (1 errors) ==== import json from "./package.json" assert { type: "json" }; ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. -==== tests/cases/conformance/node/otherc.cts (2 errors) ==== +==== tests/cases/conformance/node/otherc.cts (1 errors) ==== import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'. ==== tests/cases/conformance/node/package.json (0 errors) ==== { "name": "pkg", From 2acf3a3652fb14e484fc208c803f9d5d4a973f2c Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 22 Sep 2022 14:26:37 -0700 Subject: [PATCH 5/8] Cherry-pick PR #50691 into release-4.8 (#50743) Component commits: 364495996f Add test case 17f6e5723f Revert removal of nonInferrableAnyType cafebeeeb5 Rename test Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- src/compiler/checker.ts | 12 ++- ...nferStringLiteralUnionForBindingElement.js | 41 +++++++++ ...tringLiteralUnionForBindingElement.symbols | 73 +++++++++++++++ ...rStringLiteralUnionForBindingElement.types | 89 +++++++++++++++++++ ...nferStringLiteralUnionForBindingElement.ts | 21 +++++ 5 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/inferStringLiteralUnionForBindingElement.js create mode 100644 tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols create mode 100644 tests/baselines/reference/inferStringLiteralUnionForBindingElement.types create mode 100644 tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c8a6ce2a9b121..812d2d0289576 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -789,6 +789,7 @@ namespace ts { const wildcardType = createIntrinsicType(TypeFlags.Any, "any"); const errorType = createIntrinsicType(TypeFlags.Any, "error"); const unresolvedType = createIntrinsicType(TypeFlags.Any, "unresolved"); + const nonInferrableAnyType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.ContainsWideningType); const intrinsicMarkerType = createIntrinsicType(TypeFlags.Any, "intrinsic"); const unknownType = createIntrinsicType(TypeFlags.Unknown, "unknown"); const nonNullUnknownType = createIntrinsicType(TypeFlags.Unknown, "unknown"); @@ -9540,7 +9541,11 @@ namespace ts { if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern @@ -22598,7 +22603,10 @@ namespace ts { // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (getObjectFlags(source) & ObjectFlags.NonInferrableType) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (getObjectFlags(source) & ObjectFlags.NonInferrableType || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { diff --git a/tests/baselines/reference/inferStringLiteralUnionForBindingElement.js b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.js new file mode 100644 index 0000000000000..e5c5527287a16 --- /dev/null +++ b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.js @@ -0,0 +1,41 @@ +//// [inferStringLiteralUnionForBindingElement.ts] +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; + +function func1() { + const { firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + + const { keys } = func({keys: ["aa", "bb"]}) + const b: ("aa" | "bb")[] = keys; +} + +function func2() { + const { keys, firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + const b: ("aa" | "bb")[] = keys; +} + +function func3() { + const x = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = x.firstKey; + const b: ("aa" | "bb")[] = x.keys; +} + + +//// [inferStringLiteralUnionForBindingElement.js] +function func1() { + var firstKey = func({ keys: ["aa", "bb"] }).firstKey; + var a = firstKey; + var keys = func({ keys: ["aa", "bb"] }).keys; + var b = keys; +} +function func2() { + var _a = func({ keys: ["aa", "bb"] }), keys = _a.keys, firstKey = _a.firstKey; + var a = firstKey; + var b = keys; +} +function func3() { + var x = func({ keys: ["aa", "bb"] }); + var a = x.firstKey; + var b = x.keys; +} diff --git a/tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols new file mode 100644 index 0000000000000..1b19c0132ce79 --- /dev/null +++ b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts === +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) +>arg : Symbol(arg, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 40)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 46)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 62)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 82)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) + +function func1() { +>func1 : Symbol(func1, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 107)) + + const { firstKey } = func({keys: ["aa", "bb"]}) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 3, 11)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 3, 31)) + + const a: "aa" | "bb" = firstKey; +>a : Symbol(a, Decl(inferStringLiteralUnionForBindingElement.ts, 4, 9)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 3, 11)) + + const { keys } = func({keys: ["aa", "bb"]}) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 6, 11)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 6, 27)) + + const b: ("aa" | "bb")[] = keys; +>b : Symbol(b, Decl(inferStringLiteralUnionForBindingElement.ts, 7, 9)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 6, 11)) +} + +function func2() { +>func2 : Symbol(func2, Decl(inferStringLiteralUnionForBindingElement.ts, 8, 1)) + + const { keys, firstKey } = func({keys: ["aa", "bb"]}) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 11)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 17)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 37)) + + const a: "aa" | "bb" = firstKey; +>a : Symbol(a, Decl(inferStringLiteralUnionForBindingElement.ts, 12, 9)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 17)) + + const b: ("aa" | "bb")[] = keys; +>b : Symbol(b, Decl(inferStringLiteralUnionForBindingElement.ts, 13, 9)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 11)) +} + +function func3() { +>func3 : Symbol(func3, Decl(inferStringLiteralUnionForBindingElement.ts, 14, 1)) + + const x = func({keys: ["aa", "bb"]}) +>x : Symbol(x, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 9)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 20)) + + const a: "aa" | "bb" = x.firstKey; +>a : Symbol(a, Decl(inferStringLiteralUnionForBindingElement.ts, 18, 9)) +>x.firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 82)) +>x : Symbol(x, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 9)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 82)) + + const b: ("aa" | "bb")[] = x.keys; +>b : Symbol(b, Decl(inferStringLiteralUnionForBindingElement.ts, 19, 9)) +>x.keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 62)) +>x : Symbol(x, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 9)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 62)) +} + diff --git a/tests/baselines/reference/inferStringLiteralUnionForBindingElement.types b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.types new file mode 100644 index 0000000000000..0d3cf898877f1 --- /dev/null +++ b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.types @@ -0,0 +1,89 @@ +=== tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts === +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; +>func : (arg: { keys: T[];}) => { readonly keys: T[]; readonly firstKey: T;} +>arg : { keys: T[]; } +>keys : T[] +>keys : T[] +>firstKey : T + +function func1() { +>func1 : () => void + + const { firstKey } = func({keys: ["aa", "bb"]}) +>firstKey : "aa" | "bb" +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] +>"aa" : "aa" +>"bb" : "bb" + + const a: "aa" | "bb" = firstKey; +>a : "aa" | "bb" +>firstKey : "aa" | "bb" + + const { keys } = func({keys: ["aa", "bb"]}) +>keys : ("aa" | "bb")[] +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] +>"aa" : "aa" +>"bb" : "bb" + + const b: ("aa" | "bb")[] = keys; +>b : ("aa" | "bb")[] +>keys : ("aa" | "bb")[] +} + +function func2() { +>func2 : () => void + + const { keys, firstKey } = func({keys: ["aa", "bb"]}) +>keys : ("aa" | "bb")[] +>firstKey : "aa" | "bb" +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] +>"aa" : "aa" +>"bb" : "bb" + + const a: "aa" | "bb" = firstKey; +>a : "aa" | "bb" +>firstKey : "aa" | "bb" + + const b: ("aa" | "bb")[] = keys; +>b : ("aa" | "bb")[] +>keys : ("aa" | "bb")[] +} + +function func3() { +>func3 : () => void + + const x = func({keys: ["aa", "bb"]}) +>x : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] +>"aa" : "aa" +>"bb" : "bb" + + const a: "aa" | "bb" = x.firstKey; +>a : "aa" | "bb" +>x.firstKey : "aa" | "bb" +>x : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>firstKey : "aa" | "bb" + + const b: ("aa" | "bb")[] = x.keys; +>b : ("aa" | "bb")[] +>x.keys : ("aa" | "bb")[] +>x : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>keys : ("aa" | "bb")[] +} + diff --git a/tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts b/tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts new file mode 100644 index 0000000000000..0b8727ea5a0ce --- /dev/null +++ b/tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts @@ -0,0 +1,21 @@ +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; + +function func1() { + const { firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + + const { keys } = func({keys: ["aa", "bb"]}) + const b: ("aa" | "bb")[] = keys; +} + +function func2() { + const { keys, firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + const b: ("aa" | "bb")[] = keys; +} + +function func3() { + const x = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = x.firstKey; + const b: ("aa" | "bb")[] = x.keys; +} From 41e1ade33a2e602f3ffd9bf70e9938336980ad45 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 22 Sep 2022 14:27:38 -0700 Subject: [PATCH 6/8] Cherry-pick PR #50704 into release-4.8 (#50741) Component commits: 014fc0e1eb Preserve special intersections in mapped types 5907d7cd07 Add regression test Co-authored-by: Anders Hejlsberg --- src/compiler/checker.ts | 6 +++ ...ecialIntersectionsInMappedTypes.errors.txt | 21 +++++++++ .../specialIntersectionsInMappedTypes.js | 28 ++++++++++++ .../specialIntersectionsInMappedTypes.symbols | 41 +++++++++++++++++ .../specialIntersectionsInMappedTypes.types | 45 +++++++++++++++++++ .../specialIntersectionsInMappedTypes.ts | 17 +++++++ 6 files changed, 158 insertions(+) create mode 100644 tests/baselines/reference/specialIntersectionsInMappedTypes.errors.txt create mode 100644 tests/baselines/reference/specialIntersectionsInMappedTypes.js create mode 100644 tests/baselines/reference/specialIntersectionsInMappedTypes.symbols create mode 100644 tests/baselines/reference/specialIntersectionsInMappedTypes.types create mode 100644 tests/cases/compiler/specialIntersectionsInMappedTypes.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 812d2d0289576..2e6533061aedc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11765,6 +11765,12 @@ namespace ts { return mapType(type as UnionType, getLowerBoundOfKeyType); } if (type.flags & TypeFlags.Intersection) { + // Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {}, + // and bigint & {} intersections that are used to prevent subtype reduction in union types. + const types = (type as IntersectionType).types; + if (types.length === 2 && !!(types[0].flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(sameMap((type as UnionType).types, getLowerBoundOfKeyType)); } return type; diff --git a/tests/baselines/reference/specialIntersectionsInMappedTypes.errors.txt b/tests/baselines/reference/specialIntersectionsInMappedTypes.errors.txt new file mode 100644 index 0000000000000..31c9404989468 --- /dev/null +++ b/tests/baselines/reference/specialIntersectionsInMappedTypes.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/specialIntersectionsInMappedTypes.ts(14,1): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/compiler/specialIntersectionsInMappedTypes.ts (1 errors) ==== + // Repro from #50683 + + type Alignment = (string & {}) | "left" | "center" | "right"; + type Alignments = Record; + + const a: Alignments = { + left: "align-left", + center: "align-center", + right: "align-right", + other: "align-other", + }; + + a.left.length; + a.other.length; // Error expected here + ~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + \ No newline at end of file diff --git a/tests/baselines/reference/specialIntersectionsInMappedTypes.js b/tests/baselines/reference/specialIntersectionsInMappedTypes.js new file mode 100644 index 0000000000000..d06d8cb64b54b --- /dev/null +++ b/tests/baselines/reference/specialIntersectionsInMappedTypes.js @@ -0,0 +1,28 @@ +//// [specialIntersectionsInMappedTypes.ts] +// Repro from #50683 + +type Alignment = (string & {}) | "left" | "center" | "right"; +type Alignments = Record; + +const a: Alignments = { + left: "align-left", + center: "align-center", + right: "align-right", + other: "align-other", +}; + +a.left.length; +a.other.length; // Error expected here + + +//// [specialIntersectionsInMappedTypes.js] +"use strict"; +// Repro from #50683 +var a = { + left: "align-left", + center: "align-center", + right: "align-right", + other: "align-other" +}; +a.left.length; +a.other.length; // Error expected here diff --git a/tests/baselines/reference/specialIntersectionsInMappedTypes.symbols b/tests/baselines/reference/specialIntersectionsInMappedTypes.symbols new file mode 100644 index 0000000000000..d7ba7d4df4c05 --- /dev/null +++ b/tests/baselines/reference/specialIntersectionsInMappedTypes.symbols @@ -0,0 +1,41 @@ +=== tests/cases/compiler/specialIntersectionsInMappedTypes.ts === +// Repro from #50683 + +type Alignment = (string & {}) | "left" | "center" | "right"; +>Alignment : Symbol(Alignment, Decl(specialIntersectionsInMappedTypes.ts, 0, 0)) + +type Alignments = Record; +>Alignments : Symbol(Alignments, Decl(specialIntersectionsInMappedTypes.ts, 2, 61)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>Alignment : Symbol(Alignment, Decl(specialIntersectionsInMappedTypes.ts, 0, 0)) + +const a: Alignments = { +>a : Symbol(a, Decl(specialIntersectionsInMappedTypes.ts, 5, 5)) +>Alignments : Symbol(Alignments, Decl(specialIntersectionsInMappedTypes.ts, 2, 61)) + + left: "align-left", +>left : Symbol(left, Decl(specialIntersectionsInMappedTypes.ts, 5, 23)) + + center: "align-center", +>center : Symbol(center, Decl(specialIntersectionsInMappedTypes.ts, 6, 23)) + + right: "align-right", +>right : Symbol(right, Decl(specialIntersectionsInMappedTypes.ts, 7, 27)) + + other: "align-other", +>other : Symbol(other, Decl(specialIntersectionsInMappedTypes.ts, 8, 25)) + +}; + +a.left.length; +>a.left.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>a.left : Symbol(left) +>a : Symbol(a, Decl(specialIntersectionsInMappedTypes.ts, 5, 5)) +>left : Symbol(left) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + +a.other.length; // Error expected here +>a.other.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(specialIntersectionsInMappedTypes.ts, 5, 5)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/specialIntersectionsInMappedTypes.types b/tests/baselines/reference/specialIntersectionsInMappedTypes.types new file mode 100644 index 0000000000000..7fda315f8a3ca --- /dev/null +++ b/tests/baselines/reference/specialIntersectionsInMappedTypes.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/specialIntersectionsInMappedTypes.ts === +// Repro from #50683 + +type Alignment = (string & {}) | "left" | "center" | "right"; +>Alignment : (string & {}) | "left" | "center" | "right" + +type Alignments = Record; +>Alignments : { [x: string & {}]: string; left: string; center: string; right: string; } + +const a: Alignments = { +>a : Alignments +>{ left: "align-left", center: "align-center", right: "align-right", other: "align-other",} : { left: string; center: string; right: string; other: string; } + + left: "align-left", +>left : string +>"align-left" : "align-left" + + center: "align-center", +>center : string +>"align-center" : "align-center" + + right: "align-right", +>right : string +>"align-right" : "align-right" + + other: "align-other", +>other : string +>"align-other" : "align-other" + +}; + +a.left.length; +>a.left.length : number +>a.left : string +>a : Alignments +>left : string +>length : number + +a.other.length; // Error expected here +>a.other.length : number +>a.other : string | undefined +>a : Alignments +>other : string | undefined +>length : number + diff --git a/tests/cases/compiler/specialIntersectionsInMappedTypes.ts b/tests/cases/compiler/specialIntersectionsInMappedTypes.ts new file mode 100644 index 0000000000000..9341a0f3ae98a --- /dev/null +++ b/tests/cases/compiler/specialIntersectionsInMappedTypes.ts @@ -0,0 +1,17 @@ +// @strict: true +// @noUncheckedIndexedAccess: true + +// Repro from #50683 + +type Alignment = (string & {}) | "left" | "center" | "right"; +type Alignments = Record; + +const a: Alignments = { + left: "align-left", + center: "align-center", + right: "align-right", + other: "align-other", +}; + +a.left.length; +a.other.length; // Error expected here From 369b4d8299b051d71a3cacdb4a0b7bd9ff900e44 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 22 Sep 2022 15:00:51 -0700 Subject: [PATCH 7/8] Cherry pick #50537 and #50779 to release-4.8 (#50907) * Retain name and propertyName in declaration emit copies of binding patterns if property name is a keyword (#50537) * Retain name and propertyName in declaration emit copies of binding patterns if property name is a keyword * Accept baselines * Remove out of date file * Partially revert #41044, restoring parameter destructurings in d.ts files (#50779) * Update baselines Co-authored-by: Wesley Wigham --- src/compiler/checker.ts | 28 +++---- ...uallyTypedBindingInitializerNegative.types | 4 +- ...ationEmitBindingPatternWithReservedWord.js | 48 ++++++++++++ ...EmitBindingPatternWithReservedWord.symbols | 78 +++++++++++++++++++ ...onEmitBindingPatternWithReservedWord.types | 52 +++++++++++++ .../declarationEmitBindingPatterns.js | 2 +- .../declarationEmitBindingPatterns.types | 4 +- ...tionEmitDuplicateParameterDestructuring.js | 17 ++++ ...mitDuplicateParameterDestructuring.symbols | 22 ++++++ ...nEmitDuplicateParameterDestructuring.types | 26 +++++++ .../declarationsAndAssignments.types | 8 +- .../destructuringInFunctionType.types | 2 +- ...estructuringParameterDeclaration1ES5.types | 2 +- ...ringParameterDeclaration1ES5iterable.types | 2 +- ...estructuringParameterDeclaration1ES6.types | 2 +- .../destructuringParameterDeclaration6.types | 12 +-- .../excessPropertyCheckWithSpread.types | 6 +- .../reference/objectRestParameter.types | 2 +- .../reference/objectRestParameterES5.types | 2 +- ...amingDestructuredPropertyInFunctionType.js | 14 ++-- ...ngDestructuredPropertyInFunctionType.types | 68 ++++++++-------- ...gDestructuredPropertyInFunctionType2.types | 30 +++---- ...gParameterNestedObjectBindingPattern.types | 12 +-- ...tedObjectBindingPatternDefaultValues.types | 12 +-- ...cturingParameterObjectBindingPattern.types | 12 +-- ...terObjectBindingPatternDefaultValues.types | 12 +-- ...eticDefaultExportsWithDynamicImports.types | 2 +- ...xStatelessFunctionComponentOverload1.types | 18 ++--- ...ationEmitBindingPatternWithReservedWord.ts | 23 ++++++ ...tionEmitDuplicateParameterDestructuring.ts | 6 ++ 30 files changed, 395 insertions(+), 133 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.js create mode 100644 tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.symbols create mode 100644 tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.types create mode 100644 tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.js create mode 100644 tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.symbols create mode 100644 tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.types create mode 100644 tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts create mode 100644 tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2e6533061aedc..8381f6898077f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6094,29 +6094,19 @@ namespace ts { return parameterNode; function cloneBindingName(node: BindingName): BindingName { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName; - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node { + return elideInitializerAndSetEmitFlags(node) as BindingName; + function elideInitializerAndSetEmitFlags(node: Node): Node { if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!; + let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!; if (isBindingElement(visited)) { - if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) { - visited = factory.updateBindingElement( - visited, - visited.dotDotDotToken, - /* propertyName*/ undefined, - visited.propertyName, - /*initializer*/ undefined); - } - else { - visited = factory.updateBindingElement( - visited, - visited.dotDotDotToken, - visited.propertyName, - visited.name, - /*initializer*/ undefined); - } + visited = factory.updateBindingElement( + visited, + visited.dotDotDotToken, + visited.propertyName, + visited.name, + /*initializer*/ undefined); } if (!nodeIsSynthesized(visited)) { visited = factory.cloneNode(visited); diff --git a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types index 6d64e3b7675cf..56ad56f21e577 100644 --- a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types +++ b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types @@ -5,7 +5,7 @@ interface Show { >x : number } function f({ show: showRename = v => v }: Show) {} ->f : ({ show }: Show) => void +>f : ({ show: showRename }: Show) => void >show : any >showRename : (x: number) => string >v => v : (v: number) => number @@ -32,7 +32,7 @@ interface Nested { >nested : Show } function ff({ nested: nestedRename = { show: v => v } }: Nested) {} ->ff : ({ nested }: Nested) => void +>ff : ({ nested: nestedRename }: Nested) => void >nested : any >nestedRename : Show >{ show: v => v } : { show: (v: number) => number; } diff --git a/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.js b/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.js new file mode 100644 index 0000000000000..7468edda28bcc --- /dev/null +++ b/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.js @@ -0,0 +1,48 @@ +//// [declarationEmitBindingPatternWithReservedWord.ts] +type LocaleData = Record +type ConvertLocaleConfig = Record< + string, + T +>; +type LocaleConfig = Record>; + +export interface GetLocalesOptions { + app: unknown; + default: ConvertLocaleConfig; + config?: LocaleConfig | undefined; + name?: string; +} + +export const getLocales = ({ + app, + name, + default: defaultLocalesConfig, + config: userLocalesConfig = {}, +}: GetLocalesOptions): ConvertLocaleConfig => { + return defaultLocalesConfig; +}; + + +//// [declarationEmitBindingPatternWithReservedWord.js] +"use strict"; +exports.__esModule = true; +exports.getLocales = void 0; +var getLocales = function (_a) { + var app = _a.app, name = _a.name, defaultLocalesConfig = _a["default"], _b = _a.config, userLocalesConfig = _b === void 0 ? {} : _b; + return defaultLocalesConfig; +}; +exports.getLocales = getLocales; + + +//// [declarationEmitBindingPatternWithReservedWord.d.ts] +declare type LocaleData = Record; +declare type ConvertLocaleConfig = Record; +declare type LocaleConfig = Record>; +export interface GetLocalesOptions { + app: unknown; + default: ConvertLocaleConfig; + config?: LocaleConfig | undefined; + name?: string; +} +export declare const getLocales: ({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions) => ConvertLocaleConfig; +export {}; diff --git a/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.symbols b/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.symbols new file mode 100644 index 0000000000000..fd535c190dbc1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.symbols @@ -0,0 +1,78 @@ +=== tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts === +type LocaleData = Record +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + +type ConvertLocaleConfig = Record< +>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 1, 25)) +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + string, + T +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 1, 25)) + +>; +type LocaleConfig = Record>; +>LocaleConfig : Symbol(LocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 4, 2)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 18)) +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 18)) + +export interface GetLocalesOptions { +>GetLocalesOptions : Symbol(GetLocalesOptions, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 82)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35)) +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) + + app: unknown; +>app : Symbol(GetLocalesOptions.app, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 58)) + + default: ConvertLocaleConfig; +>default : Symbol(GetLocalesOptions.default, Decl(declarationEmitBindingPatternWithReservedWord.ts, 8, 17)) +>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35)) + + config?: LocaleConfig | undefined; +>config : Symbol(GetLocalesOptions.config, Decl(declarationEmitBindingPatternWithReservedWord.ts, 9, 36)) +>LocaleConfig : Symbol(LocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 4, 2)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35)) + + name?: string; +>name : Symbol(GetLocalesOptions.name, Decl(declarationEmitBindingPatternWithReservedWord.ts, 10, 41)) +} + +export const getLocales = ({ +>getLocales : Symbol(getLocales, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 12)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27)) +>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0)) + + app, +>app : Symbol(app, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 50)) + + name, +>name : Symbol(name, Decl(declarationEmitBindingPatternWithReservedWord.ts, 15, 8)) + + default: defaultLocalesConfig, +>default : Symbol(GetLocalesOptions.default, Decl(declarationEmitBindingPatternWithReservedWord.ts, 8, 17)) +>defaultLocalesConfig : Symbol(defaultLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 16, 9)) + + config: userLocalesConfig = {}, +>config : Symbol(GetLocalesOptions.config, Decl(declarationEmitBindingPatternWithReservedWord.ts, 9, 36)) +>userLocalesConfig : Symbol(userLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 17, 34)) + +}: GetLocalesOptions): ConvertLocaleConfig => { +>GetLocalesOptions : Symbol(GetLocalesOptions, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 82)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27)) +>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39)) +>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27)) + + return defaultLocalesConfig; +>defaultLocalesConfig : Symbol(defaultLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 16, 9)) + +}; + diff --git a/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.types b/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.types new file mode 100644 index 0000000000000..cdd4142570c81 --- /dev/null +++ b/tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.types @@ -0,0 +1,52 @@ +=== tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts === +type LocaleData = Record +>LocaleData : { [x: string]: never; } + +type ConvertLocaleConfig = Record< +>ConvertLocaleConfig : ConvertLocaleConfig + + string, + T +>; +type LocaleConfig = Record>; +>LocaleConfig : LocaleConfig + +export interface GetLocalesOptions { + app: unknown; +>app : unknown + + default: ConvertLocaleConfig; +>default : ConvertLocaleConfig + + config?: LocaleConfig | undefined; +>config : LocaleConfig + + name?: string; +>name : string +} + +export const getLocales = ({ +>getLocales : ({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions) => ConvertLocaleConfig +>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig = {},}: GetLocalesOptions): ConvertLocaleConfig => { return defaultLocalesConfig;} : ({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions) => ConvertLocaleConfig + + app, +>app : unknown + + name, +>name : string + + default: defaultLocalesConfig, +>default : any +>defaultLocalesConfig : ConvertLocaleConfig + + config: userLocalesConfig = {}, +>config : any +>userLocalesConfig : LocaleConfig +>{} : {} + +}: GetLocalesOptions): ConvertLocaleConfig => { + return defaultLocalesConfig; +>defaultLocalesConfig : ConvertLocaleConfig + +}; + diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.js b/tests/baselines/reference/declarationEmitBindingPatterns.js index 31114071a291e..5581c06ebe67f 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.js +++ b/tests/baselines/reference/declarationEmitBindingPatterns.js @@ -18,7 +18,7 @@ function f(_a, _b, _c) { //// [declarationEmitBindingPatterns.d.ts] -declare const k: ({ x }: { +declare const k: ({ x: z }: { x?: string; }) => void; declare var a: any; diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.types b/tests/baselines/reference/declarationEmitBindingPatterns.types index 151991e3039fb..d49893dad94fa 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.types +++ b/tests/baselines/reference/declarationEmitBindingPatterns.types @@ -1,7 +1,7 @@ === tests/cases/compiler/declarationEmitBindingPatterns.ts === const k = ({x: z = 'y'}) => { } ->k : ({ x }: { x?: string; }) => void ->({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void +>k : ({ x: z }: { x?: string; }) => void +>({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void >x : any >z : string >'y' : "y" diff --git a/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.js b/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.js new file mode 100644 index 0000000000000..7e1373045ff95 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.js @@ -0,0 +1,17 @@ +//// [declarationEmitDuplicateParameterDestructuring.ts] +export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b; + +export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b; + + + + +//// [declarationEmitDuplicateParameterDestructuring.d.ts] +export declare const fn1: ({ prop: a, prop: b }: { + prop: number; +}) => number; +export declare const fn2: ({ prop: a }: { + prop: number; +}, { prop: b }: { + prop: number; +}) => number; diff --git a/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.symbols b/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.symbols new file mode 100644 index 0000000000000..ed7d395d452ca --- /dev/null +++ b/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts === +export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b; +>fn1 : Symbol(fn1, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 12)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43)) +>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43)) +>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43)) +>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21)) +>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30)) + +export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b; +>fn2 : Symbol(fn2, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 12)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34)) +>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65)) +>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52)) +>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65)) +>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21)) +>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52)) + diff --git a/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.types b/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.types new file mode 100644 index 0000000000000..bed8aab73cf2d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDuplicateParameterDestructuring.types @@ -0,0 +1,26 @@ +=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts === +export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b; +>fn1 : ({ prop: a, prop: b }: { prop: number;}) => number +>({ prop: a, prop: b }: { prop: number }) => a + b : ({ prop: a, prop: b }: { prop: number;}) => number +>prop : any +>a : number +>prop : any +>b : number +>prop : number +>a + b : number +>a : number +>b : number + +export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b; +>fn2 : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number +>({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number +>prop : any +>a : number +>prop : number +>prop : any +>b : number +>prop : number +>a + b : number +>a : number +>b : number + diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index a3caaa9f6bd84..a7b72a6809424 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -417,7 +417,7 @@ function f13() { } function f14([a = 1, [b = "hello", { x, y: c = false }]]) { ->f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void >a : number >1 : 1 >b : string @@ -438,7 +438,7 @@ function f14([a = 1, [b = "hello", { x, y: c = false }]]) { } f14([2, ["abc", { x: 0, y: true }]]); >f14([2, ["abc", { x: 0, y: true }]]) : void ->f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void >[2, ["abc", { x: 0, y: true }]] : [number, [string, { x: number; y: true; }]] >2 : 2 >["abc", { x: 0, y: true }] : [string, { x: number; y: true; }] @@ -451,7 +451,7 @@ f14([2, ["abc", { x: 0, y: true }]]); f14([2, ["abc", { x: 0 }]]); >f14([2, ["abc", { x: 0 }]]) : void ->f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void >[2, ["abc", { x: 0 }]] : [number, [string, { x: number; }]] >2 : 2 >["abc", { x: 0 }] : [string, { x: number; }] @@ -462,7 +462,7 @@ f14([2, ["abc", { x: 0 }]]); f14([2, ["abc", { y: false }]]); // Error, no x >f14([2, ["abc", { y: false }]]) : void ->f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void >[2, ["abc", { y: false }]] : [number, [string, { y: false; }]] >2 : 2 >["abc", { y: false }] : [string, { y: false; }] diff --git a/tests/baselines/reference/destructuringInFunctionType.types b/tests/baselines/reference/destructuringInFunctionType.types index 553fdaa9cf3b0..2b7f0de66ccf7 100644 --- a/tests/baselines/reference/destructuringInFunctionType.types +++ b/tests/baselines/reference/destructuringInFunctionType.types @@ -31,7 +31,7 @@ type T3 = ([{ a: b }, { b: a }]); >b : a type F3 = ([{ a: b }, { b: a }]) => void; ->F3 : ([{ a }, { b }]: [{ a: any; }, { b: any; }]) => void +>F3 : ([{ a: b }, { b: a }]: [{ a: any; }, { b: any; }]) => void >a : any >b : any >b : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types index 381c486a5461d..cea8e2a231b2c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types @@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer // Type annotations must instead be written on the top- level parameter declaration function e1({x: number}) { } // x has type any NOT number ->e1 : ({ x }: { x: any; }) => void +>e1 : ({ x: number }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types index aec020bcc2870..4fee7254d2bfa 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types @@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer // Type annotations must instead be written on the top- level parameter declaration function e1({x: number}) { } // x has type any NOT number ->e1 : ({ x }: { x: any; }) => void +>e1 : ({ x: number }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index acf5dcffb5ce2..cee129da47534 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -376,7 +376,7 @@ d5(); // Parameter is optional as its declaration included an initializer // Type annotations must instead be written on the top- level parameter declaration function e1({x: number}) { } // x has type any NOT number ->e1 : ({ x }: { x: any; }) => void +>e1 : ({ x: number }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration6.types b/tests/baselines/reference/destructuringParameterDeclaration6.types index 6b5085d21219c..d135f9cb8fdbf 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration6.types @@ -7,7 +7,7 @@ // Error function a({while}) { } ->a : ({ while }: { while: any; }) => void +>a : ({ while: }: { while: any; }) => void >while : any > : any @@ -42,32 +42,32 @@ function a7(...a: string) { } a({ while: 1 }); >a({ while: 1 }) : void ->a : ({ while }: { while: any; }) => void +>a : ({ while: }: { while: any; }) => void >{ while: 1 } : { while: number; } >while : number >1 : 1 // No Error function b1({public: x}) { } ->b1 : ({ public }: { public: any; }) => void +>b1 : ({ public: x }: { public: any; }) => void >public : any >x : any function b2({while: y}) { } ->b2 : ({ while }: { while: any; }) => void +>b2 : ({ while: y }: { while: any; }) => void >while : any >y : any b1({ public: 1 }); >b1({ public: 1 }) : void ->b1 : ({ public }: { public: any; }) => void +>b1 : ({ public: x }: { public: any; }) => void >{ public: 1 } : { public: number; } >public : number >1 : 1 b2({ while: 1 }); >b2({ while: 1 }) : void ->b2 : ({ while }: { while: any; }) => void +>b2 : ({ while: y }: { while: any; }) => void >{ while: 1 } : { while: number; } >while : number >1 : 1 diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.types b/tests/baselines/reference/excessPropertyCheckWithSpread.types index de5385d0b33e0..460f43d2289f4 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.types +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.types @@ -1,6 +1,6 @@ === tests/cases/compiler/excessPropertyCheckWithSpread.ts === declare function f({ a: number }): void ->f : ({ a }: { a: any; }) => void +>f : ({ a: number }: { a: any; }) => void >a : any >number : any @@ -13,7 +13,7 @@ declare let i: I; f({ a: 1, ...i }); >f({ a: 1, ...i }) : void ->f : ({ a }: { a: any; }) => void +>f : ({ a: number }: { a: any; }) => void >{ a: 1, ...i } : { n: number; a: number; } >a : number >1 : 1 @@ -35,7 +35,7 @@ declare let r: R; f({ a: 1, ...l, ...r }); >f({ a: 1, ...l, ...r }) : void ->f : ({ a }: { a: any; }) => void +>f : ({ a: number }: { a: any; }) => void >{ a: 1, ...l, ...r } : { opt: string | number; a: number; } >a : number >1 : 1 diff --git a/tests/baselines/reference/objectRestParameter.types b/tests/baselines/reference/objectRestParameter.types index 668214c495f1f..71047deea43fe 100644 --- a/tests/baselines/reference/objectRestParameter.types +++ b/tests/baselines/reference/objectRestParameter.types @@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void); suddenly(({ x: a, ...rest }) => rest.y); >suddenly(({ x: a, ...rest }) => rest.y) : any >suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any ->({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string +>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string >x : any >a : { z: any; ka: any; } >rest : { y: string; } diff --git a/tests/baselines/reference/objectRestParameterES5.types b/tests/baselines/reference/objectRestParameterES5.types index d88da6a249433..74df68093aa45 100644 --- a/tests/baselines/reference/objectRestParameterES5.types +++ b/tests/baselines/reference/objectRestParameterES5.types @@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void); suddenly(({ x: a, ...rest }) => rest.y); >suddenly(({ x: a, ...rest }) => rest.y) : any >suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any ->({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string +>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string >x : any >a : { z: any; ka: any; } >rest : { y: string; } diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index ac5fe3b3c35e0..e60b438624276 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -167,18 +167,18 @@ interface I { }): any; } declare function f1({ a }: O): void; -declare const f2: ({ a }: O) => void; -declare const f3: ({ a, b, c }: O) => void; -declare const f4: ({ a }: O) => string; -declare const f5: ({ a, b, c }: O) => string; +declare const f2: ({ a: string }: O) => void; +declare const f3: ({ a: string, b, c }: O) => void; +declare const f4: ({ a: string }: O) => string; +declare const f5: ({ a: string, b, c }: O) => string; declare const obj1: { - method({ a }: O): void; + method({ a: string }: O): void; }; declare const obj2: { - method({ a }: O): string; + method({ a: string }: O): string; }; declare function f6({ a }: O): void; -declare const f7: ({ a, b, c }: O) => void; +declare const f7: ({ a: string, b, c }: O) => void; declare const f8: ({ "a": string }: O) => void; declare function f9({ 2: string }: { 2: any; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 9fc0a27a46282..1dbe128487cb9 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -12,37 +12,37 @@ type F1 = (arg: number) => any; // OK >arg : number type F2 = ({ a: string }: O) => any; // Error ->F2 : ({ a }: O) => any +>F2 : ({ a: string }: O) => any >a : any >string : string type F3 = ({ a: string, b, c }: O) => any; // Error ->F3 : ({ a, b, c }: O) => any +>F3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F4 = ({ a: string }: O) => any; // Error ->F4 : ({ a }: O) => any +>F4 : ({ a: string }: O) => any >a : any >string : string type F5 = ({ a: string, b, c }: O) => any; // Error ->F5 : ({ a, b, c }: O) => any +>F5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F6 = ({ a: string }) => typeof string; // OK ->F6 : ({ a }: { a: any; }) => any +>F6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type F7 = ({ a: string, b: number }) => typeof number; // Error ->F7 : ({ a, b }: { a: any; b: any; }) => any +>F7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -50,7 +50,7 @@ type F7 = ({ a: string, b: number }) => typeof number; // Error >number : any type F8 = ({ a, b: number }) => typeof number; // OK ->F8 : ({ a, b }: { a: any; b: any; }) => any +>F8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -67,37 +67,37 @@ type G1 = new (arg: number) => any; // OK >arg : number type G2 = new ({ a: string }: O) => any; // Error ->G2 : new ({ a }: O) => any +>G2 : new ({ a: string }: O) => any >a : any >string : string type G3 = new ({ a: string, b, c }: O) => any; // Error ->G3 : new ({ a, b, c }: O) => any +>G3 : new ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G4 = new ({ a: string }: O) => any; // Error ->G4 : new ({ a }: O) => any +>G4 : new ({ a: string }: O) => any >a : any >string : string type G5 = new ({ a: string, b, c }: O) => any; // Error ->G5 : new ({ a, b, c }: O) => any +>G5 : new ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G6 = new ({ a: string }) => typeof string; // OK ->G6 : new ({ a }: { a: any; }) => any +>G6 : new ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type G7 = new ({ a: string, b: number }) => typeof number; // Error ->G7 : new ({ a, b }: { a: any; b: any; }) => any +>G7 : new ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -105,7 +105,7 @@ type G7 = new ({ a: string, b: number }) => typeof number; // Error >number : any type G8 = new ({ a, b: number }) => typeof number; // OK ->G8 : new ({ a, b }: { a: any; b: any; }) => any +>G8 : new ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -161,7 +161,7 @@ interface I { >arg : number method2({ a: string }): any; // Error ->method2 : ({ a }: { a: any; }) => any +>method2 : ({ a: string }: { a: any; }) => any >a : any >string : any @@ -182,35 +182,35 @@ interface I { // Below are OK but renaming should be removed from declaration emit function f1({ a: string }: O) { } ->f1 : ({ a }: O) => void +>f1 : ({ a: string }: O) => void >a : any >string : string const f2 = function({ a: string }: O) { }; ->f2 : ({ a }: O) => void ->function({ a: string }: O) { } : ({ a }: O) => void +>f2 : ({ a: string }: O) => void +>function({ a: string }: O) { } : ({ a: string }: O) => void >a : any >string : string const f3 = ({ a: string, b, c }: O) => { }; ->f3 : ({ a, b, c }: O) => void ->({ a: string, b, c }: O) => { } : ({ a, b, c }: O) => void +>f3 : ({ a: string, b, c }: O) => void +>({ a: string, b, c }: O) => { } : ({ a: string, b, c }: O) => void >a : any >string : string >b : number >c : number const f4 = function({ a: string }: O): typeof string { return string; }; ->f4 : ({ a }: O) => string ->function({ a: string }: O): typeof string { return string; } : ({ a }: O) => string +>f4 : ({ a: string }: O) => string +>function({ a: string }: O): typeof string { return string; } : ({ a: string }: O) => string >a : any >string : string >string : string >string : string const f5 = ({ a: string, b, c }: O): typeof string => ''; ->f5 : ({ a, b, c }: O) => string ->({ a: string, b, c }: O): typeof string => '' : ({ a, b, c }: O) => string +>f5 : ({ a: string, b, c }: O) => string +>({ a: string, b, c }: O): typeof string => '' : ({ a: string, b, c }: O) => string >a : any >string : string >b : number @@ -219,21 +219,21 @@ const f5 = ({ a: string, b, c }: O): typeof string => ''; >'' : "" const obj1 = { ->obj1 : { method({ a }: O): void; } ->{ method({ a: string }: O) { }} : { method({ a }: O): void; } +>obj1 : { method({ a: string }: O): void; } +>{ method({ a: string }: O) { }} : { method({ a: string }: O): void; } method({ a: string }: O) { } ->method : ({ a }: O) => void +>method : ({ a: string }: O) => void >a : any >string : string }; const obj2 = { ->obj2 : { method({ a }: O): string; } ->{ method({ a: string }: O): typeof string { return string; }} : { method({ a }: O): string; } +>obj2 : { method({ a: string }: O): string; } +>{ method({ a: string }: O): typeof string { return string; }} : { method({ a: string }: O): string; } method({ a: string }: O): typeof string { return string; } ->method : ({ a }: O) => string +>method : ({ a: string }: O) => string >a : any >string : string >string : string @@ -241,14 +241,14 @@ const obj2 = { }; function f6({ a: string = "" }: O) { } ->f6 : ({ a }: O) => void +>f6 : ({ a: string }: O) => void >a : any >string : string >"" : "" const f7 = ({ a: string = "", b, c }: O) => { }; ->f7 : ({ a, b, c }: O) => void ->({ a: string = "", b, c }: O) => { } : ({ a, b, c }: O) => void +>f7 : ({ a: string, b, c }: O) => void +>({ a: string = "", b, c }: O) => { } : ({ a: string, b, c }: O) => void >a : any >string : string >"" : "" @@ -277,7 +277,7 @@ const f11 = ({ [2]: string }) => { }; // In below case `string` should be kept because it is used function f12({ a: string = "" }: O): typeof string { return "a"; } ->f12 : ({ a }: O) => typeof string +>f12 : ({ a: string }: O) => typeof string >a : any >string : string >"" : "" diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types index 237a2ac364150..615d9de9145c5 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -10,37 +10,37 @@ type F1 = (arg: number) => any; >arg : number type F2 = ({ a: string }: O) => any; ->F2 : ({ a }: O) => any +>F2 : ({ a: string }: O) => any >a : any >string : string type F3 = ({ a: string, b, c }: O) => any; ->F3 : ({ a, b, c }: O) => any +>F3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F4 = ({ a: string }: O) => any; ->F4 : ({ a }: O) => any +>F4 : ({ a: string }: O) => any >a : any >string : string type F5 = ({ a: string, b, c }: O) => any; ->F5 : ({ a, b, c }: O) => any +>F5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F6 = ({ a: string }) => typeof string; ->F6 : ({ a }: { a: any; }) => any +>F6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type F7 = ({ a: string, b: number }) => typeof number; ->F7 : ({ a, b }: { a: any; b: any; }) => any +>F7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -48,7 +48,7 @@ type F7 = ({ a: string, b: number }) => typeof number; >number : any type F8 = ({ a, b: number }) => typeof number; ->F8 : ({ a, b }: { a: any; b: any; }) => any +>F8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -65,37 +65,37 @@ type G1 = (arg: number) => any; >arg : number type G2 = ({ a: string }: O) => any; ->G2 : ({ a }: O) => any +>G2 : ({ a: string }: O) => any >a : any >string : string type G3 = ({ a: string, b, c }: O) => any; ->G3 : ({ a, b, c }: O) => any +>G3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G4 = ({ a: string }: O) => any; ->G4 : ({ a }: O) => any +>G4 : ({ a: string }: O) => any >a : any >string : string type G5 = ({ a: string, b, c }: O) => any; ->G5 : ({ a, b, c }: O) => any +>G5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G6 = ({ a: string }) => typeof string; ->G6 : ({ a }: { a: any; }) => any +>G6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type G7 = ({ a: string, b: number }) => typeof number; ->G7 : ({ a, b }: { a: any; b: any; }) => any +>G7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -103,7 +103,7 @@ type G7 = ({ a: string, b: number }) => typeof number; >number : any type G8 = ({ a, b: number }) => typeof number; ->G8 : ({ a, b }: { a: any; b: any; }) => any +>G8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -121,7 +121,7 @@ interface I { >arg : number method2({ a: string }): any; ->method2 : ({ a }: { a: any; }) => any +>method2 : ({ a: string }: { a: any; }) => any >a : any >string : any diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types index dcabaa3bf785d..287f0c41d2587 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { ->foo1 : ({ skills: { primary, secondary } }: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void >skills : any >primary : any >primaryA : string @@ -49,7 +49,7 @@ function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { >primaryA : string } function foo2({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) { ->foo2 : ({ name, skills: { primary, secondary } }: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void >name : any >nameC : string >skills : any @@ -81,12 +81,12 @@ function foo3({ skills }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary, secondary } }: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary, secondary } }: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -99,12 +99,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skills: { primary, secondary } }: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name, skills: { primary, secondary } }: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types index 9082abff9dfb4..8bfc93c3db70b 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1( ->foo1 : ({ skills: { primary, secondary } }?: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void { skills: { >skills : any @@ -67,7 +67,7 @@ function foo1( >primaryA : string } function foo2( ->foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void { name: nameC = "name", >name : any @@ -126,12 +126,12 @@ function foo3({ skills = { primary: "SomeSkill", secondary: "someSkill" } }: Ro foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary, secondary } }?: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary, secondary } }?: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -144,12 +144,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types index a02d95a9939b9..05a01de79ac9b 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA }: Robot) { ->foo1 : ({ name }: Robot) => void +>foo1 : ({ name: nameA }: Robot) => void >name : any >nameA : string @@ -38,7 +38,7 @@ function foo1({ name: nameA }: Robot) { >nameA : string } function foo2({ name: nameB, skill: skillB }: Robot) { ->foo2 : ({ name, skill }: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }: Robot) => void >name : any >nameB : string >skill : any @@ -65,12 +65,12 @@ function foo3({ name }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name }: Robot) => void +>foo1 : ({ name: nameA }: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name }: Robot) => void +>foo1 : ({ name: nameA }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -79,12 +79,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skill }: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name, skill }: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types index a7493bcd1dcb0..6f1712d272e25 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA = "" }: Robot = { }) { ->foo1 : ({ name }?: Robot) => void +>foo1 : ({ name: nameA }?: Robot) => void >name : any >nameA : string >"" : "" @@ -40,7 +40,7 @@ function foo1({ name: nameA = "" }: Robot = { }) { >nameA : string } function foo2({ name: nameB = "", skill: skillB = "noSkill" }: Robot = {}) { ->foo2 : ({ name, skill }?: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void >name : any >nameB : string >"" : "" @@ -72,12 +72,12 @@ function foo3({ name = "" }: Robot = {}) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name }?: Robot) => void +>foo1 : ({ name: nameA }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name }?: Robot) => void +>foo1 : ({ name: nameA }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -86,12 +86,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skill }?: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name, skill }?: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types index 3dc640792e075..3f1ef83a0ae9c 100644 --- a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types @@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42)); >import("package") : Promise<{ default: (x: number) => string; }> >"package" : "package" >then : string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->({default: foo}) => foo(42) : ({ default }: { default: (x: number) => string; }) => string +>({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string >default : any >foo : (x: number) => string >foo(42) : string diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types index 2d48ccacf899c..d5429be5e488d 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types @@ -75,27 +75,27 @@ const c5 = Hello declare function TestingOneThing({y1: string}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : any >string : any >JSX : any declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >j : { "extra-data": string; yy?: string; } >"extra-data" : string >yy : string >JSX : any declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >n : { yy: number; direction?: number; } >yy : number >direction : number >JSX : any declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } >n : { yy: string; name: string; } >yy : string >name : string @@ -105,27 +105,27 @@ declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; const d1 = ; >d1 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : true >extra-data : true const d2 = ; >d2 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string const d3 = ; >d3 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string const d4 = ; >d4 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : number >9 : 9 @@ -135,7 +135,7 @@ const d4 = ; const d5 = ; >d5 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string >name : string diff --git a/tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts b/tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts new file mode 100644 index 0000000000000..be6fdc13ea0e8 --- /dev/null +++ b/tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts @@ -0,0 +1,23 @@ +// @declaration: true +type LocaleData = Record +type ConvertLocaleConfig = Record< + string, + T +>; +type LocaleConfig = Record>; + +export interface GetLocalesOptions { + app: unknown; + default: ConvertLocaleConfig; + config?: LocaleConfig | undefined; + name?: string; +} + +export const getLocales = ({ + app, + name, + default: defaultLocalesConfig, + config: userLocalesConfig = {}, +}: GetLocalesOptions): ConvertLocaleConfig => { + return defaultLocalesConfig; +}; diff --git a/tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts b/tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts new file mode 100644 index 0000000000000..12f3ce9aa2bc8 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts @@ -0,0 +1,6 @@ +// @declaration: true +// @emitDeclarationOnly: true + +export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b; + +export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b; From a614119c1921ca61d549a7eee65c0b8c69c28752 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 23 Sep 2022 08:11:57 +0000 Subject: [PATCH 8/8] Bump version to 4.8.4 and LKG --- lib/tsc.js | 109 ++++++++++++++++---------------- lib/tsserver.js | 126 ++++++++++++++++++++----------------- lib/tsserverlibrary.js | 126 ++++++++++++++++++++----------------- lib/typescript.js | 124 +++++++++++++++++++----------------- lib/typescriptServices.js | 124 +++++++++++++++++++----------------- lib/typingsInstaller.js | 122 ++++++++++++++++++----------------- package.json | 2 +- src/compiler/corePublic.ts | 2 +- 8 files changed, 388 insertions(+), 347 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index ab79f9e91feec..74c8a3733fa68 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { var ts; (function (ts) { ts.versionMajorMinor = "4.8"; - ts.version = "4.8.3"; + ts.version = "4.8.4"; var NativeCollections; (function (NativeCollections) { var globals = typeof globalThis !== "undefined" ? globalThis : @@ -25457,6 +25457,7 @@ var ts; case 335: case 336: case 331: + case 337: return visitNode(cbNode, node.tagName) || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); case 350: @@ -34938,7 +34939,7 @@ var ts; function withPackageId(packageInfo, r) { var packageId; if (r && packageInfo) { - var packageJsonContent = packageInfo.packageJsonContent; + var packageJsonContent = packageInfo.contents.packageJsonContent; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -36067,13 +36068,13 @@ var ts; function loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson) { if (considerPackageJson === void 0) { considerPackageJson = true; } var packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - var packageJsonContent = packageInfo && packageInfo.packageJsonContent; - var versionPaths = packageInfo && packageInfo.versionPaths; + var packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + var versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { - return packageJsonInfo.resolvedEntrypoints; + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { + return packageJsonInfo.contents.resolvedEntrypoints; } var entrypoints; var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript; @@ -36081,13 +36082,13 @@ var ts; var requireState = getTemporaryModuleResolutionState(cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(), host, options); requireState.conditions = ["node", "require", "types"]; requireState.requestContainingDirectory = packageJsonInfo.packageDirectory; - var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths); + var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, false, requireState, packageJsonInfo.contents.packageJsonContent, packageJsonInfo.contents.versionPaths); entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) { var conditions = _a[_i]; var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions }); - var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions); + var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) { var resolution = exportResolutions_1[_b]; @@ -36096,7 +36097,7 @@ var ts; } } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo; function loadEntrypointsFromExportMap(scope, exports, state, extensions) { @@ -36192,7 +36193,9 @@ var ts; if (traceEnabled) trace(host, ts.Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory: packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) @@ -36208,7 +36211,7 @@ var ts; trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined }; + var result = { packageDirectory: packageDirectory, contents: { packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined } }; (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -36320,17 +36323,16 @@ var ts; } function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) { var _a, _b; - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } var parts = ts.getPathComponents(moduleName); - var nameParts = ts.getPathComponents(scope.packageJsonContent.name); + var nameParts = ts.getPathComponents(scope.contents.packageJsonContent.name); if (!ts.every(nameParts, function (p, i) { return parts[i] === p; })) { return undefined; } @@ -36338,30 +36340,30 @@ var ts; return loadModuleFromExports(scope, extensions, !ts.length(trailingParts) ? "." : ".".concat(ts.directorySeparator).concat(trailingParts.join(ts.directorySeparator)), state, cache, redirectedReference); } function loadModuleFromExports(scope, extensions, subpath, state, cache, redirectedReference) { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { var mainExport = void 0; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (ts.hasProperty(scope.packageJsonContent.exports, ".")) { - mainExport = scope.packageJsonContent.exports["."]; + else if (ts.hasProperty(scope.contents.packageJsonContent.exports, ".")) { + mainExport = scope.contents.packageJsonContent.exports["."]; } if (mainExport) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, false); return loadModuleFromTargetImportOrExport(mainExport, "", false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, false); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, false); if (result) { return result; } @@ -36379,8 +36381,7 @@ var ts; } return toSearchResult(undefined); } - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -36388,13 +36389,13 @@ var ts; } return toSearchResult(undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, true); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, true); if (result) { return result; } @@ -36691,20 +36692,20 @@ var ts; if (fromFile) { return noPackageId(fromFile); } - var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.packageJsonContent, packageInfo.versionPaths); + var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.contents.packageJsonContent, packageInfo.contents.versionPaths); return withPackageId(packageInfo, fromDirectory); } } var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest; var loader = function (extensions, candidate, onlyRecordFailures, state) { var _a; - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return (_a = loadModuleFromExports(packageInfo, extensions, ts.combinePaths(".", rest), state, cache, redirectedReference)) === null || _a === void 0 ? void 0 : _a.value; } var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); + loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.contents.packageJsonContent, packageInfo && packageInfo.contents.versionPaths); if (!pathAndExtension && packageInfo - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { pathAndExtension = loadModuleFromFile(extensions, ts.combinePaths(candidate, "index.js"), onlyRecordFailures, state); } @@ -36713,12 +36714,12 @@ var ts; if (rest !== "") { var packageDirectory = ts.combinePaths(nodeModulesDirectory, packageName); packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, ts.version, rest); + trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, ts.version, rest); } var packageDirectoryExists = nodeModulesDirectoryExists && ts.directoryProbablyExists(packageDirectory, state.host); - var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, undefined, loader, !packageDirectoryExists, state); + var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } @@ -40287,6 +40288,7 @@ var ts; var wildcardType = createIntrinsicType(1, "any"); var errorType = createIntrinsicType(1, "error"); var unresolvedType = createIntrinsicType(1, "unresolved"); + var nonInferrableAnyType = createIntrinsicType(1, "any", 65536); var intrinsicMarkerType = createIntrinsicType(1, "intrinsic"); var unknownType = createIntrinsicType(2, "unknown"); var nonNullUnknownType = createIntrinsicType(2, "unknown"); @@ -42545,7 +42547,7 @@ var ts; if (ext === ".ts" || ext === ".js" || ext === ".tsx" || ext === ".jsx") { var scope = currentSourceFile.packageJsonScope; var targetExt = ext === ".ts" ? ".mts" : ext === ".js" ? ".mjs" : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json")); } @@ -44559,19 +44561,14 @@ var ts; context.approximateLength += ts.symbolName(parameterSymbol).length + 3; return parameterNode; function cloneBindingName(node) { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node); - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) { + return elideInitializerAndSetEmitFlags(node); + function elideInitializerAndSetEmitFlags(node) { if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags); + var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, undefined, elideInitializerAndSetEmitFlags); if (ts.isBindingElement(visited)) { - if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, undefined, visited.propertyName, undefined); - } - else { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, undefined); - } + visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, undefined); } if (!ts.nodeIsSynthesized(visited)) { visited = ts.factory.cloneNode(visited); @@ -47113,7 +47110,7 @@ var ts; if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + return includePatternInType ? nonInferrableAnyType : anyType; } function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) { var members = ts.createSymbolTable(); @@ -48941,6 +48938,10 @@ var ts; return mapType(type, getLowerBoundOfKeyType); } if (type.flags & 2097152) { + var types = type.types; + if (types.length === 2 && !!(types[0].flags & (4 | 8 | 64)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(ts.sameMap(type.types, getLowerBoundOfKeyType)); } return type; @@ -57813,7 +57814,7 @@ var ts; } var inference = getInferenceInfoForType(target); if (inference) { - if (ts.getObjectFlags(source) & 262144) { + if (ts.getObjectFlags(source) & 262144 || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { @@ -68354,7 +68355,7 @@ var ts; checkDecorators(node); } function getEffectiveTypeArgumentAtIndex(node, typeParameters, index) { - if (index < typeParameters.length) { + if (node.typeArguments && index < node.typeArguments.length) { return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; @@ -76001,7 +76002,7 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments); } var nodeArguments = node.arguments; - if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) { + if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext && moduleKind !== ts.ModuleKind.Node16) { checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { var assertionArgument = nodeArguments[1]; @@ -97471,7 +97472,7 @@ var ts; state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; var packageJsonScope = ts.getPackageScopeForPath(fileName, state); - var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; + var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope }; } } @@ -98966,7 +98967,7 @@ var ts; return result; } function getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options) { - var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); + var result = getImpliedNodeFormatForFileWorker(ts.getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); var languageVersion = ts.getEmitScriptTarget(options); var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options); return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) : @@ -102976,7 +102977,7 @@ var ts; var maybeBlockedByTypesVersions = false; var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); + var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.contents.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); var importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) { var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"]; @@ -103308,7 +103309,7 @@ var ts; break; case ts.ModuleKind.CommonJS: if (file.packageJsonScope) { - (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, file.packageJsonScope.packageJsonContent.type ? + (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages(undefined, file.packageJsonScope.contents.packageJsonContent.type ? ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor))); } diff --git a/lib/tsserver.js b/lib/tsserver.js index b696263504d68..33a0f2908cad3 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -109,7 +109,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.3"; + ts.version = "4.8.4"; /* @internal */ var Comparison; (function (Comparison) { @@ -31516,6 +31516,7 @@ var ts; case 335 /* SyntaxKind.JSDocProtectedTag */: case 336 /* SyntaxKind.JSDocReadonlyTag */: case 331 /* SyntaxKind.JSDocDeprecatedTag */: + case 337 /* SyntaxKind.JSDocOverrideTag */: return visitNode(cbNode, node.tagName) || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); case 350 /* SyntaxKind.PartiallyEmittedExpression */: @@ -42804,7 +42805,7 @@ var ts; function withPackageId(packageInfo, r) { var packageId; if (r && packageInfo) { - var packageJsonContent = packageInfo.packageJsonContent; + var packageJsonContent = packageInfo.contents.packageJsonContent; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -44123,16 +44124,16 @@ var ts; function loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson) { if (considerPackageJson === void 0) { considerPackageJson = true; } var packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - var packageJsonContent = packageInfo && packageInfo.packageJsonContent; - var versionPaths = packageInfo && packageInfo.versionPaths; + var packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + var versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } /* @internal */ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } var entrypoints; var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript; @@ -44141,13 +44142,13 @@ var ts; requireState.conditions = ["node", "require", "types"]; requireState.requestContainingDirectory = packageJsonInfo.packageDirectory; var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, - /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths); + /*onlyRecordFailures*/ false, requireState, packageJsonInfo.contents.packageJsonContent, packageJsonInfo.contents.versionPaths); entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) { var conditions = _a[_i]; var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions }); - var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions); + var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) { var resolution = exportResolutions_1[_b]; @@ -44156,7 +44157,7 @@ var ts; } } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo; function loadEntrypointsFromExportMap(scope, exports, state, extensions) { @@ -44260,7 +44261,9 @@ var ts; if (traceEnabled) trace(host, ts.Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory: packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) @@ -44276,7 +44279,7 @@ var ts; trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined }; + var result = { packageDirectory: packageDirectory, contents: { packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined } }; (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -44401,17 +44404,16 @@ var ts; } function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) { var _a, _b; - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } var parts = ts.getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - var nameParts = ts.getPathComponents(scope.packageJsonContent.name); + var nameParts = ts.getPathComponents(scope.contents.packageJsonContent.name); if (!ts.every(nameParts, function (p, i) { return parts[i] === p; })) { return undefined; } @@ -44419,30 +44421,30 @@ var ts; return loadModuleFromExports(scope, extensions, !ts.length(trailingParts) ? "." : ".".concat(ts.directorySeparator).concat(trailingParts.join(ts.directorySeparator)), state, cache, redirectedReference); } function loadModuleFromExports(scope, extensions, subpath, state, cache, redirectedReference) { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { var mainExport = void 0; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (ts.hasProperty(scope.packageJsonContent.exports, ".")) { - mainExport = scope.packageJsonContent.exports["."]; + else if (ts.hasProperty(scope.contents.packageJsonContent.exports, ".")) { + mainExport = scope.contents.packageJsonContent.exports["."]; } if (mainExport) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -44460,8 +44462,7 @@ var ts; } return toSearchResult(/*value*/ undefined); } - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -44469,13 +44470,13 @@ var ts; } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -44820,7 +44821,7 @@ var ts; if (fromFile) { return noPackageId(fromFile); } - var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.packageJsonContent, packageInfo.versionPaths); + var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.contents.packageJsonContent, packageInfo.contents.versionPaths); return withPackageId(packageInfo, fromDirectory); } } @@ -44828,14 +44829,14 @@ var ts; var loader = function (extensions, candidate, onlyRecordFailures, state) { var _a; // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return (_a = loadModuleFromExports(packageInfo, extensions, ts.combinePaths(".", rest), state, cache, redirectedReference)) === null || _a === void 0 ? void 0 : _a.value; } var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); + loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.contents.packageJsonContent, packageInfo && packageInfo.contents.versionPaths); if (!pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -44847,12 +44848,12 @@ var ts; var packageDirectory = ts.combinePaths(nodeModulesDirectory, packageName); // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, ts.version, rest); + trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, ts.version, rest); } var packageDirectoryExists = nodeModulesDirectoryExists && ts.directoryProbablyExists(packageDirectory, state.host); - var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } @@ -49153,6 +49154,7 @@ var ts; var wildcardType = createIntrinsicType(1 /* TypeFlags.Any */, "any"); var errorType = createIntrinsicType(1 /* TypeFlags.Any */, "error"); var unresolvedType = createIntrinsicType(1 /* TypeFlags.Any */, "unresolved"); + var nonInferrableAnyType = createIntrinsicType(1 /* TypeFlags.Any */, "any", 65536 /* ObjectFlags.ContainsWideningType */); var intrinsicMarkerType = createIntrinsicType(1 /* TypeFlags.Any */, "intrinsic"); var unknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); var nonNullUnknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); @@ -51754,7 +51756,7 @@ var ts; if (ext === ".ts" /* Extension.Ts */ || ext === ".js" /* Extension.Js */ || ext === ".tsx" /* Extension.Tsx */ || ext === ".jsx" /* Extension.Jsx */) { var scope = currentSourceFile.packageJsonScope; var targetExt = ext === ".ts" /* Extension.Ts */ ? ".mts" /* Extension.Mts */ : ext === ".js" /* Extension.Js */ ? ".mjs" /* Extension.Mjs */ : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = ts.chainDiagnosticMessages( /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json")); @@ -53982,22 +53984,15 @@ var ts; context.approximateLength += ts.symbolName(parameterSymbol).length + 3; return parameterNode; function cloneBindingName(node) { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node); - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) { + return elideInitializerAndSetEmitFlags(node); + function elideInitializerAndSetEmitFlags(node) { if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags); + var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags); if (ts.isBindingElement(visited)) { - if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, - /* propertyName*/ undefined, visited.propertyName, - /*initializer*/ undefined); - } - else { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, - /*initializer*/ undefined); - } + visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, + /*initializer*/ undefined); } if (!ts.nodeIsSynthesized(visited)) { visited = ts.factory.cloneNode(visited); @@ -56992,7 +56987,11 @@ var ts; if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) { @@ -59093,6 +59092,12 @@ var ts; return mapType(type, getLowerBoundOfKeyType); } if (type.flags & 2097152 /* TypeFlags.Intersection */) { + // Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {}, + // and bigint & {} intersections that are used to prevent subtype reduction in union types. + var types = type.types; + if (types.length === 2 && !!(types[0].flags & (4 /* TypeFlags.String */ | 8 /* TypeFlags.Number */ | 64 /* TypeFlags.BigInt */)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(ts.sameMap(type.types, getLowerBoundOfKeyType)); } return type; @@ -69280,7 +69285,10 @@ var ts; // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */ || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { @@ -81446,7 +81454,7 @@ var ts; checkDecorators(node); } function getEffectiveTypeArgumentAtIndex(node, typeParameters, index) { - if (index < typeParameters.length) { + if (node.typeArguments && index < node.typeArguments.length) { return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; @@ -90225,7 +90233,7 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments); } var nodeArguments = node.arguments; - if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) { + if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext && moduleKind !== ts.ModuleKind.Node16) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { @@ -117872,7 +117880,7 @@ var ts; state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; var packageJsonScope = ts.getPackageScopeForPath(fileName, state); - var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; + var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope }; } } @@ -119603,7 +119611,7 @@ var ts; // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); + var result = getImpliedNodeFormatForFileWorker(ts.getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); var languageVersion = ts.getEmitScriptTarget(options); var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options); return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) : @@ -124264,7 +124272,7 @@ var ts; var maybeBlockedByTypesVersions = false; var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); + var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.contents.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); var importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) { var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"]; @@ -124626,7 +124634,7 @@ var ts; case ts.ModuleKind.CommonJS: if (file.packageJsonScope) { (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages( - /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ? + /*details*/ undefined, file.packageJsonScope.contents.packageJsonContent.type ? ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor))); } @@ -141362,7 +141370,7 @@ var ts; } var parent = node.parent; var typeChecker = program.getTypeChecker(); - if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) { + if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isIdentifier(node) && ts.isJSDocOverrideTag(parent) && parent.tagName === node)) { return getDefinitionFromOverriddenMember(typeChecker, node) || ts.emptyArray; } // Labels @@ -178842,7 +178850,7 @@ var ts; var packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex); var packageJsonCache = (_a = project.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache(); var compilerOptions = project.getCompilationSettings(); - var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); + var packageJson = ts.getPackageScopeForPath(ts.getNormalizedAbsolutePath(packageDirectory + "/package.json", project.getCurrentDirectory()), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); if (!packageJson) return undefined; // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext - diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 53b8c929ba8f1..b6532d29d2c4c 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -303,7 +303,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.3"; + ts.version = "4.8.4"; /* @internal */ var Comparison; (function (Comparison) { @@ -31710,6 +31710,7 @@ var ts; case 335 /* SyntaxKind.JSDocProtectedTag */: case 336 /* SyntaxKind.JSDocReadonlyTag */: case 331 /* SyntaxKind.JSDocDeprecatedTag */: + case 337 /* SyntaxKind.JSDocOverrideTag */: return visitNode(cbNode, node.tagName) || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); case 350 /* SyntaxKind.PartiallyEmittedExpression */: @@ -42998,7 +42999,7 @@ var ts; function withPackageId(packageInfo, r) { var packageId; if (r && packageInfo) { - var packageJsonContent = packageInfo.packageJsonContent; + var packageJsonContent = packageInfo.contents.packageJsonContent; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -44317,16 +44318,16 @@ var ts; function loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson) { if (considerPackageJson === void 0) { considerPackageJson = true; } var packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - var packageJsonContent = packageInfo && packageInfo.packageJsonContent; - var versionPaths = packageInfo && packageInfo.versionPaths; + var packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + var versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } /* @internal */ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } var entrypoints; var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript; @@ -44335,13 +44336,13 @@ var ts; requireState.conditions = ["node", "require", "types"]; requireState.requestContainingDirectory = packageJsonInfo.packageDirectory; var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, - /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths); + /*onlyRecordFailures*/ false, requireState, packageJsonInfo.contents.packageJsonContent, packageJsonInfo.contents.versionPaths); entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) { var conditions = _a[_i]; var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions }); - var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions); + var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) { var resolution = exportResolutions_1[_b]; @@ -44350,7 +44351,7 @@ var ts; } } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo; function loadEntrypointsFromExportMap(scope, exports, state, extensions) { @@ -44454,7 +44455,9 @@ var ts; if (traceEnabled) trace(host, ts.Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory: packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) @@ -44470,7 +44473,7 @@ var ts; trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined }; + var result = { packageDirectory: packageDirectory, contents: { packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined } }; (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -44595,17 +44598,16 @@ var ts; } function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) { var _a, _b; - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } var parts = ts.getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - var nameParts = ts.getPathComponents(scope.packageJsonContent.name); + var nameParts = ts.getPathComponents(scope.contents.packageJsonContent.name); if (!ts.every(nameParts, function (p, i) { return parts[i] === p; })) { return undefined; } @@ -44613,30 +44615,30 @@ var ts; return loadModuleFromExports(scope, extensions, !ts.length(trailingParts) ? "." : ".".concat(ts.directorySeparator).concat(trailingParts.join(ts.directorySeparator)), state, cache, redirectedReference); } function loadModuleFromExports(scope, extensions, subpath, state, cache, redirectedReference) { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { var mainExport = void 0; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (ts.hasProperty(scope.packageJsonContent.exports, ".")) { - mainExport = scope.packageJsonContent.exports["."]; + else if (ts.hasProperty(scope.contents.packageJsonContent.exports, ".")) { + mainExport = scope.contents.packageJsonContent.exports["."]; } if (mainExport) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -44654,8 +44656,7 @@ var ts; } return toSearchResult(/*value*/ undefined); } - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -44663,13 +44664,13 @@ var ts; } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -45014,7 +45015,7 @@ var ts; if (fromFile) { return noPackageId(fromFile); } - var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.packageJsonContent, packageInfo.versionPaths); + var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.contents.packageJsonContent, packageInfo.contents.versionPaths); return withPackageId(packageInfo, fromDirectory); } } @@ -45022,14 +45023,14 @@ var ts; var loader = function (extensions, candidate, onlyRecordFailures, state) { var _a; // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return (_a = loadModuleFromExports(packageInfo, extensions, ts.combinePaths(".", rest), state, cache, redirectedReference)) === null || _a === void 0 ? void 0 : _a.value; } var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); + loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.contents.packageJsonContent, packageInfo && packageInfo.contents.versionPaths); if (!pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -45041,12 +45042,12 @@ var ts; var packageDirectory = ts.combinePaths(nodeModulesDirectory, packageName); // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, ts.version, rest); + trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, ts.version, rest); } var packageDirectoryExists = nodeModulesDirectoryExists && ts.directoryProbablyExists(packageDirectory, state.host); - var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } @@ -49347,6 +49348,7 @@ var ts; var wildcardType = createIntrinsicType(1 /* TypeFlags.Any */, "any"); var errorType = createIntrinsicType(1 /* TypeFlags.Any */, "error"); var unresolvedType = createIntrinsicType(1 /* TypeFlags.Any */, "unresolved"); + var nonInferrableAnyType = createIntrinsicType(1 /* TypeFlags.Any */, "any", 65536 /* ObjectFlags.ContainsWideningType */); var intrinsicMarkerType = createIntrinsicType(1 /* TypeFlags.Any */, "intrinsic"); var unknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); var nonNullUnknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); @@ -51948,7 +51950,7 @@ var ts; if (ext === ".ts" /* Extension.Ts */ || ext === ".js" /* Extension.Js */ || ext === ".tsx" /* Extension.Tsx */ || ext === ".jsx" /* Extension.Jsx */) { var scope = currentSourceFile.packageJsonScope; var targetExt = ext === ".ts" /* Extension.Ts */ ? ".mts" /* Extension.Mts */ : ext === ".js" /* Extension.Js */ ? ".mjs" /* Extension.Mjs */ : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = ts.chainDiagnosticMessages( /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json")); @@ -54176,22 +54178,15 @@ var ts; context.approximateLength += ts.symbolName(parameterSymbol).length + 3; return parameterNode; function cloneBindingName(node) { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node); - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) { + return elideInitializerAndSetEmitFlags(node); + function elideInitializerAndSetEmitFlags(node) { if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags); + var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags); if (ts.isBindingElement(visited)) { - if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, - /* propertyName*/ undefined, visited.propertyName, - /*initializer*/ undefined); - } - else { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, - /*initializer*/ undefined); - } + visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, + /*initializer*/ undefined); } if (!ts.nodeIsSynthesized(visited)) { visited = ts.factory.cloneNode(visited); @@ -57186,7 +57181,11 @@ var ts; if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) { @@ -59287,6 +59286,12 @@ var ts; return mapType(type, getLowerBoundOfKeyType); } if (type.flags & 2097152 /* TypeFlags.Intersection */) { + // Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {}, + // and bigint & {} intersections that are used to prevent subtype reduction in union types. + var types = type.types; + if (types.length === 2 && !!(types[0].flags & (4 /* TypeFlags.String */ | 8 /* TypeFlags.Number */ | 64 /* TypeFlags.BigInt */)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(ts.sameMap(type.types, getLowerBoundOfKeyType)); } return type; @@ -69474,7 +69479,10 @@ var ts; // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */ || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { @@ -81640,7 +81648,7 @@ var ts; checkDecorators(node); } function getEffectiveTypeArgumentAtIndex(node, typeParameters, index) { - if (index < typeParameters.length) { + if (node.typeArguments && index < node.typeArguments.length) { return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; @@ -90419,7 +90427,7 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments); } var nodeArguments = node.arguments; - if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) { + if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext && moduleKind !== ts.ModuleKind.Node16) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { @@ -118066,7 +118074,7 @@ var ts; state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; var packageJsonScope = ts.getPackageScopeForPath(fileName, state); - var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; + var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope }; } } @@ -119797,7 +119805,7 @@ var ts; // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); + var result = getImpliedNodeFormatForFileWorker(ts.getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); var languageVersion = ts.getEmitScriptTarget(options); var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options); return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) : @@ -124458,7 +124466,7 @@ var ts; var maybeBlockedByTypesVersions = false; var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); + var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.contents.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); var importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) { var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"]; @@ -124820,7 +124828,7 @@ var ts; case ts.ModuleKind.CommonJS: if (file.packageJsonScope) { (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages( - /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ? + /*details*/ undefined, file.packageJsonScope.contents.packageJsonContent.type ? ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor))); } @@ -141975,7 +141983,7 @@ var ts; } var parent = node.parent; var typeChecker = program.getTypeChecker(); - if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) { + if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isIdentifier(node) && ts.isJSDocOverrideTag(parent) && parent.tagName === node)) { return getDefinitionFromOverriddenMember(typeChecker, node) || ts.emptyArray; } // Labels @@ -179036,7 +179044,7 @@ var ts; var packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex); var packageJsonCache = (_a = project.getModuleResolutionCache()) === null || _a === void 0 ? void 0 : _a.getPackageJsonInfoCache(); var compilerOptions = project.getCompilationSettings(); - var packageJson = ts.getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); + var packageJson = ts.getPackageScopeForPath(ts.getNormalizedAbsolutePath(packageDirectory + "/package.json", project.getCurrentDirectory()), ts.getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions)); if (!packageJson) return undefined; // Use fake options instead of actual compiler options to avoid following export map if the project uses node16 or nodenext - diff --git a/lib/typescript.js b/lib/typescript.js index 3c93c04e0e47a..c0f6f3a5702b4 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.3"; + ts.version = "4.8.4"; /* @internal */ var Comparison; (function (Comparison) { @@ -31701,6 +31701,7 @@ var ts; case 335 /* SyntaxKind.JSDocProtectedTag */: case 336 /* SyntaxKind.JSDocReadonlyTag */: case 331 /* SyntaxKind.JSDocDeprecatedTag */: + case 337 /* SyntaxKind.JSDocOverrideTag */: return visitNode(cbNode, node.tagName) || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); case 350 /* SyntaxKind.PartiallyEmittedExpression */: @@ -42989,7 +42990,7 @@ var ts; function withPackageId(packageInfo, r) { var packageId; if (r && packageInfo) { - var packageJsonContent = packageInfo.packageJsonContent; + var packageJsonContent = packageInfo.contents.packageJsonContent; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -44308,16 +44309,16 @@ var ts; function loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson) { if (considerPackageJson === void 0) { considerPackageJson = true; } var packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - var packageJsonContent = packageInfo && packageInfo.packageJsonContent; - var versionPaths = packageInfo && packageInfo.versionPaths; + var packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + var versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } /* @internal */ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } var entrypoints; var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript; @@ -44326,13 +44327,13 @@ var ts; requireState.conditions = ["node", "require", "types"]; requireState.requestContainingDirectory = packageJsonInfo.packageDirectory; var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, - /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths); + /*onlyRecordFailures*/ false, requireState, packageJsonInfo.contents.packageJsonContent, packageJsonInfo.contents.versionPaths); entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) { var conditions = _a[_i]; var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions }); - var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions); + var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) { var resolution = exportResolutions_1[_b]; @@ -44341,7 +44342,7 @@ var ts; } } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo; function loadEntrypointsFromExportMap(scope, exports, state, extensions) { @@ -44445,7 +44446,9 @@ var ts; if (traceEnabled) trace(host, ts.Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory: packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) @@ -44461,7 +44464,7 @@ var ts; trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined }; + var result = { packageDirectory: packageDirectory, contents: { packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined } }; (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -44586,17 +44589,16 @@ var ts; } function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) { var _a, _b; - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } var parts = ts.getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - var nameParts = ts.getPathComponents(scope.packageJsonContent.name); + var nameParts = ts.getPathComponents(scope.contents.packageJsonContent.name); if (!ts.every(nameParts, function (p, i) { return parts[i] === p; })) { return undefined; } @@ -44604,30 +44606,30 @@ var ts; return loadModuleFromExports(scope, extensions, !ts.length(trailingParts) ? "." : ".".concat(ts.directorySeparator).concat(trailingParts.join(ts.directorySeparator)), state, cache, redirectedReference); } function loadModuleFromExports(scope, extensions, subpath, state, cache, redirectedReference) { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { var mainExport = void 0; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (ts.hasProperty(scope.packageJsonContent.exports, ".")) { - mainExport = scope.packageJsonContent.exports["."]; + else if (ts.hasProperty(scope.contents.packageJsonContent.exports, ".")) { + mainExport = scope.contents.packageJsonContent.exports["."]; } if (mainExport) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -44645,8 +44647,7 @@ var ts; } return toSearchResult(/*value*/ undefined); } - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -44654,13 +44655,13 @@ var ts; } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -45005,7 +45006,7 @@ var ts; if (fromFile) { return noPackageId(fromFile); } - var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.packageJsonContent, packageInfo.versionPaths); + var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.contents.packageJsonContent, packageInfo.contents.versionPaths); return withPackageId(packageInfo, fromDirectory); } } @@ -45013,14 +45014,14 @@ var ts; var loader = function (extensions, candidate, onlyRecordFailures, state) { var _a; // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return (_a = loadModuleFromExports(packageInfo, extensions, ts.combinePaths(".", rest), state, cache, redirectedReference)) === null || _a === void 0 ? void 0 : _a.value; } var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); + loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.contents.packageJsonContent, packageInfo && packageInfo.contents.versionPaths); if (!pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -45032,12 +45033,12 @@ var ts; var packageDirectory = ts.combinePaths(nodeModulesDirectory, packageName); // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, ts.version, rest); + trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, ts.version, rest); } var packageDirectoryExists = nodeModulesDirectoryExists && ts.directoryProbablyExists(packageDirectory, state.host); - var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } @@ -49338,6 +49339,7 @@ var ts; var wildcardType = createIntrinsicType(1 /* TypeFlags.Any */, "any"); var errorType = createIntrinsicType(1 /* TypeFlags.Any */, "error"); var unresolvedType = createIntrinsicType(1 /* TypeFlags.Any */, "unresolved"); + var nonInferrableAnyType = createIntrinsicType(1 /* TypeFlags.Any */, "any", 65536 /* ObjectFlags.ContainsWideningType */); var intrinsicMarkerType = createIntrinsicType(1 /* TypeFlags.Any */, "intrinsic"); var unknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); var nonNullUnknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); @@ -51939,7 +51941,7 @@ var ts; if (ext === ".ts" /* Extension.Ts */ || ext === ".js" /* Extension.Js */ || ext === ".tsx" /* Extension.Tsx */ || ext === ".jsx" /* Extension.Jsx */) { var scope = currentSourceFile.packageJsonScope; var targetExt = ext === ".ts" /* Extension.Ts */ ? ".mts" /* Extension.Mts */ : ext === ".js" /* Extension.Js */ ? ".mjs" /* Extension.Mjs */ : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = ts.chainDiagnosticMessages( /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json")); @@ -54167,22 +54169,15 @@ var ts; context.approximateLength += ts.symbolName(parameterSymbol).length + 3; return parameterNode; function cloneBindingName(node) { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node); - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) { + return elideInitializerAndSetEmitFlags(node); + function elideInitializerAndSetEmitFlags(node) { if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags); + var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags); if (ts.isBindingElement(visited)) { - if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, - /* propertyName*/ undefined, visited.propertyName, - /*initializer*/ undefined); - } - else { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, - /*initializer*/ undefined); - } + visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, + /*initializer*/ undefined); } if (!ts.nodeIsSynthesized(visited)) { visited = ts.factory.cloneNode(visited); @@ -57177,7 +57172,11 @@ var ts; if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) { @@ -59278,6 +59277,12 @@ var ts; return mapType(type, getLowerBoundOfKeyType); } if (type.flags & 2097152 /* TypeFlags.Intersection */) { + // Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {}, + // and bigint & {} intersections that are used to prevent subtype reduction in union types. + var types = type.types; + if (types.length === 2 && !!(types[0].flags & (4 /* TypeFlags.String */ | 8 /* TypeFlags.Number */ | 64 /* TypeFlags.BigInt */)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(ts.sameMap(type.types, getLowerBoundOfKeyType)); } return type; @@ -69465,7 +69470,10 @@ var ts; // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */ || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { @@ -81631,7 +81639,7 @@ var ts; checkDecorators(node); } function getEffectiveTypeArgumentAtIndex(node, typeParameters, index) { - if (index < typeParameters.length) { + if (node.typeArguments && index < node.typeArguments.length) { return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; @@ -90410,7 +90418,7 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments); } var nodeArguments = node.arguments; - if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) { + if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext && moduleKind !== ts.ModuleKind.Node16) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { @@ -118057,7 +118065,7 @@ var ts; state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; var packageJsonScope = ts.getPackageScopeForPath(fileName, state); - var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; + var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope }; } } @@ -119788,7 +119796,7 @@ var ts; // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); + var result = getImpliedNodeFormatForFileWorker(ts.getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); var languageVersion = ts.getEmitScriptTarget(options); var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options); return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) : @@ -124449,7 +124457,7 @@ var ts; var maybeBlockedByTypesVersions = false; var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); + var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.contents.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); var importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) { var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"]; @@ -124811,7 +124819,7 @@ var ts; case ts.ModuleKind.CommonJS: if (file.packageJsonScope) { (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages( - /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ? + /*details*/ undefined, file.packageJsonScope.contents.packageJsonContent.type ? ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor))); } @@ -141966,7 +141974,7 @@ var ts; } var parent = node.parent; var typeChecker = program.getTypeChecker(); - if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) { + if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isIdentifier(node) && ts.isJSDocOverrideTag(parent) && parent.tagName === node)) { return getDefinitionFromOverriddenMember(typeChecker, node) || ts.emptyArray; } // Labels diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 61b1259b561f8..955e00658c063 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.3"; + ts.version = "4.8.4"; /* @internal */ var Comparison; (function (Comparison) { @@ -31701,6 +31701,7 @@ var ts; case 335 /* SyntaxKind.JSDocProtectedTag */: case 336 /* SyntaxKind.JSDocReadonlyTag */: case 331 /* SyntaxKind.JSDocDeprecatedTag */: + case 337 /* SyntaxKind.JSDocOverrideTag */: return visitNode(cbNode, node.tagName) || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); case 350 /* SyntaxKind.PartiallyEmittedExpression */: @@ -42989,7 +42990,7 @@ var ts; function withPackageId(packageInfo, r) { var packageId; if (r && packageInfo) { - var packageJsonContent = packageInfo.packageJsonContent; + var packageJsonContent = packageInfo.contents.packageJsonContent; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -44308,16 +44309,16 @@ var ts; function loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson) { if (considerPackageJson === void 0) { considerPackageJson = true; } var packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - var packageJsonContent = packageInfo && packageInfo.packageJsonContent; - var versionPaths = packageInfo && packageInfo.versionPaths; + var packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + var versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } /* @internal */ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } var entrypoints; var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript; @@ -44326,13 +44327,13 @@ var ts; requireState.conditions = ["node", "require", "types"]; requireState.requestContainingDirectory = packageJsonInfo.packageDirectory; var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, - /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths); + /*onlyRecordFailures*/ false, requireState, packageJsonInfo.contents.packageJsonContent, packageJsonInfo.contents.versionPaths); entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) { var conditions = _a[_i]; var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions }); - var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions); + var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) { var resolution = exportResolutions_1[_b]; @@ -44341,7 +44342,7 @@ var ts; } } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo; function loadEntrypointsFromExportMap(scope, exports, state, extensions) { @@ -44445,7 +44446,9 @@ var ts; if (traceEnabled) trace(host, ts.Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory: packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) @@ -44461,7 +44464,7 @@ var ts; trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined }; + var result = { packageDirectory: packageDirectory, contents: { packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined } }; (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -44586,17 +44589,16 @@ var ts; } function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) { var _a, _b; - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } var parts = ts.getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - var nameParts = ts.getPathComponents(scope.packageJsonContent.name); + var nameParts = ts.getPathComponents(scope.contents.packageJsonContent.name); if (!ts.every(nameParts, function (p, i) { return parts[i] === p; })) { return undefined; } @@ -44604,30 +44606,30 @@ var ts; return loadModuleFromExports(scope, extensions, !ts.length(trailingParts) ? "." : ".".concat(ts.directorySeparator).concat(trailingParts.join(ts.directorySeparator)), state, cache, redirectedReference); } function loadModuleFromExports(scope, extensions, subpath, state, cache, redirectedReference) { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { var mainExport = void 0; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (ts.hasProperty(scope.packageJsonContent.exports, ".")) { - mainExport = scope.packageJsonContent.exports["."]; + else if (ts.hasProperty(scope.contents.packageJsonContent.exports, ".")) { + mainExport = scope.contents.packageJsonContent.exports["."]; } if (mainExport) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -44645,8 +44647,7 @@ var ts; } return toSearchResult(/*value*/ undefined); } - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -44654,13 +44655,13 @@ var ts; } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -45005,7 +45006,7 @@ var ts; if (fromFile) { return noPackageId(fromFile); } - var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.packageJsonContent, packageInfo.versionPaths); + var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.contents.packageJsonContent, packageInfo.contents.versionPaths); return withPackageId(packageInfo, fromDirectory); } } @@ -45013,14 +45014,14 @@ var ts; var loader = function (extensions, candidate, onlyRecordFailures, state) { var _a; // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return (_a = loadModuleFromExports(packageInfo, extensions, ts.combinePaths(".", rest), state, cache, redirectedReference)) === null || _a === void 0 ? void 0 : _a.value; } var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); + loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.contents.packageJsonContent, packageInfo && packageInfo.contents.versionPaths); if (!pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -45032,12 +45033,12 @@ var ts; var packageDirectory = ts.combinePaths(nodeModulesDirectory, packageName); // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, ts.version, rest); + trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, ts.version, rest); } var packageDirectoryExists = nodeModulesDirectoryExists && ts.directoryProbablyExists(packageDirectory, state.host); - var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } @@ -49338,6 +49339,7 @@ var ts; var wildcardType = createIntrinsicType(1 /* TypeFlags.Any */, "any"); var errorType = createIntrinsicType(1 /* TypeFlags.Any */, "error"); var unresolvedType = createIntrinsicType(1 /* TypeFlags.Any */, "unresolved"); + var nonInferrableAnyType = createIntrinsicType(1 /* TypeFlags.Any */, "any", 65536 /* ObjectFlags.ContainsWideningType */); var intrinsicMarkerType = createIntrinsicType(1 /* TypeFlags.Any */, "intrinsic"); var unknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); var nonNullUnknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); @@ -51939,7 +51941,7 @@ var ts; if (ext === ".ts" /* Extension.Ts */ || ext === ".js" /* Extension.Js */ || ext === ".tsx" /* Extension.Tsx */ || ext === ".jsx" /* Extension.Jsx */) { var scope = currentSourceFile.packageJsonScope; var targetExt = ext === ".ts" /* Extension.Ts */ ? ".mts" /* Extension.Mts */ : ext === ".js" /* Extension.Js */ ? ".mjs" /* Extension.Mjs */ : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = ts.chainDiagnosticMessages( /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json")); @@ -54167,22 +54169,15 @@ var ts; context.approximateLength += ts.symbolName(parameterSymbol).length + 3; return parameterNode; function cloneBindingName(node) { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node); - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) { + return elideInitializerAndSetEmitFlags(node); + function elideInitializerAndSetEmitFlags(node) { if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags); + var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags); if (ts.isBindingElement(visited)) { - if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, - /* propertyName*/ undefined, visited.propertyName, - /*initializer*/ undefined); - } - else { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, - /*initializer*/ undefined); - } + visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, + /*initializer*/ undefined); } if (!ts.nodeIsSynthesized(visited)) { visited = ts.factory.cloneNode(visited); @@ -57177,7 +57172,11 @@ var ts; if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) { @@ -59278,6 +59277,12 @@ var ts; return mapType(type, getLowerBoundOfKeyType); } if (type.flags & 2097152 /* TypeFlags.Intersection */) { + // Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {}, + // and bigint & {} intersections that are used to prevent subtype reduction in union types. + var types = type.types; + if (types.length === 2 && !!(types[0].flags & (4 /* TypeFlags.String */ | 8 /* TypeFlags.Number */ | 64 /* TypeFlags.BigInt */)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(ts.sameMap(type.types, getLowerBoundOfKeyType)); } return type; @@ -69465,7 +69470,10 @@ var ts; // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */ || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { @@ -81631,7 +81639,7 @@ var ts; checkDecorators(node); } function getEffectiveTypeArgumentAtIndex(node, typeParameters, index) { - if (index < typeParameters.length) { + if (node.typeArguments && index < node.typeArguments.length) { return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; @@ -90410,7 +90418,7 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments); } var nodeArguments = node.arguments; - if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) { + if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext && moduleKind !== ts.ModuleKind.Node16) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { @@ -118057,7 +118065,7 @@ var ts; state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; var packageJsonScope = ts.getPackageScopeForPath(fileName, state); - var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; + var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope }; } } @@ -119788,7 +119796,7 @@ var ts; // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); + var result = getImpliedNodeFormatForFileWorker(ts.getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); var languageVersion = ts.getEmitScriptTarget(options); var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options); return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) : @@ -124449,7 +124457,7 @@ var ts; var maybeBlockedByTypesVersions = false; var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); + var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.contents.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); var importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) { var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"]; @@ -124811,7 +124819,7 @@ var ts; case ts.ModuleKind.CommonJS: if (file.packageJsonScope) { (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages( - /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ? + /*details*/ undefined, file.packageJsonScope.contents.packageJsonContent.type ? ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor))); } @@ -141966,7 +141974,7 @@ var ts; } var parent = node.parent; var typeChecker = program.getTypeChecker(); - if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isJSDocOverrideTag(node) && ts.rangeContainsPosition(node.tagName, position))) { + if (node.kind === 159 /* SyntaxKind.OverrideKeyword */ || (ts.isIdentifier(node) && ts.isJSDocOverrideTag(parent) && parent.tagName === node)) { return getDefinitionFromOverriddenMember(typeChecker, node) || ts.emptyArray; } // Labels diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 9303e787c1ef4..c7a265d6c0dcc 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -89,7 +89,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.3"; + ts.version = "4.8.4"; /* @internal */ var Comparison; (function (Comparison) { @@ -31496,6 +31496,7 @@ var ts; case 335 /* SyntaxKind.JSDocProtectedTag */: case 336 /* SyntaxKind.JSDocReadonlyTag */: case 331 /* SyntaxKind.JSDocDeprecatedTag */: + case 337 /* SyntaxKind.JSDocOverrideTag */: return visitNode(cbNode, node.tagName) || (typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment)); case 350 /* SyntaxKind.PartiallyEmittedExpression */: @@ -42784,7 +42785,7 @@ var ts; function withPackageId(packageInfo, r) { var packageId; if (r && packageInfo) { - var packageJsonContent = packageInfo.packageJsonContent; + var packageJsonContent = packageInfo.contents.packageJsonContent; if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { packageId = { name: packageJsonContent.name, @@ -44103,16 +44104,16 @@ var ts; function loadNodeModuleFromDirectory(extensions, candidate, onlyRecordFailures, state, considerPackageJson) { if (considerPackageJson === void 0) { considerPackageJson = true; } var packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; - var packageJsonContent = packageInfo && packageInfo.packageJsonContent; - var versionPaths = packageInfo && packageInfo.versionPaths; + var packageJsonContent = packageInfo && packageInfo.contents.packageJsonContent; + var versionPaths = packageInfo && packageInfo.contents.versionPaths; return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } /* @internal */ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) { - if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) { + if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) { // Cached value excludes resolutions to JS files - those could be // cached separately, but they're used rarely. - return packageJsonInfo.resolvedEntrypoints; + return packageJsonInfo.contents.resolvedEntrypoints; } var entrypoints; var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript; @@ -44121,13 +44122,13 @@ var ts; requireState.conditions = ["node", "require", "types"]; requireState.requestContainingDirectory = packageJsonInfo.packageDirectory; var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory, - /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths); + /*onlyRecordFailures*/ false, requireState, packageJsonInfo.contents.packageJsonContent, packageJsonInfo.contents.versionPaths); entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path); - if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) { + if (features & NodeResolutionFeatures.Exports && packageJsonInfo.contents.packageJsonContent.exports) { for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) { var conditions = _a[_i]; var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions }); - var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions); + var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.contents.packageJsonContent.exports, exportState, extensions); if (exportResolutions) { for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) { var resolution = exportResolutions_1[_b]; @@ -44136,7 +44137,7 @@ var ts; } } } - return packageJsonInfo.resolvedEntrypoints = entrypoints || false; + return packageJsonInfo.contents.resolvedEntrypoints = entrypoints || false; } ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo; function loadEntrypointsFromExportMap(scope, exports, state, extensions) { @@ -44240,7 +44241,9 @@ var ts; if (traceEnabled) trace(host, ts.Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath); state.affectingLocations.push(packageJsonPath); - return existing; + return existing.packageDirectory === packageDirectory ? + existing : + { packageDirectory: packageDirectory, contents: existing.contents }; } else { if (existing && traceEnabled) @@ -44256,7 +44259,7 @@ var ts; trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined }; + var result = { packageDirectory: packageDirectory, contents: { packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined } }; (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result); state.affectingLocations.push(packageJsonPath); return result; @@ -44381,17 +44384,16 @@ var ts; } function loadModuleFromSelfNameReference(extensions, moduleName, directory, state, cache, redirectedReference) { var _a, _b; - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); - if (!scope || !scope.packageJsonContent.exports) { + if (!scope || !scope.contents.packageJsonContent.exports) { return undefined; } - if (typeof scope.packageJsonContent.name !== "string") { + if (typeof scope.contents.packageJsonContent.name !== "string") { return undefined; } var parts = ts.getPathComponents(moduleName); // unrooted paths should have `""` as their 0th entry - var nameParts = ts.getPathComponents(scope.packageJsonContent.name); + var nameParts = ts.getPathComponents(scope.contents.packageJsonContent.name); if (!ts.every(nameParts, function (p, i) { return parts[i] === p; })) { return undefined; } @@ -44399,30 +44401,30 @@ var ts; return loadModuleFromExports(scope, extensions, !ts.length(trailingParts) ? "." : ".".concat(ts.directorySeparator).concat(trailingParts.join(ts.directorySeparator)), state, cache, redirectedReference); } function loadModuleFromExports(scope, extensions, subpath, state, cache, redirectedReference) { - if (!scope.packageJsonContent.exports) { + if (!scope.contents.packageJsonContent.exports) { return undefined; } if (subpath === ".") { var mainExport = void 0; - if (typeof scope.packageJsonContent.exports === "string" || Array.isArray(scope.packageJsonContent.exports) || (typeof scope.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.packageJsonContent.exports))) { - mainExport = scope.packageJsonContent.exports; + if (typeof scope.contents.packageJsonContent.exports === "string" || Array.isArray(scope.contents.packageJsonContent.exports) || (typeof scope.contents.packageJsonContent.exports === "object" && noKeyStartsWithDot(scope.contents.packageJsonContent.exports))) { + mainExport = scope.contents.packageJsonContent.exports; } - else if (ts.hasProperty(scope.packageJsonContent.exports, ".")) { - mainExport = scope.packageJsonContent.exports["."]; + else if (ts.hasProperty(scope.contents.packageJsonContent.exports, ".")) { + mainExport = scope.contents.packageJsonContent.exports["."]; } if (mainExport) { var loadModuleFromTargetImportOrExport = getLoadModuleFromTargetImportOrExport(extensions, state, cache, redirectedReference, subpath, scope, /*isImports*/ false); return loadModuleFromTargetImportOrExport(mainExport, "", /*pattern*/ false); } } - else if (allKeysStartWithDot(scope.packageJsonContent.exports)) { - if (typeof scope.packageJsonContent.exports !== "object") { + else if (allKeysStartWithDot(scope.contents.packageJsonContent.exports)) { + if (typeof scope.contents.packageJsonContent.exports !== "object") { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1, subpath, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.packageJsonContent.exports, scope, /*isImports*/ false); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, subpath, scope.contents.packageJsonContent.exports, scope, /*isImports*/ false); if (result) { return result; } @@ -44440,8 +44442,7 @@ var ts; } return toSearchResult(/*value*/ undefined); } - var useCaseSensitiveFileNames = typeof state.host.useCaseSensitiveFileNames === "function" ? state.host.useCaseSensitiveFileNames() : state.host.useCaseSensitiveFileNames; - var directoryPath = ts.toPath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a), ts.createGetCanonicalFileName(useCaseSensitiveFileNames === undefined ? true : useCaseSensitiveFileNames)); + var directoryPath = ts.getNormalizedAbsolutePath(ts.combinePaths(directory, "dummy"), (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); var scope = getPackageScopeForPath(directoryPath, state); if (!scope) { if (state.traceEnabled) { @@ -44449,13 +44450,13 @@ var ts; } return toSearchResult(/*value*/ undefined); } - if (!scope.packageJsonContent.imports) { + if (!scope.contents.packageJsonContent.imports) { if (state.traceEnabled) { trace(state.host, ts.Diagnostics.package_json_scope_0_has_no_imports_defined, scope.packageDirectory); } return toSearchResult(/*value*/ undefined); } - var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.packageJsonContent.imports, scope, /*isImports*/ true); + var result = loadModuleFromImportsOrExports(extensions, state, cache, redirectedReference, moduleName, scope.contents.packageJsonContent.imports, scope, /*isImports*/ true); if (result) { return result; } @@ -44800,7 +44801,7 @@ var ts; if (fromFile) { return noPackageId(fromFile); } - var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.packageJsonContent, packageInfo.versionPaths); + var fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageInfo.contents.packageJsonContent, packageInfo.contents.versionPaths); return withPackageId(packageInfo, fromDirectory); } } @@ -44808,14 +44809,14 @@ var ts; var loader = function (extensions, candidate, onlyRecordFailures, state) { var _a; // package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them) - if (packageInfo && packageInfo.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { + if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) { return (_a = loadModuleFromExports(packageInfo, extensions, ts.combinePaths(".", rest), state, cache, redirectedReference)) === null || _a === void 0 ? void 0 : _a.value; } var pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.packageJsonContent, packageInfo && packageInfo.versionPaths); + loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageInfo && packageInfo.contents.packageJsonContent, packageInfo && packageInfo.contents.versionPaths); if (!pathAndExtension && packageInfo // eslint-disable-next-line no-null/no-null - && (packageInfo.packageJsonContent.exports === undefined || packageInfo.packageJsonContent.exports === null) + && (packageInfo.contents.packageJsonContent.exports === undefined || packageInfo.contents.packageJsonContent.exports === null) && state.features & NodeResolutionFeatures.EsmMode) { // EsmMode disables index lookup in `loadNodeModuleFromDirectoryWorker` generally, however non-relative package resolutions still assume // a default `index.js` entrypoint if no `main` or `exports` are present @@ -44827,12 +44828,12 @@ var ts; var packageDirectory = ts.combinePaths(nodeModulesDirectory, packageName); // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); - if (packageInfo && packageInfo.versionPaths) { + if (packageInfo && packageInfo.contents.versionPaths) { if (state.traceEnabled) { - trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, ts.version, rest); + trace(state.host, ts.Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, ts.version, rest); } var packageDirectoryExists = nodeModulesDirectoryExists && ts.directoryProbablyExists(packageDirectory, state.host); - var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); + var fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } @@ -49133,6 +49134,7 @@ var ts; var wildcardType = createIntrinsicType(1 /* TypeFlags.Any */, "any"); var errorType = createIntrinsicType(1 /* TypeFlags.Any */, "error"); var unresolvedType = createIntrinsicType(1 /* TypeFlags.Any */, "unresolved"); + var nonInferrableAnyType = createIntrinsicType(1 /* TypeFlags.Any */, "any", 65536 /* ObjectFlags.ContainsWideningType */); var intrinsicMarkerType = createIntrinsicType(1 /* TypeFlags.Any */, "intrinsic"); var unknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); var nonNullUnknownType = createIntrinsicType(2 /* TypeFlags.Unknown */, "unknown"); @@ -51734,7 +51736,7 @@ var ts; if (ext === ".ts" /* Extension.Ts */ || ext === ".js" /* Extension.Js */ || ext === ".tsx" /* Extension.Tsx */ || ext === ".jsx" /* Extension.Jsx */) { var scope = currentSourceFile.packageJsonScope; var targetExt = ext === ".ts" /* Extension.Ts */ ? ".mts" /* Extension.Mts */ : ext === ".js" /* Extension.Js */ ? ".mjs" /* Extension.Mjs */ : undefined; - if (scope && !scope.packageJsonContent.type) { + if (scope && !scope.contents.packageJsonContent.type) { if (targetExt) { diagnosticDetails = ts.chainDiagnosticMessages( /*details*/ undefined, ts.Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1, targetExt, ts.combinePaths(scope.packageDirectory, "package.json")); @@ -53962,22 +53964,15 @@ var ts; context.approximateLength += ts.symbolName(parameterSymbol).length + 3; return parameterNode; function cloneBindingName(node) { - return elideInitializerAndPropertyRenamingAndSetEmitFlags(node); - function elideInitializerAndPropertyRenamingAndSetEmitFlags(node) { + return elideInitializerAndSetEmitFlags(node); + function elideInitializerAndSetEmitFlags(node) { if (context.tracker.trackSymbol && ts.isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - var visited = ts.visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags); + var visited = ts.visitEachChild(node, elideInitializerAndSetEmitFlags, ts.nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags); if (ts.isBindingElement(visited)) { - if (visited.propertyName && ts.isIdentifier(visited.propertyName) && ts.isIdentifier(visited.name)) { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, - /* propertyName*/ undefined, visited.propertyName, - /*initializer*/ undefined); - } - else { - visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, - /*initializer*/ undefined); - } + visited = ts.factory.updateBindingElement(visited, visited.dotDotDotToken, visited.propertyName, visited.name, + /*initializer*/ undefined); } if (!ts.nodeIsSynthesized(visited)) { visited = ts.factory.cloneNode(visited); @@ -56972,7 +56967,11 @@ var ts; if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) { @@ -59073,6 +59072,12 @@ var ts; return mapType(type, getLowerBoundOfKeyType); } if (type.flags & 2097152 /* TypeFlags.Intersection */) { + // Similarly to getTypeFromIntersectionTypeNode, we preserve the special string & {}, number & {}, + // and bigint & {} intersections that are used to prevent subtype reduction in union types. + var types = type.types; + if (types.length === 2 && !!(types[0].flags & (4 /* TypeFlags.String */ | 8 /* TypeFlags.Number */ | 64 /* TypeFlags.BigInt */)) && types[1] === emptyTypeLiteralType) { + return type; + } return getIntersectionType(ts.sameMap(type.types, getLowerBoundOfKeyType)); } return type; @@ -69260,7 +69265,10 @@ var ts; // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (ts.getObjectFlags(source) & 262144 /* ObjectFlags.NonInferrableType */ || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { @@ -81426,7 +81434,7 @@ var ts; checkDecorators(node); } function getEffectiveTypeArgumentAtIndex(node, typeParameters, index) { - if (index < typeParameters.length) { + if (node.typeArguments && index < node.typeArguments.length) { return getTypeFromTypeNode(node.typeArguments[index]); } return getEffectiveTypeArguments(node, typeParameters)[index]; @@ -90205,7 +90213,7 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.This_use_of_import_is_invalid_import_calls_can_be_written_but_they_must_have_parentheses_and_cannot_have_type_arguments); } var nodeArguments = node.arguments; - if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext) { + if (moduleKind !== ts.ModuleKind.ESNext && moduleKind !== ts.ModuleKind.NodeNext && moduleKind !== ts.ModuleKind.Node16) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { @@ -117852,7 +117860,7 @@ var ts; state.failedLookupLocations = packageJsonLocations; state.affectingLocations = packageJsonLocations; var packageJsonScope = ts.getPackageScopeForPath(fileName, state); - var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; + var impliedNodeFormat = (packageJsonScope === null || packageJsonScope === void 0 ? void 0 : packageJsonScope.contents.packageJsonContent.type) === "module" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS; return { impliedNodeFormat: impliedNodeFormat, packageJsonLocations: packageJsonLocations, packageJsonScope: packageJsonScope }; } } @@ -119583,7 +119591,7 @@ var ts; // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront. - var result = getImpliedNodeFormatForFileWorker(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); + var result = getImpliedNodeFormatForFileWorker(ts.getNormalizedAbsolutePath(fileName, currentDirectory), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options); var languageVersion = ts.getEmitScriptTarget(options); var setExternalModuleIndicator = ts.getSetExternalModuleIndicator(options); return typeof result === "object" ? __assign(__assign({}, result), { languageVersion: languageVersion, setExternalModuleIndicator: setExternalModuleIndicator }) : @@ -124244,7 +124252,7 @@ var ts; var maybeBlockedByTypesVersions = false; var cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (typeof cachedPackageJson === "object" || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) { - var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); + var packageJsonContent = (cachedPackageJson === null || cachedPackageJson === void 0 ? void 0 : cachedPackageJson.contents.packageJsonContent) || JSON.parse(host.readFile(packageJsonPath)); var importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node16 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) { var conditions = ["node", importMode === ts.ModuleKind.ESNext ? "import" : "require", "types"]; @@ -124606,7 +124614,7 @@ var ts; case ts.ModuleKind.CommonJS: if (file.packageJsonScope) { (result !== null && result !== void 0 ? result : (result = [])).push(ts.chainDiagnosticMessages( - /*details*/ undefined, file.packageJsonScope.packageJsonContent.type ? + /*details*/ undefined, file.packageJsonScope.contents.packageJsonContent.type ? ts.Diagnostics.File_is_CommonJS_module_because_0_has_field_type_whose_value_is_not_module : ts.Diagnostics.File_is_CommonJS_module_because_0_does_not_have_field_type, toFileName(ts.last(file.packageJsonLocations), fileNameConvertor))); } diff --git a/package.json b/package.json index 759cfbc32d810..5abd9d225d19e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "4.8.3", + "version": "4.8.4", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index 0abc89d49fdf4..437ccdbcfb72b 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -5,7 +5,7 @@ namespace ts { // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - export const version = "4.8.3" as string; + export const version = "4.8.4" as string; /** * Type of objects whose values are all of the same type.