Skip to content

Commit 8f43369

Browse files
committed
fix(parser): improve spreading extraction
1 parent 2d60940 commit 8f43369

File tree

6 files changed

+2857
-3
lines changed

6 files changed

+2857
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
'@pandacss/core': patch
3+
'@pandacss/parser': patch
4+
---
5+
6+
Fix css.raw spreading within selectors and conditions
7+
8+
Fixed several scenarios where spreading css.raw objects wouldn't be properly extracted:
9+
10+
**Child selectors:**
11+
12+
```js
13+
const baseStyles = css.raw({ margin: 0, padding: 0 })
14+
const component = css({
15+
'& p': { ...baseStyles, fontSize: '1rem' }, // Now works
16+
})
17+
```
18+
19+
**Nested conditions:**
20+
21+
```js
22+
const interactive = css.raw({ cursor: 'pointer', transition: 'all 0.2s' })
23+
const card = css({
24+
_hover: {
25+
...interactive, // Now works
26+
_dark: { ...interactive, color: 'white' },
27+
},
28+
})
29+
```
30+
31+
**CSS aliases:**
32+
33+
```js
34+
import { css as xcss } from 'styled-system/css'
35+
const styles = xcss.raw({ color: 'red' })
36+
// xcss.raw now properly recognized
37+
```

packages/core/__tests__/file-matcher.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,43 @@ describe('file matcher', () => {
143143
])
144144

145145
expect(file.isRawFn('css')).toMatchInlineSnapshot('true')
146-
expect(file.isRawFn('xcss')).toMatchInlineSnapshot('false')
146+
expect(file.isRawFn('xcss')).toMatchInlineSnapshot('true') // xcss is an alias for css, should be true
147147

148148
expect(file.isRawFn('css.raw')).toMatchInlineSnapshot('true')
149+
expect(file.isRawFn('xcss.raw')).toMatchInlineSnapshot('true') // xcss.raw should work too
149150
expect(file.isRawFn('stack.raw')).toMatchInlineSnapshot('true')
150151

151-
expect(file.isRawFn('cva.raw')).toMatchInlineSnapshot('false')
152+
expect(file.isRawFn('cva.raw')).toMatchInlineSnapshot('true') // cva is imported, should be true
153+
})
154+
155+
test('is raw fn with sva aliases', () => {
156+
const ctx = createContext()
157+
158+
const file = ctx.imports.file([
159+
{ mod: 'styled-system/css', name: 'css', alias: 'styledCss' },
160+
{ mod: 'styled-system/css', name: 'cva', alias: 'componentVariant' },
161+
{ mod: 'styled-system/css', name: 'sva', alias: 'slotVariant' },
162+
])
163+
164+
// Test aliased css functions
165+
expect(file.isRawFn('styledCss')).toMatchInlineSnapshot('true')
166+
expect(file.isRawFn('styledCss.raw')).toMatchInlineSnapshot('true')
167+
168+
// Test aliased cva functions
169+
expect(file.isRawFn('componentVariant')).toMatchInlineSnapshot('true')
170+
expect(file.isRawFn('componentVariant.raw')).toMatchInlineSnapshot('true')
171+
172+
// Test aliased sva functions
173+
expect(file.isRawFn('slotVariant')).toMatchInlineSnapshot('true')
174+
expect(file.isRawFn('slotVariant.raw')).toMatchInlineSnapshot('true')
175+
176+
// Test non-aliased should still work
177+
expect(file.isRawFn('css')).toMatchInlineSnapshot('true')
178+
expect(file.isRawFn('css.raw')).toMatchInlineSnapshot('true')
179+
180+
// Test non-existent aliases
181+
expect(file.isRawFn('randomAlias')).toMatchInlineSnapshot('false')
182+
expect(file.isRawFn('randomAlias.raw')).toMatchInlineSnapshot('false')
152183
})
153184

154185
test('namespace', () => {

packages/core/src/file-matcher.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ export class FileMatcher {
187187

188188
isRawFn = (fnName: string) => {
189189
const name = fnName.split('.raw')[0] ?? ''
190-
return name === 'css' || this.isValidPattern(name) || this.isValidRecipe(name)
190+
191+
// Check if it's css (literal or alias), pattern, or recipe
192+
const isCssOrAlias =
193+
name === 'css' || this.cssAliases.has(name) || this.cvaAliases.has(name) || this.svaAliases.has(name)
194+
195+
return isCssOrAlias || this.isValidPattern(name) || this.isValidRecipe(name)
191196
}
192197

193198
isNamespaced = (fnName: string) => {

0 commit comments

Comments
 (0)