fix(48541): forbid function extraction to arrow function with expression body (#48548)

This commit is contained in:
Oleksandr T
2022-04-04 22:27:49 +03:00
committed by GitHub
parent d5f5c6d61e
commit e02998f70d
8 changed files with 20 additions and 9 deletions

View File

@@ -3529,9 +3529,10 @@ namespace FourSlash {
};
}
public verifyRefactorAvailable(negative: boolean, triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string) {
public verifyRefactorAvailable(negative: boolean, triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string, actionDescription?: string) {
let refactors = this.getApplicableRefactorsAtSelection(triggerReason);
refactors = refactors.filter(r => r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName)));
refactors = refactors.filter(r =>
r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName)) && (actionDescription === undefined || r.actions.some(a => a.description === actionDescription)));
const isAvailable = refactors.length > 0;
if (negative) {

View File

@@ -215,8 +215,8 @@ namespace FourSlashInterface {
this.state.verifyRefactorsAvailable(names);
}
public refactorAvailable(name: string, actionName?: string) {
this.state.verifyRefactorAvailable(this.negative, "implicit", name, actionName);
public refactorAvailable(name: string, actionName?: string, actionDescription?: string) {
this.state.verifyRefactorAvailable(this.negative, "implicit", name, actionName, actionDescription);
}
public refactorAvailableForTriggerReason(triggerReason: ts.RefactorTriggerReason, name: string, actionName?: string) {

View File

@@ -639,7 +639,8 @@ namespace ts.refactor.extractSymbol {
}
function isScope(node: Node): node is Scope {
return isFunctionLikeDeclaration(node) || isSourceFile(node) || isModuleBlock(node) || isClassLike(node);
return isArrowFunction(node) ? isFunctionBody(node.body) :
isFunctionLikeDeclaration(node) || isSourceFile(node) || isModuleBlock(node) || isClassLike(node);
}
/**