* Check if a cn()/clsx() call has the prefix in a conditional argument.
( args: any[], prefix: string )
| 367 | * Check if a cn()/clsx() call has the prefix in a conditional argument. |
| 368 | */ |
| 369 | function checkConflictingConditional( |
| 370 | args: any[], |
| 371 | prefix: string |
| 372 | ): boolean { |
| 373 | for (const arg of args) { |
| 374 | // LogicalExpression: `active && "bg-blue-500"` |
| 375 | if (arg.type === "LogicalExpression") { |
| 376 | if ( |
| 377 | arg.right?.type === "StringLiteral" && |
| 378 | arg.right.value |
| 379 | .split(/\s+/) |
| 380 | .some((c: string) => classMatchesPrefix(c, prefix)) |
| 381 | ) { |
| 382 | return true; |
| 383 | } |
| 384 | } |
| 385 | // ConditionalExpression: `active ? "bg-blue-500" : "bg-red-500"` |
| 386 | if (arg.type === "ConditionalExpression") { |
| 387 | for (const branch of [arg.consequent, arg.alternate]) { |
| 388 | if ( |
| 389 | branch?.type === "StringLiteral" && |
| 390 | branch.value |
| 391 | .split(/\s+/) |
| 392 | .some((c: string) => classMatchesPrefix(c, prefix)) |
| 393 | ) { |
| 394 | return true; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | return false; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Apply className updates to a JSX element node. |
no test coverage detected