mirror of
				https://github.com/vuejs/babel-plugin-jsx.git
				synced 2025-11-01 01:42:21 +08:00 
			
		
		
		
	refactor(jsx-explorer): dogfooding of JSX syntax
This commit is contained in:
		| @@ -74,7 +74,7 @@ function main() { | ||||
|       src, | ||||
|       { | ||||
|         babelrc: false, | ||||
|         plugins: [[babelPluginJsx, compilerOptions]], | ||||
|         plugins: [[babelPluginJsx, { ...compilerOptions }]], | ||||
|         ast: true, | ||||
|       }, | ||||
|       (err, result = {}) => { | ||||
|   | ||||
| @@ -1,113 +0,0 @@ | ||||
| import { createApp, h, reactive } from 'vue'; | ||||
| import { type VueJSXPluginOptions } from '@vue/babel-plugin-jsx'; | ||||
|  | ||||
| export { VueJSXPluginOptions }; | ||||
|  | ||||
| export const compilerOptions: VueJSXPluginOptions = reactive({ | ||||
|   mergeProps: true, | ||||
|   optimize: false, | ||||
|   transformOn: false, | ||||
|   enableObjectSlots: true, | ||||
|   resolveType: false, | ||||
| }); | ||||
|  | ||||
| const App = { | ||||
|   setup() { | ||||
|     return () => [ | ||||
|       h('h1', 'Vue 3 JSX Explorer'), | ||||
|       h( | ||||
|         'a', | ||||
|         { | ||||
|           href: 'https://app.netlify.com/sites/vue-jsx-explorer/deploys', | ||||
|           target: '_blank', | ||||
|         }, | ||||
|         'History' | ||||
|       ), | ||||
|  | ||||
|       h('div', { id: 'options-wrapper' }, [ | ||||
|         h('div', { id: 'options-label' }, 'Options ↘'), | ||||
|         h('ul', { id: 'options' }, [ | ||||
|           // mergeProps | ||||
|           h('li', [ | ||||
|             h('input', { | ||||
|               type: 'checkbox', | ||||
|               id: 'mergeProps', | ||||
|               name: 'mergeProps', | ||||
|               checked: compilerOptions.mergeProps, | ||||
|               onChange(e: Event) { | ||||
|                 compilerOptions.mergeProps = ( | ||||
|                   e.target as HTMLInputElement | ||||
|                 ).checked; | ||||
|               }, | ||||
|             }), | ||||
|             h('label', { for: 'mergeProps' }, 'mergeProps'), | ||||
|           ]), | ||||
|  | ||||
|           // optimize | ||||
|           h('li', [ | ||||
|             h('input', { | ||||
|               type: 'checkbox', | ||||
|               id: 'optimize', | ||||
|               checked: compilerOptions.optimize, | ||||
|               onChange(e: Event) { | ||||
|                 compilerOptions.optimize = ( | ||||
|                   e.target as HTMLInputElement | ||||
|                 ).checked; | ||||
|               }, | ||||
|             }), | ||||
|             h('label', { for: 'optimize' }, 'optimize'), | ||||
|           ]), | ||||
|  | ||||
|           // transformOn | ||||
|           h('li', [ | ||||
|             h('input', { | ||||
|               type: 'checkbox', | ||||
|               id: 'transformOn', | ||||
|               checked: compilerOptions.transformOn, | ||||
|               onChange(e: Event) { | ||||
|                 compilerOptions.transformOn = ( | ||||
|                   e.target as HTMLInputElement | ||||
|                 ).checked; | ||||
|               }, | ||||
|             }), | ||||
|             h('label', { for: 'transformOn' }, 'transformOn'), | ||||
|           ]), | ||||
|  | ||||
|           // enableObjectSlots | ||||
|           h('li', [ | ||||
|             h('input', { | ||||
|               type: 'checkbox', | ||||
|               id: 'enableObjectSlots', | ||||
|               checked: compilerOptions.enableObjectSlots, | ||||
|               onChange(e: Event) { | ||||
|                 compilerOptions.enableObjectSlots = ( | ||||
|                   e.target as HTMLInputElement | ||||
|                 ).checked; | ||||
|               }, | ||||
|             }), | ||||
|             h('label', { for: 'enableObjectSlots' }, 'enableObjectSlots'), | ||||
|           ]), | ||||
|  | ||||
|           // resolveType | ||||
|           h('li', [ | ||||
|             h('input', { | ||||
|               type: 'checkbox', | ||||
|               id: 'resolveType', | ||||
|               checked: compilerOptions.resolveType, | ||||
|               onChange(e: Event) { | ||||
|                 compilerOptions.resolveType = ( | ||||
|                   e.target as HTMLInputElement | ||||
|                 ).checked; | ||||
|               }, | ||||
|             }), | ||||
|             h('label', { for: 'resolveType' }, 'resolveType'), | ||||
|           ]), | ||||
|         ]), | ||||
|       ]), | ||||
|     ]; | ||||
|   }, | ||||
| }; | ||||
|  | ||||
| export function initOptions() { | ||||
|   createApp(App).mount(document.getElementById('header')!); | ||||
| } | ||||
							
								
								
									
										111
									
								
								packages/jsx-explorer/src/options.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								packages/jsx-explorer/src/options.tsx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,111 @@ | ||||
| import { createApp, defineComponent, reactive } from 'vue'; | ||||
| import { type VueJSXPluginOptions } from '@vue/babel-plugin-jsx'; | ||||
|  | ||||
| export { VueJSXPluginOptions }; | ||||
|  | ||||
| export const compilerOptions: VueJSXPluginOptions = reactive({ | ||||
|   mergeProps: true, | ||||
|   optimize: false, | ||||
|   transformOn: false, | ||||
|   enableObjectSlots: true, | ||||
|   resolveType: false, | ||||
| }); | ||||
|  | ||||
| const App = defineComponent({ | ||||
|   setup() { | ||||
|     return () => [ | ||||
|       <> | ||||
|         <h1>Vue 3 JSX Explorer</h1> | ||||
|         <a | ||||
|           href="https://app.netlify.com/sites/vue-jsx-explorer/deploys" | ||||
|           target="_blank" | ||||
|         > | ||||
|           History | ||||
|         </a> | ||||
|         <div id="options-wrapper"> | ||||
|           <div id="options-label">Options ↘</div> | ||||
|           <ul id="options"> | ||||
|             <li> | ||||
|               <input | ||||
|                 type="checkbox" | ||||
|                 id="mergeProps" | ||||
|                 name="mergeProps" | ||||
|                 checked={compilerOptions.mergeProps} | ||||
|                 onChange={(e: Event) => { | ||||
|                   compilerOptions.mergeProps = ( | ||||
|                     e.target as HTMLInputElement | ||||
|                   ).checked; | ||||
|                 }} | ||||
|               /> | ||||
|               <label for="mergeProps">mergeProps</label> | ||||
|             </li> | ||||
|  | ||||
|             <li> | ||||
|               <input | ||||
|                 type="checkbox" | ||||
|                 id="optimize" | ||||
|                 name="optimize" | ||||
|                 checked={compilerOptions.optimize} | ||||
|                 onChange={(e: Event) => { | ||||
|                   compilerOptions.optimize = ( | ||||
|                     e.target as HTMLInputElement | ||||
|                   ).checked; | ||||
|                 }} | ||||
|               /> | ||||
|               <label for="optimize">optimize</label> | ||||
|             </li> | ||||
|  | ||||
|             <li> | ||||
|               <input | ||||
|                 type="checkbox" | ||||
|                 id="transformOn" | ||||
|                 name="transformOn" | ||||
|                 checked={compilerOptions.transformOn} | ||||
|                 onChange={(e: Event) => { | ||||
|                   compilerOptions.transformOn = ( | ||||
|                     e.target as HTMLInputElement | ||||
|                   ).checked; | ||||
|                 }} | ||||
|               /> | ||||
|               <label for="transformOn">transformOn</label> | ||||
|             </li> | ||||
|  | ||||
|             <li> | ||||
|               <input | ||||
|                 type="checkbox" | ||||
|                 id="enableObjectSlots" | ||||
|                 name="enableObjectSlots" | ||||
|                 checked={compilerOptions.enableObjectSlots} | ||||
|                 onChange={(e: Event) => { | ||||
|                   compilerOptions.enableObjectSlots = ( | ||||
|                     e.target as HTMLInputElement | ||||
|                   ).checked; | ||||
|                 }} | ||||
|               /> | ||||
|               <label for="enableObjectSlots">enableObjectSlots</label> | ||||
|             </li> | ||||
|  | ||||
|             <li> | ||||
|               <input | ||||
|                 type="checkbox" | ||||
|                 id="resolveType" | ||||
|                 name="resolveType" | ||||
|                 checked={!!compilerOptions.resolveType} | ||||
|                 onChange={(e: Event) => { | ||||
|                   compilerOptions.resolveType = ( | ||||
|                     e.target as HTMLInputElement | ||||
|                   ).checked; | ||||
|                 }} | ||||
|               /> | ||||
|               <label for="resolveType">resolveType</label> | ||||
|             </li> | ||||
|           </ul> | ||||
|         </div> | ||||
|       </>, | ||||
|     ]; | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export function initOptions() { | ||||
|   createApp(App).mount(document.getElementById('header')!); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user