File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -273,6 +273,13 @@ let i: I = [#|{ a: 1 }|];
273273const myObj: { member(x: number, y: string): void } = {
274274 member: [#|(x, y) => x + y|],
275275}
276+ ` ) ;
277+
278+ testExtractConstant ( "extractConstant_CaseClauseExpression" , `
279+ switch (1) {
280+ case [#|1|]:
281+ break;
282+ }
276283` ) ;
277284 } ) ;
278285
Original file line number Diff line number Diff line change @@ -1321,6 +1321,13 @@ namespace ts.refactor.extractSymbol {
13211321 }
13221322 prevStatement = statement ;
13231323 }
1324+
1325+ if ( ! prevStatement && isCaseClause ( curr ) ) {
1326+ // We must have been in the expression of the case clause.
1327+ Debug . assert ( isSwitchStatement ( curr . parent . parent ) ) ;
1328+ return curr . parent . parent ;
1329+ }
1330+
13241331 // There must be at least one statement since we started in one.
13251332 Debug . assert ( prevStatement !== undefined ) ;
13261333 return prevStatement ;
Original file line number Diff line number Diff line change 1+ // ==ORIGINAL==
2+
3+ switch ( 1 ) {
4+ case /*[#|*/ 1 /*|]*/ :
5+ break ;
6+ }
7+
8+ // ==SCOPE::Extract to constant in enclosing scope==
9+ const newLocal = 1 ;
10+ switch ( 1 ) {
11+ case /*RENAME*/ newLocal :
12+ break ;
13+ }
Original file line number Diff line number Diff line change 1+ // ==ORIGINAL==
2+
3+ switch ( 1 ) {
4+ case /*[#|*/ 1 /*|]*/ :
5+ break ;
6+ }
7+
8+ // ==SCOPE::Extract to constant in enclosing scope==
9+ const newLocal = 1 ;
10+ switch ( 1 ) {
11+ case /*RENAME*/ newLocal :
12+ break ;
13+ }
You can’t perform that action at this time.
0 commit comments