Commit edf7aa9
feat(selector): support &:has(${Component}) same-file selectors (#370)
* feat(selector): support &:has(${Component}) same-file selectors
Transforms `&:has(${StyledIcon})` to `stylex.when.descendant(":is(*)", IconMarker)`,
enabling parent components to conditionally style themselves based on the presence
of a specific child component.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(test): avoid shorthand/longhand conflict in selector-has test case
The previous test used `padding: 8px 16px` (expands to logical `paddingInline`)
with `&:has() { padding-right: 32px }` — the computed-key default lookup doesn't
resolve physical longhands from logical shorthands, causing `default: null`.
Changed to non-conflicting properties (background + color) instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(computed-keys): resolve logical shorthand base values for physical longhands
When a computed-key override targets a physical longhand (e.g. paddingRight)
and the base style uses a logical shorthand (e.g. paddingInline from
`padding: 8px 16px`), the default value lookup now falls back to the
logical shorthand. Previously this produced `default: null`, losing the
base padding.
Restores the original selector-has test case with shorthand + longhand
pattern that exercises this fix.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(selector): bail on compound :has() selectors like &:has(${Icon}):hover
The loose HAS_COMPONENT_SELECTOR_RE regex matched any selector containing
&:has(__SC_EXPR_N__), letting compound forms like &:has(${Icon}):hover bypass
the interpolated-pseudo bailout. This caused them to fall through into the
descendant-component handler, producing invalid output with unresolved
placeholders. Now uses the strict anchored regex so only exact &:has(${Component})
selectors are handled; compound forms correctly bail.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(selector): normalize specificity hacks for :has() detection, bail on unresolvable media
Two review fixes:
- Use specificity-normalized selector for isHasPattern so &&:has(${Icon}) is
correctly detected as a :has() pattern instead of falling through to the
descendant-component handler
- Add state.markBail() in resolveMediaAndEmitComputedKeys when media query
interpolation cannot resolve, preventing lossy transformation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent f8d85d2 commit edf7aa9
File tree
9 files changed
+367
-109
lines changed- src
- __tests__
- internal
- lower-rules
- test-cases
9 files changed
+367
-109
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
100 | 108 | | |
101 | 109 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5633 | 5633 | | |
5634 | 5634 | | |
5635 | 5635 | | |
| 5636 | + | |
| 5637 | + | |
| 5638 | + | |
| 5639 | + | |
| 5640 | + | |
| 5641 | + | |
| 5642 | + | |
| 5643 | + | |
| 5644 | + | |
| 5645 | + | |
| 5646 | + | |
| 5647 | + | |
| 5648 | + | |
| 5649 | + | |
| 5650 | + | |
| 5651 | + | |
| 5652 | + | |
| 5653 | + | |
| 5654 | + | |
| 5655 | + | |
| 5656 | + | |
| 5657 | + | |
| 5658 | + | |
| 5659 | + | |
| 5660 | + | |
| 5661 | + | |
| 5662 | + | |
| 5663 | + | |
| 5664 | + | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
| 5685 | + | |
| 5686 | + | |
| 5687 | + | |
| 5688 | + | |
| 5689 | + | |
| 5690 | + | |
| 5691 | + | |
| 5692 | + | |
| 5693 | + | |
| 5694 | + | |
| 5695 | + | |
| 5696 | + | |
| 5697 | + | |
| 5698 | + | |
| 5699 | + | |
| 5700 | + | |
| 5701 | + | |
| 5702 | + | |
| 5703 | + | |
| 5704 | + | |
| 5705 | + | |
| 5706 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| |||
0 commit comments