Skip to content

Commit 8991b1e

Browse files
authored
feat(parser): vue/svelte support (#758)
* fix(cli): default ship outfile * feat(parser): vue support * feat(parser): better svelte support * chore: add changeset * chore: include components dir in nuxt sandbox * chore: update snapshots * fix(playground): use browser version of vue compiler chore(parser): add try/catch on vue/svelte to tsx functions
1 parent 3f81096 commit 8991b1e

File tree

18 files changed

+1051
-345
lines changed

18 files changed

+1051
-345
lines changed

.changeset/cold-apricots-clap.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@pandacss/parser': patch
3+
'@pandacss/dev': patch
4+
---
5+
6+
- Experimental support for .vue files and better .svelte support
7+
- Fix `panda ship` default outfile path

packages/cli/src/cli-main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export async function main() {
270270
config: maybeGlob ? { include: [maybeGlob] } : undefined,
271271
})
272272

273-
const outfile = outfileFlag ?? join(...ctx.paths.root, 'debug')
273+
const outfile = outfileFlag ?? join(...ctx.paths.root, `${ctx.config.outdir}/panda.json`)
274274

275275
if (minify) {
276276
ctx.config.minify = true

packages/parser/__tests__/fixture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function getFixtureProject(code: string, options?: <Conf extends UserConf
7171
hooks,
7272
})
7373

74-
return { parse: () => project.parseSourceFile(staticFilePath), generator }
74+
return { parse: (filePath = staticFilePath) => project.parseSourceFile(filePath), generator, project }
7575
}
7676

7777
export function importParser(code: string, option: { name: string; module: string }) {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { svelteToTsx } from '../src/svelte-to-tsx'
3+
import { getFixtureProject } from './fixture'
4+
5+
const run = (code: string) => {
6+
const { parse, generator } = getFixtureProject(code)
7+
const result = parse()!
8+
return {
9+
json: result?.toArray().map(({ box, ...item }) => item),
10+
css: generator.getParserCss(result)!,
11+
}
12+
}
13+
14+
describe('extract svelte templates', () => {
15+
test('svelte basic template', () => {
16+
const code = `
17+
<script lang="ts">
18+
import { css } from "styled-system/css";
19+
20+
let style = css({ color: 'green.400' })
21+
let style2 = css({ color: 'purple.400' })
22+
</script>
23+
24+
<h1 class={style}>using class binding</h1>
25+
<p class={css({ color: 'red.500' })}>using inline styles</p>
26+
<span class="style3">using actual class</span>
27+
`
28+
29+
const transformed = svelteToTsx(code)
30+
expect(transformed).toMatchInlineSnapshot(`
31+
"import { css } from \\"styled-system/css\\";
32+
33+
let style = css({ color: 'green.400' })
34+
let style2 = css({ color: 'purple.400' })
35+
36+
37+
const render = <div><h1 class={style}>using class binding</h1>
38+
<p class={css({ color: 'red.500' })}>using inline styles</p>
39+
<span class=\\"style3\\">using actual class</span></div>"
40+
`)
41+
42+
const result = run(transformed)
43+
expect(result.json).toMatchInlineSnapshot(`
44+
[
45+
{
46+
"data": [
47+
{
48+
"color": "green.400",
49+
},
50+
],
51+
"name": "css",
52+
"type": "object",
53+
},
54+
{
55+
"data": [
56+
{
57+
"color": "purple.400",
58+
},
59+
],
60+
"name": "css",
61+
"type": "object",
62+
},
63+
{
64+
"data": [
65+
{
66+
"color": "red.500",
67+
},
68+
],
69+
"name": "css",
70+
"type": "object",
71+
},
72+
]
73+
`)
74+
75+
expect(result.css).toMatchInlineSnapshot(`
76+
"@layer utilities {
77+
.text_green\\\\.400 {
78+
color: var(--colors-green-400)
79+
}
80+
81+
.text_purple\\\\.400 {
82+
color: var(--colors-purple-400)
83+
}
84+
85+
.text_red\\\\.500 {
86+
color: var(--colors-red-500)
87+
}
88+
}"
89+
`)
90+
})
91+
})

0 commit comments

Comments
 (0)