From 7275ded359554bbef410c96cd8cfc32a2f31ed84 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 30 May 2023 21:10:15 +0000 Subject: [PATCH] Bump version to 5.1.3 and update LKG. --- lib/tsc.js | 57 +++++++++++----------- lib/tsserver.js | 97 ++++++++++++++++++++++++-------------- lib/tsserverlibrary.d.ts | 4 +- lib/tsserverlibrary.js | 97 ++++++++++++++++++++++++-------------- lib/typescript.d.ts | 3 +- lib/typescript.js | 94 +++++++++++++++++++++++------------- lib/typingsInstaller.js | 3 +- package.json | 2 +- src/compiler/corePublic.ts | 2 +- 9 files changed, 221 insertions(+), 138 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 80de55fe38900..7670cce0ca8a9 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -18,7 +18,7 @@ and limitations under the License. // src/compiler/corePublic.ts var versionMajorMinor = "5.1"; -var version = "5.1.1-rc"; +var version = "5.1.3"; // src/compiler/core.ts var emptyArray = []; @@ -7704,6 +7704,7 @@ var Diagnostics = { Convert_typedef_to_TypeScript_type: diag(95176, 3 /* Message */, "Convert_typedef_to_TypeScript_type_95176", "Convert typedef to TypeScript type."), Convert_all_typedef_to_TypeScript_types: diag(95177, 3 /* Message */, "Convert_all_typedef_to_TypeScript_types_95177", "Convert all typedef to TypeScript types."), Move_to_file: diag(95178, 3 /* Message */, "Move_to_file_95178", "Move to file"), + Cannot_move_to_file_selected_file_is_invalid: diag(95179, 3 /* Message */, "Cannot_move_to_file_selected_file_is_invalid_95179", "Cannot move to file, selected file is invalid"), No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, 1 /* Error */, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."), Classes_may_not_have_a_field_named_constructor: diag(18006, 1 /* Error */, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."), JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, 1 /* Error */, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"), @@ -53984,7 +53985,7 @@ function createTypeChecker(host) { } else if (type !== firstType) { checkFlags |= 64 /* HasNonUniformType */; } - if (isLiteralType(type) || isPatternLiteralType(type) || type === uniqueLiteralType) { + if (isLiteralType(type) || isPatternLiteralType(type)) { checkFlags |= 128 /* HasLiteralType */; } if (type.flags & 131072 /* Never */ && type !== uniqueLiteralType) { @@ -56183,31 +56184,28 @@ function createTypeChecker(host) { return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin); } function getUnionOrIntersectionTypePredicate(signatures, kind) { - let first2; + let last2; const types = []; for (const sig of signatures) { const pred = getTypePredicateOfSignature(sig); - if (!pred || pred.kind === 2 /* AssertsThis */ || pred.kind === 3 /* AssertsIdentifier */) { - if (kind !== 2097152 /* Intersection */) { - continue; - } else { - return; - } - } - if (first2) { - if (!typePredicateKindsMatch(first2, pred)) { + if (pred) { + if (pred.kind !== 0 /* This */ && pred.kind !== 1 /* Identifier */ || last2 && !typePredicateKindsMatch(last2, pred)) { return void 0; } + last2 = pred; + types.push(pred.type); } else { - first2 = pred; + const returnType = kind !== 2097152 /* Intersection */ ? getReturnTypeOfSignature(sig) : void 0; + if (returnType !== falseType && returnType !== regularFalseType) { + return void 0; + } } - types.push(pred.type); } - if (!first2) { + if (!last2) { return void 0; } const compositeType = getUnionOrIntersectionType(types, kind); - return createTypePredicate(first2.kind, first2.parameterName, first2.parameterIndex, compositeType); + return createTypePredicate(last2.kind, last2.parameterName, last2.parameterIndex, compositeType); } function typePredicateKindsMatch(a, b) { return a.kind === b.kind && a.parameterIndex === b.parameterIndex; @@ -58088,18 +58086,19 @@ function createTypeChecker(host) { case 185 /* TypeQuery */: const entityName = node2.exprName; const firstIdentifier = getFirstIdentifier(entityName); - const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); - const tpDeclaration = tp.symbol.declarations[0]; - let tpScope; - if (tpDeclaration.kind === 167 /* TypeParameter */) { - tpScope = tpDeclaration.parent; - } else if (tp.isThisType) { - tpScope = tpDeclaration; - } else { - return true; - } - if (firstIdentifierSymbol.declarations) { - return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + if (!isThisIdentifier(firstIdentifier)) { + const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); + const tpDeclaration = tp.symbol.declarations[0]; + const tpScope = tpDeclaration.kind === 167 /* TypeParameter */ ? tpDeclaration.parent : ( + // Type parameter is a regular type parameter, e.g. foo + tp.isThisType ? tpDeclaration : ( + // Type parameter is the this type, and its declaration is the class declaration. + void 0 + ) + ); + if (firstIdentifierSymbol.declarations && tpScope) { + return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + } } return true; case 173 /* MethodDeclaration */: @@ -81638,7 +81637,7 @@ function createTypeChecker(host) { if (requestedExternalEmitHelperNames.has(name)) continue; requestedExternalEmitHelperNames.add(name); - const symbol = getSymbol(helpersModule.exports, escapeLeadingUnderscores(name), 111551 /* Value */); + const symbol = resolveSymbol(getSymbol(getExportsOfModule(helpersModule), escapeLeadingUnderscores(name), 111551 /* Value */)); if (!symbol) { error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name); } else if (helper & 524288 /* ClassPrivateFieldGet */) { diff --git a/lib/tsserver.js b/lib/tsserver.js index ec8709520bd17..63bcdac309ff4 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -2304,7 +2304,7 @@ module.exports = __toCommonJS(server_exports); // src/compiler/corePublic.ts var versionMajorMinor = "5.1"; -var version = "5.1.1-rc"; +var version = "5.1.3"; var Comparison = /* @__PURE__ */ ((Comparison3) => { Comparison3[Comparison3["LessThan"] = -1] = "LessThan"; Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo"; @@ -11212,6 +11212,7 @@ var Diagnostics = { Convert_typedef_to_TypeScript_type: diag(95176, 3 /* Message */, "Convert_typedef_to_TypeScript_type_95176", "Convert typedef to TypeScript type."), Convert_all_typedef_to_TypeScript_types: diag(95177, 3 /* Message */, "Convert_all_typedef_to_TypeScript_types_95177", "Convert all typedef to TypeScript types."), Move_to_file: diag(95178, 3 /* Message */, "Move_to_file_95178", "Move to file"), + Cannot_move_to_file_selected_file_is_invalid: diag(95179, 3 /* Message */, "Cannot_move_to_file_selected_file_is_invalid_95179", "Cannot move to file, selected file is invalid"), No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, 1 /* Error */, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."), Classes_may_not_have_a_field_named_constructor: diag(18006, 1 /* Error */, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."), JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, 1 /* Error */, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"), @@ -58635,7 +58636,7 @@ function createTypeChecker(host) { } else if (type !== firstType) { checkFlags |= 64 /* HasNonUniformType */; } - if (isLiteralType(type) || isPatternLiteralType(type) || type === uniqueLiteralType) { + if (isLiteralType(type) || isPatternLiteralType(type)) { checkFlags |= 128 /* HasLiteralType */; } if (type.flags & 131072 /* Never */ && type !== uniqueLiteralType) { @@ -60834,31 +60835,28 @@ function createTypeChecker(host) { return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin); } function getUnionOrIntersectionTypePredicate(signatures, kind) { - let first2; + let last2; const types = []; for (const sig of signatures) { const pred = getTypePredicateOfSignature(sig); - if (!pred || pred.kind === 2 /* AssertsThis */ || pred.kind === 3 /* AssertsIdentifier */) { - if (kind !== 2097152 /* Intersection */) { - continue; - } else { - return; - } - } - if (first2) { - if (!typePredicateKindsMatch(first2, pred)) { + if (pred) { + if (pred.kind !== 0 /* This */ && pred.kind !== 1 /* Identifier */ || last2 && !typePredicateKindsMatch(last2, pred)) { return void 0; } + last2 = pred; + types.push(pred.type); } else { - first2 = pred; + const returnType = kind !== 2097152 /* Intersection */ ? getReturnTypeOfSignature(sig) : void 0; + if (returnType !== falseType && returnType !== regularFalseType) { + return void 0; + } } - types.push(pred.type); } - if (!first2) { + if (!last2) { return void 0; } const compositeType = getUnionOrIntersectionType(types, kind); - return createTypePredicate(first2.kind, first2.parameterName, first2.parameterIndex, compositeType); + return createTypePredicate(last2.kind, last2.parameterName, last2.parameterIndex, compositeType); } function typePredicateKindsMatch(a, b) { return a.kind === b.kind && a.parameterIndex === b.parameterIndex; @@ -62739,18 +62737,19 @@ function createTypeChecker(host) { case 185 /* TypeQuery */: const entityName = node2.exprName; const firstIdentifier = getFirstIdentifier(entityName); - const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); - const tpDeclaration = tp.symbol.declarations[0]; - let tpScope; - if (tpDeclaration.kind === 167 /* TypeParameter */) { - tpScope = tpDeclaration.parent; - } else if (tp.isThisType) { - tpScope = tpDeclaration; - } else { - return true; - } - if (firstIdentifierSymbol.declarations) { - return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + if (!isThisIdentifier(firstIdentifier)) { + const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); + const tpDeclaration = tp.symbol.declarations[0]; + const tpScope = tpDeclaration.kind === 167 /* TypeParameter */ ? tpDeclaration.parent : ( + // Type parameter is a regular type parameter, e.g. foo + tp.isThisType ? tpDeclaration : ( + // Type parameter is the this type, and its declaration is the class declaration. + void 0 + ) + ); + if (firstIdentifierSymbol.declarations && tpScope) { + return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + } } return true; case 173 /* MethodDeclaration */: @@ -86289,7 +86288,7 @@ function createTypeChecker(host) { if (requestedExternalEmitHelperNames.has(name)) continue; requestedExternalEmitHelperNames.add(name); - const symbol = getSymbol2(helpersModule.exports, escapeLeadingUnderscores(name), 111551 /* Value */); + const symbol = resolveSymbol(getSymbol2(getExportsOfModule(helpersModule), escapeLeadingUnderscores(name), 111551 /* Value */)); if (!symbol) { error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name); } else if (helper & 524288 /* ClassPrivateFieldGet */) { @@ -136456,15 +136455,18 @@ registerRefactor(refactorNameForMoveToFile, { Debug.assert(actionName2 === refactorNameForMoveToFile, "Wrong refactor invoked"); const statements = Debug.checkDefined(getStatementsToMove(context)); Debug.assert(interactiveRefactorArguments, "No interactive refactor arguments available"); - const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences)); - return { edits, renameFilename: void 0, renameLocation: void 0 }; + const targetFile = interactiveRefactorArguments.targetFile; + if (hasJSFileExtension(targetFile) || hasTSFileExtension(targetFile)) { + const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences)); + return { edits, renameFilename: void 0, renameLocation: void 0 }; + } + return { edits: [], renameFilename: void 0, renameLocation: void 0, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Cannot_move_to_file_selected_file_is_invalid) }; } }); function doChange4(context, oldFile, targetFile, program, toMove, changes, host, preferences) { - var _a; const checker = program.getTypeChecker(); const usage = getUsageInfo(oldFile, toMove.all, checker); - if (!host.fileExists(targetFile) || host.fileExists(targetFile) && ((_a = program.getSourceFile(targetFile)) == null ? void 0 : _a.statements.length) === 0) { + if (!host.fileExists(targetFile)) { changes.createNewFile(oldFile, targetFile, getNewStatementsAndRemoveFromOldFile2(oldFile, targetFile, usage, changes, toMove, program, host, preferences)); addNewFileToTsconfig(program, changes, oldFile.fileName, targetFile, hostGetCanonicalFileName(host)); } else { @@ -136502,6 +136504,13 @@ function getNewStatementsAndRemoveFromOldFile2(oldFile, targetFile, usage, chang if (typeof targetFile !== "string") { if (targetFile.statements.length > 0) { changes.insertNodesAfter(targetFile, targetFile.statements[targetFile.statements.length - 1], body); + } else { + changes.insertNodesAtEndOfFile( + targetFile, + body, + /*blankLineBetween*/ + false + ); } if (imports.length > 0) { insertImports( @@ -141839,7 +141848,11 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h onUnRecoverableConfigFileDiagnostic: noop }; const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings); + let releasedScriptKinds = /* @__PURE__ */ new Set(); if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) { + compilerHost = void 0; + parsedCommandLines = void 0; + releasedScriptKinds = void 0; return; } const options = { @@ -141852,6 +141865,7 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h program = createProgram(options); compilerHost = void 0; parsedCommandLines = void 0; + releasedScriptKinds = void 0; sourceMapper.clearCache(); program.getTypeChecker(); return; @@ -141906,10 +141920,11 @@ function createLanguageService(host, documentRegistry = createDocumentRegistry(h if (!shouldCreateNewSourceFile) { const oldSourceFile = program && program.getSourceFileByPath(path); if (oldSourceFile) { - if (scriptKind === oldSourceFile.scriptKind) { + if (scriptKind === oldSourceFile.scriptKind || releasedScriptKinds.has(oldSourceFile.resolvedPath)) { return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions); } else { documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat); + releasedScriptKinds.add(oldSourceFile.resolvedPath); } } } @@ -165853,6 +165868,17 @@ var ChangeTracker = class { this.insertNodeAt(sourceFile, pos, insert, options); } } + insertNodesAtEndOfFile(sourceFile, newNodes, blankLineBetween) { + this.insertAtEndOfFile(sourceFile, newNodes, blankLineBetween); + } + insertAtEndOfFile(sourceFile, insert, blankLineBetween) { + const pos = sourceFile.end + 1; + const options = { + prefix: this.newLineCharacter, + suffix: this.newLineCharacter + (blankLineBetween ? this.newLineCharacter : "") + }; + this.insertNodesAt(sourceFile, pos, insert, options); + } insertStatementsInNewFile(fileName, statements, oldFile) { if (!this.newFileChanges) { this.newFileChanges = createMultiMap(); @@ -181964,7 +181990,8 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter return { renameLocation: mappedRenameLocation, renameFilename, - edits: this.mapTextChangesToCodeEdits(edits) + edits: this.mapTextChangesToCodeEdits(edits), + notApplicableReason: result.notApplicableReason }; } return result; diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 870d881644902..ca20adbcc9179 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -619,6 +619,7 @@ declare namespace ts { */ renameLocation?: Location; renameFilename?: string; + notApplicableReason?: string; } /** * Organize imports by: @@ -10190,7 +10191,7 @@ declare namespace ts { * arguments for any interactive action before offering it. */ getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string, includeInteractiveActions?: boolean): ApplicableRefactorInfo[]; - getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined, includeInteractiveActions?: InteractiveRefactorArguments): RefactorEditInfo | undefined; + getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined, interactiveRefactorArguments?: InteractiveRefactorArguments): RefactorEditInfo | undefined; getMoveToRefactoringFileSuggestions(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string): { newFileName: string; files: string[]; @@ -10480,6 +10481,7 @@ declare namespace ts { renameFilename?: string; renameLocation?: number; commands?: CodeActionCommand[]; + notApplicableReason?: string; } type RefactorTriggerReason = "implicit" | "invoked"; interface TextInsertion { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 22e446c17b457..872b4a4bd1fed 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -35,7 +35,7 @@ var ts = (() => { "src/compiler/corePublic.ts"() { "use strict"; versionMajorMinor = "5.1"; - version = "5.1.1-rc"; + version = "5.1.3"; Comparison = /* @__PURE__ */ ((Comparison3) => { Comparison3[Comparison3["LessThan"] = -1] = "LessThan"; Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo"; @@ -9018,6 +9018,7 @@ ${lanes.join("\n")} Convert_typedef_to_TypeScript_type: diag(95176, 3 /* Message */, "Convert_typedef_to_TypeScript_type_95176", "Convert typedef to TypeScript type."), Convert_all_typedef_to_TypeScript_types: diag(95177, 3 /* Message */, "Convert_all_typedef_to_TypeScript_types_95177", "Convert all typedef to TypeScript types."), Move_to_file: diag(95178, 3 /* Message */, "Move_to_file_95178", "Move to file"), + Cannot_move_to_file_selected_file_is_invalid: diag(95179, 3 /* Message */, "Cannot_move_to_file_selected_file_is_invalid_95179", "Cannot move to file, selected file is invalid"), No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, 1 /* Error */, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."), Classes_may_not_have_a_field_named_constructor: diag(18006, 1 /* Error */, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."), JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, 1 /* Error */, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"), @@ -56426,7 +56427,7 @@ ${lanes.join("\n")} } else if (type !== firstType) { checkFlags |= 64 /* HasNonUniformType */; } - if (isLiteralType(type) || isPatternLiteralType(type) || type === uniqueLiteralType) { + if (isLiteralType(type) || isPatternLiteralType(type)) { checkFlags |= 128 /* HasLiteralType */; } if (type.flags & 131072 /* Never */ && type !== uniqueLiteralType) { @@ -58625,31 +58626,28 @@ ${lanes.join("\n")} return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin); } function getUnionOrIntersectionTypePredicate(signatures, kind) { - let first2; + let last2; const types = []; for (const sig of signatures) { const pred = getTypePredicateOfSignature(sig); - if (!pred || pred.kind === 2 /* AssertsThis */ || pred.kind === 3 /* AssertsIdentifier */) { - if (kind !== 2097152 /* Intersection */) { - continue; - } else { - return; - } - } - if (first2) { - if (!typePredicateKindsMatch(first2, pred)) { + if (pred) { + if (pred.kind !== 0 /* This */ && pred.kind !== 1 /* Identifier */ || last2 && !typePredicateKindsMatch(last2, pred)) { return void 0; } + last2 = pred; + types.push(pred.type); } else { - first2 = pred; + const returnType = kind !== 2097152 /* Intersection */ ? getReturnTypeOfSignature(sig) : void 0; + if (returnType !== falseType && returnType !== regularFalseType) { + return void 0; + } } - types.push(pred.type); } - if (!first2) { + if (!last2) { return void 0; } const compositeType = getUnionOrIntersectionType(types, kind); - return createTypePredicate(first2.kind, first2.parameterName, first2.parameterIndex, compositeType); + return createTypePredicate(last2.kind, last2.parameterName, last2.parameterIndex, compositeType); } function typePredicateKindsMatch(a, b) { return a.kind === b.kind && a.parameterIndex === b.parameterIndex; @@ -60530,18 +60528,19 @@ ${lanes.join("\n")} case 185 /* TypeQuery */: const entityName = node2.exprName; const firstIdentifier = getFirstIdentifier(entityName); - const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); - const tpDeclaration = tp.symbol.declarations[0]; - let tpScope; - if (tpDeclaration.kind === 167 /* TypeParameter */) { - tpScope = tpDeclaration.parent; - } else if (tp.isThisType) { - tpScope = tpDeclaration; - } else { - return true; - } - if (firstIdentifierSymbol.declarations) { - return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + if (!isThisIdentifier(firstIdentifier)) { + const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); + const tpDeclaration = tp.symbol.declarations[0]; + const tpScope = tpDeclaration.kind === 167 /* TypeParameter */ ? tpDeclaration.parent : ( + // Type parameter is a regular type parameter, e.g. foo + tp.isThisType ? tpDeclaration : ( + // Type parameter is the this type, and its declaration is the class declaration. + void 0 + ) + ); + if (firstIdentifierSymbol.declarations && tpScope) { + return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + } } return true; case 173 /* MethodDeclaration */: @@ -84080,7 +84079,7 @@ ${lanes.join("\n")} if (requestedExternalEmitHelperNames.has(name)) continue; requestedExternalEmitHelperNames.add(name); - const symbol = getSymbol2(helpersModule.exports, escapeLeadingUnderscores(name), 111551 /* Value */); + const symbol = resolveSymbol(getSymbol2(getExportsOfModule(helpersModule), escapeLeadingUnderscores(name), 111551 /* Value */)); if (!symbol) { error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name); } else if (helper & 524288 /* ClassPrivateFieldGet */) { @@ -134844,10 +134843,9 @@ ${lanes.join("\n")} // src/services/refactors/moveToFile.ts function doChange4(context, oldFile, targetFile, program, toMove, changes, host, preferences) { - var _a; const checker = program.getTypeChecker(); const usage = getUsageInfo(oldFile, toMove.all, checker); - if (!host.fileExists(targetFile) || host.fileExists(targetFile) && ((_a = program.getSourceFile(targetFile)) == null ? void 0 : _a.statements.length) === 0) { + if (!host.fileExists(targetFile)) { changes.createNewFile(oldFile, targetFile, getNewStatementsAndRemoveFromOldFile2(oldFile, targetFile, usage, changes, toMove, program, host, preferences)); addNewFileToTsconfig(program, changes, oldFile.fileName, targetFile, hostGetCanonicalFileName(host)); } else { @@ -134885,6 +134883,13 @@ ${lanes.join("\n")} if (typeof targetFile !== "string") { if (targetFile.statements.length > 0) { changes.insertNodesAfter(targetFile, targetFile.statements[targetFile.statements.length - 1], body); + } else { + changes.insertNodesAtEndOfFile( + targetFile, + body, + /*blankLineBetween*/ + false + ); } if (imports.length > 0) { insertImports( @@ -135703,8 +135708,12 @@ ${lanes.join("\n")} Debug.assert(actionName2 === refactorNameForMoveToFile, "Wrong refactor invoked"); const statements = Debug.checkDefined(getStatementsToMove(context)); Debug.assert(interactiveRefactorArguments, "No interactive refactor arguments available"); - const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences)); - return { edits, renameFilename: void 0, renameLocation: void 0 }; + const targetFile = interactiveRefactorArguments.targetFile; + if (hasJSFileExtension(targetFile) || hasTSFileExtension(targetFile)) { + const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences)); + return { edits, renameFilename: void 0, renameLocation: void 0 }; + } + return { edits: [], renameFilename: void 0, renameLocation: void 0, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Cannot_move_to_file_selected_file_is_invalid) }; } }); } @@ -139783,7 +139792,11 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} onUnRecoverableConfigFileDiagnostic: noop }; const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings); + let releasedScriptKinds = /* @__PURE__ */ new Set(); if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) { + compilerHost = void 0; + parsedCommandLines = void 0; + releasedScriptKinds = void 0; return; } const options = { @@ -139796,6 +139809,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} program = createProgram(options); compilerHost = void 0; parsedCommandLines = void 0; + releasedScriptKinds = void 0; sourceMapper.clearCache(); program.getTypeChecker(); return; @@ -139850,10 +139864,11 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} if (!shouldCreateNewSourceFile) { const oldSourceFile = program && program.getSourceFileByPath(path); if (oldSourceFile) { - if (scriptKind === oldSourceFile.scriptKind) { + if (scriptKind === oldSourceFile.scriptKind || releasedScriptKinds.has(oldSourceFile.resolvedPath)) { return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions); } else { documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat); + releasedScriptKinds.add(oldSourceFile.resolvedPath); } } } @@ -165722,6 +165737,17 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} this.insertNodeAt(sourceFile, pos, insert, options); } } + insertNodesAtEndOfFile(sourceFile, newNodes, blankLineBetween) { + this.insertAtEndOfFile(sourceFile, newNodes, blankLineBetween); + } + insertAtEndOfFile(sourceFile, insert, blankLineBetween) { + const pos = sourceFile.end + 1; + const options = { + prefix: this.newLineCharacter, + suffix: this.newLineCharacter + (blankLineBetween ? this.newLineCharacter : "") + }; + this.insertNodesAt(sourceFile, pos, insert, options); + } insertStatementsInNewFile(fileName, statements, oldFile) { if (!this.newFileChanges) { this.newFileChanges = createMultiMap(); @@ -179401,7 +179427,8 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter return { renameLocation: mappedRenameLocation, renameFilename, - edits: this.mapTextChangesToCodeEdits(edits) + edits: this.mapTextChangesToCodeEdits(edits), + notApplicableReason: result.notApplicableReason }; } return result; diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 862560ba05a7d..0dae9f82541a3 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -6227,7 +6227,7 @@ declare namespace ts { * arguments for any interactive action before offering it. */ getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string, includeInteractiveActions?: boolean): ApplicableRefactorInfo[]; - getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined, includeInteractiveActions?: InteractiveRefactorArguments): RefactorEditInfo | undefined; + getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined, interactiveRefactorArguments?: InteractiveRefactorArguments): RefactorEditInfo | undefined; getMoveToRefactoringFileSuggestions(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string): { newFileName: string; files: string[]; @@ -6517,6 +6517,7 @@ declare namespace ts { renameFilename?: string; renameLocation?: number; commands?: CodeActionCommand[]; + notApplicableReason?: string; } type RefactorTriggerReason = "implicit" | "invoked"; interface TextInsertion { diff --git a/lib/typescript.js b/lib/typescript.js index 87906a6ebe268..3e038fb51b5e6 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -35,7 +35,7 @@ var ts = (() => { "src/compiler/corePublic.ts"() { "use strict"; versionMajorMinor = "5.1"; - version = "5.1.1-rc"; + version = "5.1.3"; Comparison = /* @__PURE__ */ ((Comparison3) => { Comparison3[Comparison3["LessThan"] = -1] = "LessThan"; Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo"; @@ -9018,6 +9018,7 @@ ${lanes.join("\n")} Convert_typedef_to_TypeScript_type: diag(95176, 3 /* Message */, "Convert_typedef_to_TypeScript_type_95176", "Convert typedef to TypeScript type."), Convert_all_typedef_to_TypeScript_types: diag(95177, 3 /* Message */, "Convert_all_typedef_to_TypeScript_types_95177", "Convert all typedef to TypeScript types."), Move_to_file: diag(95178, 3 /* Message */, "Move_to_file_95178", "Move to file"), + Cannot_move_to_file_selected_file_is_invalid: diag(95179, 3 /* Message */, "Cannot_move_to_file_selected_file_is_invalid_95179", "Cannot move to file, selected file is invalid"), No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, 1 /* Error */, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."), Classes_may_not_have_a_field_named_constructor: diag(18006, 1 /* Error */, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."), JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, 1 /* Error */, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"), @@ -56426,7 +56427,7 @@ ${lanes.join("\n")} } else if (type !== firstType) { checkFlags |= 64 /* HasNonUniformType */; } - if (isLiteralType(type) || isPatternLiteralType(type) || type === uniqueLiteralType) { + if (isLiteralType(type) || isPatternLiteralType(type)) { checkFlags |= 128 /* HasLiteralType */; } if (type.flags & 131072 /* Never */ && type !== uniqueLiteralType) { @@ -58625,31 +58626,28 @@ ${lanes.join("\n")} return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin); } function getUnionOrIntersectionTypePredicate(signatures, kind) { - let first2; + let last2; const types = []; for (const sig of signatures) { const pred = getTypePredicateOfSignature(sig); - if (!pred || pred.kind === 2 /* AssertsThis */ || pred.kind === 3 /* AssertsIdentifier */) { - if (kind !== 2097152 /* Intersection */) { - continue; - } else { - return; - } - } - if (first2) { - if (!typePredicateKindsMatch(first2, pred)) { + if (pred) { + if (pred.kind !== 0 /* This */ && pred.kind !== 1 /* Identifier */ || last2 && !typePredicateKindsMatch(last2, pred)) { return void 0; } + last2 = pred; + types.push(pred.type); } else { - first2 = pred; + const returnType = kind !== 2097152 /* Intersection */ ? getReturnTypeOfSignature(sig) : void 0; + if (returnType !== falseType && returnType !== regularFalseType) { + return void 0; + } } - types.push(pred.type); } - if (!first2) { + if (!last2) { return void 0; } const compositeType = getUnionOrIntersectionType(types, kind); - return createTypePredicate(first2.kind, first2.parameterName, first2.parameterIndex, compositeType); + return createTypePredicate(last2.kind, last2.parameterName, last2.parameterIndex, compositeType); } function typePredicateKindsMatch(a, b) { return a.kind === b.kind && a.parameterIndex === b.parameterIndex; @@ -60530,18 +60528,19 @@ ${lanes.join("\n")} case 185 /* TypeQuery */: const entityName = node2.exprName; const firstIdentifier = getFirstIdentifier(entityName); - const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); - const tpDeclaration = tp.symbol.declarations[0]; - let tpScope; - if (tpDeclaration.kind === 167 /* TypeParameter */) { - tpScope = tpDeclaration.parent; - } else if (tp.isThisType) { - tpScope = tpDeclaration; - } else { - return true; - } - if (firstIdentifierSymbol.declarations) { - return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + if (!isThisIdentifier(firstIdentifier)) { + const firstIdentifierSymbol = getResolvedSymbol(firstIdentifier); + const tpDeclaration = tp.symbol.declarations[0]; + const tpScope = tpDeclaration.kind === 167 /* TypeParameter */ ? tpDeclaration.parent : ( + // Type parameter is a regular type parameter, e.g. foo + tp.isThisType ? tpDeclaration : ( + // Type parameter is the this type, and its declaration is the class declaration. + void 0 + ) + ); + if (firstIdentifierSymbol.declarations && tpScope) { + return some(firstIdentifierSymbol.declarations, (idDecl) => isNodeDescendantOf(idDecl, tpScope)) || some(node2.typeArguments, containsReference); + } } return true; case 173 /* MethodDeclaration */: @@ -84080,7 +84079,7 @@ ${lanes.join("\n")} if (requestedExternalEmitHelperNames.has(name)) continue; requestedExternalEmitHelperNames.add(name); - const symbol = getSymbol2(helpersModule.exports, escapeLeadingUnderscores(name), 111551 /* Value */); + const symbol = resolveSymbol(getSymbol2(getExportsOfModule(helpersModule), escapeLeadingUnderscores(name), 111551 /* Value */)); if (!symbol) { error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name); } else if (helper & 524288 /* ClassPrivateFieldGet */) { @@ -134859,10 +134858,9 @@ ${lanes.join("\n")} // src/services/refactors/moveToFile.ts function doChange4(context, oldFile, targetFile, program, toMove, changes, host, preferences) { - var _a; const checker = program.getTypeChecker(); const usage = getUsageInfo(oldFile, toMove.all, checker); - if (!host.fileExists(targetFile) || host.fileExists(targetFile) && ((_a = program.getSourceFile(targetFile)) == null ? void 0 : _a.statements.length) === 0) { + if (!host.fileExists(targetFile)) { changes.createNewFile(oldFile, targetFile, getNewStatementsAndRemoveFromOldFile2(oldFile, targetFile, usage, changes, toMove, program, host, preferences)); addNewFileToTsconfig(program, changes, oldFile.fileName, targetFile, hostGetCanonicalFileName(host)); } else { @@ -134900,6 +134898,13 @@ ${lanes.join("\n")} if (typeof targetFile !== "string") { if (targetFile.statements.length > 0) { changes.insertNodesAfter(targetFile, targetFile.statements[targetFile.statements.length - 1], body); + } else { + changes.insertNodesAtEndOfFile( + targetFile, + body, + /*blankLineBetween*/ + false + ); } if (imports.length > 0) { insertImports( @@ -135718,8 +135723,12 @@ ${lanes.join("\n")} Debug.assert(actionName2 === refactorNameForMoveToFile, "Wrong refactor invoked"); const statements = Debug.checkDefined(getStatementsToMove(context)); Debug.assert(interactiveRefactorArguments, "No interactive refactor arguments available"); - const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences)); - return { edits, renameFilename: void 0, renameLocation: void 0 }; + const targetFile = interactiveRefactorArguments.targetFile; + if (hasJSFileExtension(targetFile) || hasTSFileExtension(targetFile)) { + const edits = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange4(context, context.file, interactiveRefactorArguments.targetFile, context.program, statements, t, context.host, context.preferences)); + return { edits, renameFilename: void 0, renameLocation: void 0 }; + } + return { edits: [], renameFilename: void 0, renameLocation: void 0, notApplicableReason: getLocaleSpecificMessage(Diagnostics.Cannot_move_to_file_selected_file_is_invalid) }; } }); } @@ -139798,7 +139807,11 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} onUnRecoverableConfigFileDiagnostic: noop }; const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings); + let releasedScriptKinds = /* @__PURE__ */ new Set(); if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), (fileName) => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasInvalidatedLibResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) { + compilerHost = void 0; + parsedCommandLines = void 0; + releasedScriptKinds = void 0; return; } const options = { @@ -139811,6 +139824,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} program = createProgram(options); compilerHost = void 0; parsedCommandLines = void 0; + releasedScriptKinds = void 0; sourceMapper.clearCache(); program.getTypeChecker(); return; @@ -139865,10 +139879,11 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} if (!shouldCreateNewSourceFile) { const oldSourceFile = program && program.getSourceFileByPath(path); if (oldSourceFile) { - if (scriptKind === oldSourceFile.scriptKind) { + if (scriptKind === oldSourceFile.scriptKind || releasedScriptKinds.has(oldSourceFile.resolvedPath)) { return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind, languageVersionOrOptions); } else { documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions()), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat); + releasedScriptKinds.add(oldSourceFile.resolvedPath); } } } @@ -165737,6 +165752,17 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")} this.insertNodeAt(sourceFile, pos, insert, options); } } + insertNodesAtEndOfFile(sourceFile, newNodes, blankLineBetween) { + this.insertAtEndOfFile(sourceFile, newNodes, blankLineBetween); + } + insertAtEndOfFile(sourceFile, insert, blankLineBetween) { + const pos = sourceFile.end + 1; + const options = { + prefix: this.newLineCharacter, + suffix: this.newLineCharacter + (blankLineBetween ? this.newLineCharacter : "") + }; + this.insertNodesAt(sourceFile, pos, insert, options); + } insertStatementsInNewFile(fileName, statements, oldFile) { if (!this.newFileChanges) { this.newFileChanges = createMultiMap(); diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 5f70f8de5fb60..e29b10166c898 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -54,7 +54,7 @@ var path = __toESM(require("path")); // src/compiler/corePublic.ts var versionMajorMinor = "5.1"; -var version = "5.1.1-rc"; +var version = "5.1.3"; // src/compiler/core.ts var emptyArray = []; @@ -7078,6 +7078,7 @@ var Diagnostics = { Convert_typedef_to_TypeScript_type: diag(95176, 3 /* Message */, "Convert_typedef_to_TypeScript_type_95176", "Convert typedef to TypeScript type."), Convert_all_typedef_to_TypeScript_types: diag(95177, 3 /* Message */, "Convert_all_typedef_to_TypeScript_types_95177", "Convert all typedef to TypeScript types."), Move_to_file: diag(95178, 3 /* Message */, "Move_to_file_95178", "Move to file"), + Cannot_move_to_file_selected_file_is_invalid: diag(95179, 3 /* Message */, "Cannot_move_to_file_selected_file_is_invalid_95179", "Cannot move to file, selected file is invalid"), No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer: diag(18004, 1 /* Error */, "No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer_18004", "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer."), Classes_may_not_have_a_field_named_constructor: diag(18006, 1 /* Error */, "Classes_may_not_have_a_field_named_constructor_18006", "Classes may not have a field named 'constructor'."), JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array: diag(18007, 1 /* Error */, "JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array_18007", "JSX expressions may not use the comma operator. Did you mean to write an array?"), diff --git a/package.json b/package.json index 6226e1cd7e9f5..291ad5fbf1745 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "5.1.1-rc", + "version": "5.1.3", "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 98acdaa9d18e9..0109115ede21d 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -4,7 +4,7 @@ export const versionMajorMinor = "5.1"; // 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 = "5.1.1-rc" as string; +export const version = "5.1.3" as string; /** * Type of objects whose values are all of the same type.