mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 10:46:28 -05:00
Handle extracting case clause expression as constant
This commit is contained in:
@@ -273,6 +273,13 @@ let i: I = [#|{ a: 1 }|];
|
||||
const myObj: { member(x: number, y: string): void } = {
|
||||
member: [#|(x, y) => x + y|],
|
||||
}
|
||||
`);
|
||||
|
||||
testExtractConstant("extractConstant_CaseClauseExpression", `
|
||||
switch (1) {
|
||||
case [#|1|]:
|
||||
break;
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
|
||||
@@ -1321,6 +1321,13 @@ namespace ts.refactor.extractSymbol {
|
||||
}
|
||||
prevStatement = statement;
|
||||
}
|
||||
|
||||
if (!prevStatement && isCaseClause(curr)) {
|
||||
// We must have been in the expression of the case clause.
|
||||
Debug.assert(isSwitchStatement(curr.parent.parent));
|
||||
return curr.parent.parent;
|
||||
}
|
||||
|
||||
// There must be at least one statement since we started in one.
|
||||
Debug.assert(prevStatement !== undefined);
|
||||
return prevStatement;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// ==ORIGINAL==
|
||||
|
||||
switch (1) {
|
||||
case /*[#|*/1/*|]*/:
|
||||
break;
|
||||
}
|
||||
|
||||
// ==SCOPE::Extract to constant in enclosing scope==
|
||||
const newLocal = 1;
|
||||
switch (1) {
|
||||
case /*RENAME*/newLocal:
|
||||
break;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// ==ORIGINAL==
|
||||
|
||||
switch (1) {
|
||||
case /*[#|*/1/*|]*/:
|
||||
break;
|
||||
}
|
||||
|
||||
// ==SCOPE::Extract to constant in enclosing scope==
|
||||
const newLocal = 1;
|
||||
switch (1) {
|
||||
case /*RENAME*/newLocal:
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user