@@ -1086,17 +1086,18 @@ namespace ts {
10861086 return isCallExpression ( node ) && ! ! ( node . flags & NodeFlags . OptionalChain ) ;
10871087 }
10881088
1089- export function isOptionalChain ( node : Node ) : node is PropertyAccessChain | ElementAccessChain | CallChain {
1089+ export function isOptionalChain ( node : Node ) : node is PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain {
10901090 const kind = node . kind ;
10911091 return ! ! ( node . flags & NodeFlags . OptionalChain ) &&
10921092 ( kind === SyntaxKind . PropertyAccessExpression
10931093 || kind === SyntaxKind . ElementAccessExpression
1094- || kind === SyntaxKind . CallExpression ) ;
1094+ || kind === SyntaxKind . CallExpression
1095+ || kind === SyntaxKind . NonNullExpression ) ;
10951096 }
10961097
10971098 /* @internal */
10981099 export function isOptionalChainRoot ( node : Node ) : node is OptionalChainRoot {
1099- return isOptionalChain ( node ) && ! ! node . questionDotToken ;
1100+ return isOptionalChain ( node ) && ! isNonNullExpression ( node ) && ! ! node . questionDotToken ;
11001101 }
11011102
11021103 /**
@@ -1111,17 +1112,18 @@ namespace ts {
11111112 * Determines whether a node is the outermost `OptionalChain` in an ECMAScript `OptionalExpression`:
11121113 *
11131114 * 1. For `a?.b.c`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.`)
1114- * 2. For `(a?.b.c).d`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.` since parens end the chain)
1115- * 3. For `a?.b.c?.d`, both `a?.b.c` and `a?.b.c?.d` are outermost (`c` is the end of the chain starting at `a?.`, and `d` is
1115+ * 2. For `a?.b!`, the outermost chain is `a?.b!` (`c` is the end of the chain starting at `a?.`)
1116+ * 3. For `(a?.b.c).d`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.` since parens end the chain)
1117+ * 4. For `a?.b.c?.d`, both `a?.b.c` and `a?.b.c?.d` are outermost (`c` is the end of the chain starting at `a?.`, and `d` is
11161118 * the end of the chain starting at `c?.`)
1117- * 4 . For `a?.(b?.c).d`, both `b?.c` and `a?.(b?.c)d` are outermost (`c` is the end of the chain starting at `b`, and `d` is
1119+ * 5 . For `a?.(b?.c).d`, both `b?.c` and `a?.(b?.c)d` are outermost (`c` is the end of the chain starting at `b`, and `d` is
11181120 * the end of the chain starting at `a?.`)
11191121 */
11201122 /* @internal */
11211123 export function isOutermostOptionalChain ( node : OptionalChain ) {
1122- return ! isOptionalChain ( node . parent ) // cases 1 and 2
1123- || isOptionalChainRoot ( node . parent ) // case 3
1124- || node !== node . parent . expression ; // case 4
1124+ return ! isOptionalChain ( node . parent ) // cases 1, 2, and 3
1125+ || isOptionalChainRoot ( node . parent ) // case 4
1126+ || node !== node . parent . expression ; // case 5
11251127 }
11261128
11271129 export function isNullishCoalesce ( node : Node ) {
@@ -1152,11 +1154,7 @@ namespace ts {
11521154 export function skipPartiallyEmittedExpressions ( node : Expression ) : Expression ;
11531155 export function skipPartiallyEmittedExpressions ( node : Node ) : Node ;
11541156 export function skipPartiallyEmittedExpressions ( node : Node ) {
1155- while ( node . kind === SyntaxKind . PartiallyEmittedExpression ) {
1156- node = ( < PartiallyEmittedExpression > node ) . expression ;
1157- }
1158-
1159- return node ;
1157+ return skipOuterExpressions ( node , OuterExpressionKinds . PartiallyEmittedExpressions ) ;
11601158 }
11611159
11621160 export function isFunctionExpression ( node : Node ) : node is FunctionExpression {
@@ -1231,6 +1229,10 @@ namespace ts {
12311229 return node . kind === SyntaxKind . NonNullExpression ;
12321230 }
12331231
1232+ export function isNonNullChain ( node : Node ) : node is NonNullChain {
1233+ return isNonNullExpression ( node ) && ! ! ( node . flags & NodeFlags . OptionalChain ) ;
1234+ }
1235+
12341236 export function isMetaProperty ( node : Node ) : node is MetaProperty {
12351237 return node . kind === SyntaxKind . MetaProperty ;
12361238 }
0 commit comments