Commit 0c5f21d
fix: css-prop key shadowing, ts-jest detection, import aliasing (#421)
* fix(css-prop): treat plain object keys as literal property names
A `css={{ position: 'absolute' }}` object key is a literal property name, not
a reference to a binding, even when the local scope defines a same-named
variable. The reducer in transpileCssProp incorrectly extracted such keys as
prop interpolations, producing invalid output like `p.$_css: 'absolute'`.
Require `property.computed` in the key-rewrite check so only `[expr]` keys
are treated as scope references. Closes #409.
* fix(detection): recognize TypeScript's __importDefault helper
The plugin already understands Babel's `_interopRequireDefault(require(...))`
shape and tracks the resulting local binding for downstream styled detection.
TypeScript's compiler emits a functionally identical helper named
`__importDefault`, which previously slipped past the check so files compiled
through tsc / ts-jest never picked up displayName or componentId.
Match either helper name in assignStyledRequired. Closes #406, #343.
* feat(detection): follow local alias of the styled import
TypeScript theme-typing setups re-bind the styled import through a local
const so the type can be narrowed:
const styled = baseStyled as ThemedStyledInterface<MyTheme>
After type-stripping Babel sees a plain `const styled = baseStyled`. The
detector previously only matched the exact import binding name, so
`styled.div` no longer resolved and the declaration lost displayName /
componentId. Walk single-identifier (and TSAsExpression / TSTypeAssertion)
alias chains lazily when the direct-name check misses.
Adds regression fixtures for the alias case (#238), the sc v6 named-import
shape, and chained `withConfig(getConfig())` augmentation.
* docs: state the tested matrix in README
Adds a short Requirements section above Quick Start naming the versions
exercised in CI. No enforcement change; the peer ranges in package.json
remain unchanged so existing installs keep working.
* feat(css-prop): add cssPropImportPath option for React Native targets
The css-prop transform auto-injects `import _styled from 'styled-components'`
when the file has no existing styled import. That hardcoded path was the only
piece blocking React Native from using the css-prop syntax: the rest of the
transform already produces the right shape, since PascalCase JSX names route
through the identifier branch and emit `styled(View)` rather than
`styled('View')`.
Introduce a `cssPropImportPath` option naming the package to inject from.
Defaults to `'styled-components'` (existing behavior). RN consumers can set
it to `'styled-components/native'` so the injected import resolves to the
correct runtime.
Closes #272.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d0add03 commit 0c5f21d
27 files changed
Lines changed: 322 additions & 8 deletions
File tree
- .changeset
- src
- utils
- visitors
- test/fixtures
- css-prop-object-key-shadowed-by-binding
- css-prop-with-native-import-path
- named-import-styled-from-sc-v6
- pre-transpiled-tsc-importdefault
- styled-alias-via-local-binding
- withconfig-chained-on-existing-config
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
25 | 39 | | |
26 | 40 | | |
27 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
78 | 109 | | |
79 | 110 | | |
80 | 111 | | |
| |||
91 | 122 | | |
92 | 123 | | |
93 | 124 | | |
| 125 | + | |
| 126 | + | |
94 | 127 | | |
95 | 128 | | |
96 | | - | |
| 129 | + | |
97 | 130 | | |
98 | | - | |
| 131 | + | |
99 | 132 | | |
100 | 133 | | |
101 | | - | |
| 134 | + | |
102 | 135 | | |
103 | 136 | | |
104 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | | - | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
178 | 181 | | |
| 182 | + | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments