@@ -312,6 +312,7 @@ import {
312312 singleOrUndefined ,
313313 skipAlias ,
314314 skipOuterExpressions ,
315+ skipParentheses ,
315316 some ,
316317 SortKind ,
317318 SourceFile ,
@@ -360,6 +361,7 @@ import {
360361 VariableDeclaration ,
361362 visitEachChild ,
362363 VoidExpression ,
364+ walkUpParenthesizedExpressions ,
363365 YieldExpression ,
364366} from "./_namespaces/ts" ;
365367
@@ -3298,7 +3300,7 @@ export function needsParentheses(expression: Expression): boolean {
32983300
32993301/** @internal */
33003302export function getContextualTypeFromParent ( node : Expression , checker : TypeChecker , contextFlags ?: ContextFlags ) : Type | undefined {
3301- const { parent } = node ;
3303+ const parent = walkUpParenthesizedExpressions ( node . parent ) ;
33023304 switch ( parent . kind ) {
33033305 case SyntaxKind . NewExpression :
33043306 return checker . getContextualType ( parent as NewExpression , contextFlags ) ;
@@ -3309,7 +3311,7 @@ export function getContextualTypeFromParent(node: Expression, checker: TypeCheck
33093311 : checker . getContextualType ( node , contextFlags ) ;
33103312 }
33113313 case SyntaxKind . CaseClause :
3312- return ( parent as CaseClause ) . expression === node ? getSwitchedType ( parent as CaseClause , checker ) : undefined ;
3314+ return getSwitchedType ( parent as CaseClause , checker ) ;
33133315 default :
33143316 return checker . getContextualType ( node , contextFlags ) ;
33153317 }
@@ -4098,8 +4100,8 @@ export function newCaseClauseTracker(checker: TypeChecker, clauses: readonly (Ca
40984100
40994101 for ( const clause of clauses ) {
41004102 if ( ! isDefaultClause ( clause ) ) {
4101- if ( isLiteralExpression ( clause . expression ) ) {
4102- const expression = clause . expression ;
4103+ const expression = skipParentheses ( clause . expression ) ;
4104+ if ( isLiteralExpression ( expression ) ) {
41034105 switch ( expression . kind ) {
41044106 case SyntaxKind . NoSubstitutionTemplateLiteral :
41054107 case SyntaxKind . StringLiteral :
0 commit comments