Skip to content

fix: don't inject attributes into comparison operators - #2

Merged
Peyton-Spencer merged 1 commit into
mainfrom
fix/comparison-operators
Feb 8, 2026
Merged

fix: don't inject attributes into comparison operators#2
Peyton-Spencer merged 1 commit into
mainfrom
fix/comparison-operators

Conversation

@Peyton-Spencer

Copy link
Copy Markdown
Contributor

Summary

  • The JSX regex was matching < in less-than comparisons (count() < totalPages, userTier < minimumTier, newIndex < props.images.length) as JSX opening tags, injecting data-solid-source attributes into expressions and causing parse errors
  • Added isLikelyJsx() context checker that walks backwards from each < (skipping whitespace) to determine context:
    • After ), ], quotes → comparison (end of expression)
    • After (, {, =, ?, :, operators → JSX (start of expression)
    • After keyword like return → JSX
    • After any other identifier → comparison
  • Combined with the existing (?<!\w) lookbehind (generics), handles all three false positive classes: generics, comparisons after identifiers, comparisons after function calls

Test plan

  • All 55 tests pass (7 new: comparisons, mixed files, JSX after keywords/operators/ternaries)
  • Build succeeds with clean DTS
  • Verified in ditto-app: bun start produces zero transform errors (previously had errors in useConversationHistory.tsx, Modal.tsx, ImageCarousel.tsx, usePairFeedback.tsx, useModal.tsx, useImageViewer.tsx, useSubjectViewer.tsx)

🤖 Generated with Claude Code

The regex was matching `<` in less-than comparisons like
`count() < totalPages` and `userTier < minimumTier` as JSX tags.

Add isLikelyJsx() context check that walks backwards from each `<`,
skipping whitespace, to determine if it's JSX or a comparison:
- After `)`, `]`, quotes → comparison (end of expression)
- After `(`, `{`, `=`, `?`, `:`, operators → JSX (start of expression)
- After a keyword like `return` → JSX
- After any other identifier → comparison

Combined with the existing (?<!\w) lookbehind (for generics), this
handles all three classes of false positives: generics, comparisons
after identifiers, and comparisons after function calls.

Tested against ditto-app (real-world SolidJS app) with zero errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Peyton-Spencer
Peyton-Spencer merged commit 7d09497 into main Feb 8, 2026
1 check passed
@Peyton-Spencer
Peyton-Spencer deleted the fix/comparison-operators branch February 9, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant