mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -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;
|
||||
|
||||
Reference in New Issue
Block a user