diff --git a/packages/babel-plugin-jsx/src/index.ts b/packages/babel-plugin-jsx/src/index.ts index 47abea7..ec78c35 100644 --- a/packages/babel-plugin-jsx/src/index.ts +++ b/packages/babel-plugin-jsx/src/index.ts @@ -11,7 +11,7 @@ export type State = { opts: Opts; } -interface Opts { +export interface Opts { transformOn?: boolean; optimize?: boolean; mergeProps?: boolean; diff --git a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap index cc088ac..00fcd14 100644 --- a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap +++ b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap @@ -79,6 +79,21 @@ withDirectives(createVNode(\\"input\\", { }, null, 8, [\\"onUpdate:modelValue\\"]), [[vModelText, test]]);" `; +exports[`override props multiple: multiple 1`] = ` +"import { resolveComponent, createVNode } from \\"vue\\"; +createVNode(resolveComponent(\\"A\\"), { + \\"loading\\": true, + ...a, + \\"class\\": \\"x\\", + \\"style\\": x +}, null);" +`; + +exports[`override props single: single 1`] = ` +"import { createVNode } from \\"vue\\"; +createVNode(\\"div\\", a, null);" +`; + exports[`reassign variable as component: reassign variable as component 1`] = ` "import { defineComponent, createVNode } from \\"vue\\"; let a = 1; diff --git a/packages/babel-plugin-jsx/test/snapshot.test.ts b/packages/babel-plugin-jsx/test/snapshot.test.ts index a748ed9..941acb1 100644 --- a/packages/babel-plugin-jsx/test/snapshot.test.ts +++ b/packages/babel-plugin-jsx/test/snapshot.test.ts @@ -1,12 +1,14 @@ import { transform } from '@babel/core'; -import JSX from '../src'; +import JSX, { Opts } from '../src'; -const transpile = (source: string) => new Promise((resolve, reject) => transform( +const transpile = ( + source: string, options: Opts = {}, +) => new Promise((resolve, reject) => transform( source, { filename: '', presets: null, - plugins: [[JSX, { optimize: true }]], + plugins: [[JSX, options]], configFile: false, }, (error, result) => { if (error) { @@ -138,7 +140,26 @@ tests.forEach(( test( name, async () => { - expect(await transpile(from)).toMatchSnapshot(name); + expect(await transpile(from, { optimize: true })).toMatchSnapshot(name); + }, + ); +}); + +const overridePropsTests = [{ + name: 'single', + from: '
', +}, { + name: 'multiple', + from: '', +}]; + +overridePropsTests.forEach(( + { name, from }, +) => { + test( + `override props ${name}`, + async () => { + expect(await transpile(from, { mergeProps: false })).toMatchSnapshot(name); }, ); });