Skip to content

Commit c581ad1

Browse files
committed
ensure angle bracketed type expressions don't leak out of the brackets
1 parent 9bc7425 commit c581ad1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/cognitive-complexity/cognitive-complexity.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ function nodeCost(
238238
}
239239

240240
const opSequenceInProgress = mutCtx.precedingOperator;
241+
const typeOpSequenceInProgress = mutCtx.precedingTypeOperator;
242+
const pauseOpSequence = pausesASequenceOfBinaryOperators(node);
241243

242244
// Check if the node ends any ongoing sequence of binary operators
243245
if (breaksASequenceOfBinaryOperators(node)) {
@@ -258,9 +260,9 @@ function nodeCost(
258260
// Pass along the operator info
259261
else if (isChainableBinaryTypeOperator(node)) {
260262
mutCtx.precedingTypeOperator = node.kind;
261-
}
262-
else if (pausesASequenceOfBinaryOperators(node)) {
263+
} else if (pauseOpSequence) {
263264
mutCtx.precedingOperator = undefined;
265+
mutCtx.precedingTypeOperator = undefined;
264266
}
265267

266268
const ctxForChildrenSameDepth = {
@@ -285,9 +287,10 @@ function nodeCost(
285287

286288
const costOfBelowChildren = aggregateCostOfChildren(below, ctxForChildrenBelow, mutCtx);
287289

288-
if (pausesASequenceOfBinaryOperators(node)) {
289-
// continue whatever sequence we paused
290+
// continue a paused sequence
291+
if (pauseOpSequence) {
290292
mutCtx.precedingOperator = opSequenceInProgress;
293+
mutCtx.precedingTypeOperator = typeOpSequenceInProgress;
291294
}
292295

293296
score += costOfSameDepthChildren.score;

0 commit comments

Comments
 (0)