mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
fix(54982): "Inline variable" causes failure when variable is used as the initializer of a destructured variable declaration (#54988)
This commit is contained in:
parent
02e8d5ec61
commit
f7a93c83ca
@ -132,7 +132,7 @@ function getInliningInfo(file: SourceFile, startPosition: number, tryWithReferen
|
||||
|
||||
// If triggered in a variable declaration, make sure it's not in a catch clause or for-loop
|
||||
// and that it has a value.
|
||||
if (isInitializedVariable(parent) && isVariableDeclarationInVariableStatement(parent)) {
|
||||
if (isInitializedVariable(parent) && isVariableDeclarationInVariableStatement(parent) && isIdentifier(parent.name)) {
|
||||
// Don't inline the variable if it has multiple declarations.
|
||||
if (checker.getMergedSymbol(parent.symbol).declarations?.length !== 1) {
|
||||
return { error: getLocaleSpecificMessage(Diagnostics.Variables_with_multiple_declarations_cannot_be_inlined) };
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////export function Component(props: any) {
|
||||
//// const { foo } = /*a*/props/*b*/;
|
||||
////}
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Inline variable");
|
||||
@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////export function func(arr: any) {
|
||||
//// const [foo] = /*a*/arr/*b*/;
|
||||
////}
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Inline variable");
|
||||
@ -0,0 +1,9 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////function f() {
|
||||
//// const a = { prop: 123 };
|
||||
//// const { prop } = /*a*/a/*b*/;
|
||||
////}
|
||||
|
||||
goTo.select("a", "b");
|
||||
verify.not.refactorAvailable("Inline variable");
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////function f() {
|
||||
//// const a = { prop: 123 };
|
||||
//// const { prop } = /*a*/a/*b*/;
|
||||
////}
|
||||
goTo.select("a", "b");
|
||||
verify.refactorAvailableForTriggerReason("invoked", "Inline variable");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Inline variable",
|
||||
actionName: "Inline variable",
|
||||
actionDescription: "Inline variable",
|
||||
newContent:
|
||||
`function f() {
|
||||
const { prop } = { prop: 123 };
|
||||
}`,
|
||||
triggerReason: "invoked"
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user