MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / checkConflictingConditional

Function checkConflictingConditional

packages/cli/src/transform.ts:369–400  ·  view source on GitHub ↗

* Check if a cn()/clsx() call has the prefix in a conditional argument.

(
  args: any[],
  prefix: string
)

Source from the content-addressed store, hash-verified

367 * Check if a cn()/clsx() call has the prefix in a conditional argument.
368 */
369function 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.

Callers 1

mutateClassNameFunction · 0.85

Calls 1

classMatchesPrefixFunction · 0.70

Tested by

no test coverage detected