Skip to content

Commit 4841f2e

Browse files
committed
feat: support transforming jsx
resolves #177
1 parent c15fd92 commit 4841f2e

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function MyJSXComponent() {
2+
return <div>My JSX Component</div>
3+
}

src/commands/build.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ export default defineCommand({
5050
outDir,
5151
entries: [
5252
'src/module',
53-
{ input: 'src/runtime/', outDir: `${outDir}/runtime`, ext: 'mjs' },
53+
{
54+
input: 'src/runtime/',
55+
outDir: `${outDir}/runtime`,
56+
ext: 'mjs',
57+
esbuild: {
58+
jsxImportSource: 'vue',
59+
jsx: 'automatic',
60+
jsxFactory: 'h',
61+
}
62+
},
5463
],
5564
rollup: {
5665
esbuild: {

test/__snapshots__/JsxComponent.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function MyJSXComponent(): import("vue/jsx-runtime").JSX.Element;

test/__snapshots__/JsxComponent.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { jsx } from "vue/jsx-runtime";
2+
export default function MyJSXComponent() {
3+
return /* @__PURE__ */ jsx("div", { children: "My JSX Component" });
4+
}

test/build.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ describe('module builder', () => {
106106
const componentFile = await readFile(join(distDir, 'runtime/composables/useWrappedFetch.d.ts'), 'utf-8')
107107
expect(componentFile).toMatchFileSnapshot('__snapshots__/useWrappedFetch.d.ts')
108108
})
109+
110+
it('should handle JSX correctly', async () => {
111+
const [component, declaration] = await Promise.all([
112+
readFile(join(distDir, 'runtime/components/JsxComponent.mjs'), 'utf-8'),
113+
readFile(join(distDir, 'runtime/components/JsxComponent.d.ts'), 'utf-8')
114+
])
115+
expect(component).toMatchFileSnapshot('__snapshots__/JsxComponent.mjs')
116+
expect(declaration).toMatchFileSnapshot('__snapshots__/JsxComponent.d.ts')
117+
})
109118
})

0 commit comments

Comments
 (0)