Commit 9b0049b
Support prop-based inline style theme access via useTheme() rewriting
When an interpolation accesses props.theme in a conditional expression
that the adapter cannot resolve statically, the codemod now rewrites
props.theme to theme (from useTheme() hook) and emits it as an inline
style, instead of bailing with 'Unsupported prop-based inline style
props.theme access is not supported'.
This supports patterns like:
border-left: ${props =>
props.$isHighlighted ? `2px solid ${props.theme.color.x}` : '2px solid transparent'};
The fix applies to arrow functions with a simple Identifier parameter
(e.g., (props) => ...). Destructured ObjectPattern parameters
(e.g., ({ theme }) => ...) retain the existing bail behavior to avoid
closure variable confusion.
Changes:
- inline-style-props.ts: Rewrite props.theme to theme and mark
needsUseThemeHook instead of bailing (both pseudo/media and base paths)
- rule-interpolated-declaration.ts: Redirect emitStyleFunctionFromPropsObject
with theme access to inline styles; handle shouldForwardProp path similarly
- Filter 'theme' from collected props to avoid marking it as a forwarded prop
Co-authored-by: Kenneth Skovhus <skovhus@users.noreply.github.com>1 parent dc6a8e8 commit 9b0049b
File tree
3 files changed
+107
-40
lines changed- src
- __tests__
- internal/lower-rules
3 files changed
+107
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3573 | 3573 | | |
3574 | 3574 | | |
3575 | 3575 | | |
3576 | | - | |
3577 | | - | |
| 3576 | + | |
3578 | 3577 | | |
3579 | 3578 | | |
3580 | 3579 | | |
| |||
3591 | 3590 | | |
3592 | 3591 | | |
3593 | 3592 | | |
3594 | | - | |
3595 | | - | |
3596 | | - | |
3597 | | - | |
3598 | | - | |
3599 | | - | |
3600 | | - | |
3601 | | - | |
3602 | | - | |
3603 | | - | |
3604 | | - | |
3605 | | - | |
3606 | | - | |
3607 | | - | |
3608 | | - | |
3609 | | - | |
3610 | | - | |
3611 | | - | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
3612 | 3598 | | |
3613 | 3599 | | |
3614 | 3600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
135 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
136 | 141 | | |
137 | 142 | | |
138 | 143 | | |
| |||
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 193 | + | |
| 194 | + | |
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
| |||
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
201 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
202 | 211 | | |
203 | 212 | | |
204 | 213 | | |
| |||
210 | 219 | | |
211 | 220 | | |
212 | 221 | | |
213 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
214 | 226 | | |
215 | 227 | | |
216 | 228 | | |
| |||
348 | 360 | | |
349 | 361 | | |
350 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
Lines changed: 60 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1583 | 1583 | | |
1584 | 1584 | | |
1585 | 1585 | | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
1594 | 1619 | | |
1595 | 1620 | | |
1596 | 1621 | | |
| |||
1944 | 1969 | | |
1945 | 1970 | | |
1946 | 1971 | | |
1947 | | - | |
| 1972 | + | |
| 1973 | + | |
1948 | 1974 | | |
1949 | 1975 | | |
1950 | 1976 | | |
| |||
1956 | 1982 | | |
1957 | 1983 | | |
1958 | 1984 | | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
1959 | 1988 | | |
1960 | 1989 | | |
1961 | 1990 | | |
1962 | 1991 | | |
1963 | 1992 | | |
1964 | | - | |
| 1993 | + | |
| 1994 | + | |
1965 | 1995 | | |
1966 | 1996 | | |
1967 | 1997 | | |
| |||
1982 | 2012 | | |
1983 | 2013 | | |
1984 | 2014 | | |
1985 | | - | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
1986 | 2021 | | |
1987 | 2022 | | |
1988 | 2023 | | |
| |||
2769 | 2804 | | |
2770 | 2805 | | |
2771 | 2806 | | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
2772 | 2821 | | |
2773 | 2822 | | |
2774 | 2823 | | |
| |||
0 commit comments