@@ -1076,17 +1076,18 @@ namespace ts {
1076
1076
return isCallExpression ( node ) && ! ! ( node . flags & NodeFlags . OptionalChain ) ;
1077
1077
}
1078
1078
1079
- export function isOptionalChain ( node : Node ) : node is PropertyAccessChain | ElementAccessChain | CallChain {
1079
+ export function isOptionalChain ( node : Node ) : node is PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain {
1080
1080
const kind = node . kind ;
1081
1081
return ! ! ( node . flags & NodeFlags . OptionalChain ) &&
1082
1082
( kind === SyntaxKind . PropertyAccessExpression
1083
1083
|| kind === SyntaxKind . ElementAccessExpression
1084
- || kind === SyntaxKind . CallExpression ) ;
1084
+ || kind === SyntaxKind . CallExpression
1085
+ || kind === SyntaxKind . NonNullExpression ) ;
1085
1086
}
1086
1087
1087
1088
/* @internal */
1088
1089
export function isOptionalChainRoot ( node : Node ) : node is OptionalChainRoot {
1089
- return isOptionalChain ( node ) && ! ! node . questionDotToken ;
1090
+ return isOptionalChain ( node ) && ! isNonNullExpression ( node ) && ! ! node . questionDotToken ;
1090
1091
}
1091
1092
1092
1093
/**
@@ -1101,17 +1102,18 @@ namespace ts {
1101
1102
* Determines whether a node is the outermost `OptionalChain` in an ECMAScript `OptionalExpression`:
1102
1103
*
1103
1104
* 1. For `a?.b.c`, the outermost chain is `a?.b.c` (`c` is the end of the chain starting at `a?.`)
1104
- * 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)
1105
- * 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
1105
+ * 2. For `a?.b!`, the outermost chain is `a?.b!` (`c` is the end of the chain starting at `a?.`)
1106
+ * 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)
1107
+ * 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
1106
1108
* the end of the chain starting at `c?.`)
1107
- * 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
1109
+ * 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
1108
1110
* the end of the chain starting at `a?.`)
1109
1111
*/
1110
1112
/* @internal */
1111
1113
export function isOutermostOptionalChain ( node : OptionalChain ) {
1112
- return ! isOptionalChain ( node . parent ) // cases 1 and 2
1113
- || isOptionalChainRoot ( node . parent ) // case 3
1114
- || node !== node . parent . expression ; // case 4
1114
+ return ! isOptionalChain ( node . parent ) // cases 1, 2, and 3
1115
+ || isOptionalChainRoot ( node . parent ) // case 4
1116
+ || node !== node . parent . expression ; // case 5
1115
1117
}
1116
1118
1117
1119
export function isNullishCoalesce ( node : Node ) {
@@ -1142,11 +1144,7 @@ namespace ts {
1142
1144
export function skipPartiallyEmittedExpressions ( node : Expression ) : Expression ;
1143
1145
export function skipPartiallyEmittedExpressions ( node : Node ) : Node ;
1144
1146
export function skipPartiallyEmittedExpressions ( node : Node ) {
1145
- while ( node . kind === SyntaxKind . PartiallyEmittedExpression ) {
1146
- node = ( < PartiallyEmittedExpression > node ) . expression ;
1147
- }
1148
-
1149
- return node ;
1147
+ return skipOuterExpressions ( node , OuterExpressionKinds . PartiallyEmittedExpressions ) ;
1150
1148
}
1151
1149
1152
1150
export function isFunctionExpression ( node : Node ) : node is FunctionExpression {
@@ -1221,6 +1219,10 @@ namespace ts {
1221
1219
return node . kind === SyntaxKind . NonNullExpression ;
1222
1220
}
1223
1221
1222
+ export function isNonNullChain ( node : Node ) : node is NonNullChain {
1223
+ return isNonNullExpression ( node ) && ! ! ( node . flags & NodeFlags . OptionalChain ) ;
1224
+ }
1225
+
1224
1226
export function isMetaProperty ( node : Node ) : node is MetaProperty {
1225
1227
return node . kind === SyntaxKind . MetaProperty ;
1226
1228
}
0 commit comments