@@ -1086,17 +1086,18 @@ namespace ts {
1086
1086
return isCallExpression ( node ) && ! ! ( node . flags & NodeFlags . OptionalChain ) ;
1087
1087
}
1088
1088
1089
- export function isOptionalChain ( node : Node ) : node is PropertyAccessChain | ElementAccessChain | CallChain {
1089
+ export function isOptionalChain ( node : Node ) : node is PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain {
1090
1090
const kind = node . kind ;
1091
1091
return ! ! ( node . flags & NodeFlags . OptionalChain ) &&
1092
1092
( kind === SyntaxKind . PropertyAccessExpression
1093
1093
|| kind === SyntaxKind . ElementAccessExpression
1094
- || kind === SyntaxKind . CallExpression ) ;
1094
+ || kind === SyntaxKind . CallExpression
1095
+ || kind === SyntaxKind . NonNullExpression ) ;
1095
1096
}
1096
1097
1097
1098
/* @internal */
1098
1099
export function isOptionalChainRoot ( node : Node ) : node is OptionalChainRoot {
1099
- return isOptionalChain ( node ) && ! ! node . questionDotToken ;
1100
+ return isOptionalChain ( node ) && ! isNonNullExpression ( node ) && ! ! node . questionDotToken ;
1100
1101
}
1101
1102
1102
1103
/**
@@ -1111,17 +1112,18 @@ namespace ts {
1111
1112
* Determines whether a node is the outermost `OptionalChain` in an ECMAScript `OptionalExpression`:
1112
1113
*
1113
1114
* 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` (`b` 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
1116
1118
* 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
1118
1120
* the end of the chain starting at `a?.`)
1119
1121
*/
1120
1122
/* @internal */
1121
1123
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
1125
1127
}
1126
1128
1127
1129
export function isNullishCoalesce ( node : Node ) {
@@ -1152,11 +1154,7 @@ namespace ts {
1152
1154
export function skipPartiallyEmittedExpressions ( node : Expression ) : Expression ;
1153
1155
export function skipPartiallyEmittedExpressions ( node : Node ) : Node ;
1154
1156
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 ) ;
1160
1158
}
1161
1159
1162
1160
export function isFunctionExpression ( node : Node ) : node is FunctionExpression {
@@ -1231,6 +1229,10 @@ namespace ts {
1231
1229
return node . kind === SyntaxKind . NonNullExpression ;
1232
1230
}
1233
1231
1232
+ export function isNonNullChain ( node : Node ) : node is NonNullChain {
1233
+ return isNonNullExpression ( node ) && ! ! ( node . flags & NodeFlags . OptionalChain ) ;
1234
+ }
1235
+
1234
1236
export function isMetaProperty ( node : Node ) : node is MetaProperty {
1235
1237
return node . kind === SyntaxKind . MetaProperty ;
1236
1238
}
0 commit comments