mirror of
				https://github.com/vuejs/babel-plugin-jsx.git
				synced 2025-11-01 01:42:21 +08:00 
			
		
		
		
	Rename babel-preset-jsx to babel-plugin-jsx
This commit is contained in:
		
							
								
								
									
										4
									
								
								.babelrc
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								.babelrc
									
									
									
									
									
								
							| @@ -1,6 +1,8 @@ | ||||
| { | ||||
|   "presets": [ | ||||
|     "@babel/env", | ||||
|     "@babel/env" | ||||
|   ], | ||||
|   "plugins": [ | ||||
|     "./src/index.js" | ||||
|   ] | ||||
| } | ||||
|   | ||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,20 +1,20 @@ | ||||
| # Babel Preset JSX for Vue 3.0 | ||||
| # Babel Plugin JSX for Vue 3.0 | ||||
|  | ||||
| To add Vue JSX support. | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| Install the preset with: | ||||
| Install the plugin with: | ||||
|  | ||||
| ``` | ||||
| npm install @ant-design-vue/babel-preset-jsx | ||||
| npm install @ant-design-vue/babel-plugin-jsx | ||||
| ``` | ||||
|  | ||||
| Then add the preset to .babelrc: | ||||
| Then add the plugin to .babelrc: | ||||
|  | ||||
| ``` | ||||
| { | ||||
|   "presets": ["@ant-design-vue/babel-preset-jsx"] | ||||
|   "plugins": ["@ant-design-vue/babel-plugin-jsx"] | ||||
| } | ||||
| ``` | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| { | ||||
|   "name": "@ant-design-vue/babel-preset-jsx", | ||||
|   "name": "@ant-design-vue/babel-plugin-jsx", | ||||
|   "version": "1.0.0-alpha.0", | ||||
|   "description": "Babel preset for Vue 3.0 JSX", | ||||
|   "description": "Babel plugin for Vue 3.0 JSX", | ||||
|   "main": "src/index.js", | ||||
|   "scripts": { | ||||
|     "dev": "webpack-dev-server", | ||||
|   | ||||
| @@ -1,28 +0,0 @@ | ||||
| const syntaxJsx = require('@babel/plugin-syntax-jsx').default; | ||||
| const t = require('@babel/types'); | ||||
| const helperModuleImports = require('@babel/helper-module-imports'); | ||||
|  | ||||
| const transformFragment = (path, { name }) => { | ||||
|   const children = path.get('children') || []; | ||||
|   return t.jsxElement( | ||||
|     t.jsxOpeningElement(t.jsxIdentifier(name), []), | ||||
|     t.jsxClosingElement(t.jsxIdentifier(name)), | ||||
|     children.map(({ node }) => node), | ||||
|     false, | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| module.exports = () => ({ | ||||
|   name: 'babel-sugar-fragment', | ||||
|   inherits: syntaxJsx, | ||||
|   visitor: { | ||||
|     JSXFragment: { | ||||
|       enter(path, state) { | ||||
|         if (!state.vueFragment) { | ||||
|           state.vueFragment = helperModuleImports.addNamed(path, 'Fragment', 'vue'); | ||||
|         } | ||||
|         path.replaceWith(transformFragment(path, state.vueFragment)); | ||||
|       }, | ||||
|     }, | ||||
|   }, | ||||
| }); | ||||
							
								
								
									
										19
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/index.js
									
									
									
									
									
								
							| @@ -1,11 +1,14 @@ | ||||
| const babelSugarVModel = require('./babel-sugar-v-model'); | ||||
| const babelPluginTransformVueJsx = require('./babel-plugin-transform-vue-jsx'); | ||||
| const babelSugarFragment = require('./babel-sugar-fragment'); | ||||
| const syntaxJsx = require('@babel/plugin-syntax-jsx').default; | ||||
| const tranformVueJSX = require('./transform-vue-jsx'); | ||||
| const sugarVModel = require('./sugar-v-model'); | ||||
| const sugarFragment = require('./sugar-fragment'); | ||||
|  | ||||
| module.exports = () => ({ | ||||
|   plugins: [ | ||||
|     babelSugarVModel, | ||||
|     babelPluginTransformVueJsx, | ||||
|     babelSugarFragment, | ||||
|   ], | ||||
|   name: 'babel-plugin-jsx', | ||||
|   inherits: syntaxJsx, | ||||
|   visitor: { | ||||
|     ...sugarVModel, | ||||
|     ...tranformVueJSX, | ||||
|     ...sugarFragment, | ||||
|   }, | ||||
| }); | ||||
|   | ||||
							
								
								
									
										23
									
								
								src/sugar-fragment.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/sugar-fragment.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| const t = require('@babel/types'); | ||||
| const helperModuleImports = require('@babel/helper-module-imports'); | ||||
|  | ||||
| const transformFragment = (path, { name }) => { | ||||
|   const children = path.get('children') || []; | ||||
|   return t.jsxElement( | ||||
|     t.jsxOpeningElement(t.jsxIdentifier(name), []), | ||||
|     t.jsxClosingElement(t.jsxIdentifier(name)), | ||||
|     children.map(({ node }) => node), | ||||
|     false, | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| module.exports = { | ||||
|   JSXFragment: { | ||||
|     enter(path, state) { | ||||
|       if (!state.vueFragment) { | ||||
|         state.vueFragment = helperModuleImports.addNamed(path, 'Fragment', 'vue'); | ||||
|       } | ||||
|       path.replaceWith(transformFragment(path, state.vueFragment)); | ||||
|     }, | ||||
|   }, | ||||
| }; | ||||
| @@ -1,4 +1,3 @@ | ||||
| const syntaxJsx = require('@babel/plugin-syntax-jsx').default; | ||||
| const t = require('@babel/types'); | ||||
| const htmlTags = require('html-tags'); | ||||
| const svgTags = require('svg-tags'); | ||||
| @@ -163,10 +162,7 @@ const parseVModel = (path) => { | ||||
|   }; | ||||
| }; | ||||
| 
 | ||||
| module.exports = () => ({ | ||||
|   name: 'babel-sugar-v-model', | ||||
|   inherits: syntaxJsx, | ||||
|   visitor: { | ||||
| module.exports = { | ||||
|   JSXAttribute: { | ||||
|     exit(path, state) { | ||||
|       const parsed = parseVModel(path); | ||||
| @@ -205,5 +201,4 @@ module.exports = () => ({ | ||||
|       } | ||||
|     }, | ||||
|   }, | ||||
|   }, | ||||
| }); | ||||
| }; | ||||
| @@ -1,4 +1,3 @@ | ||||
| const syntaxJsx = require('@babel/plugin-syntax-jsx').default; | ||||
| const t = require('@babel/types'); | ||||
| const htmlTags = require('html-tags'); | ||||
| const svgTags = require('svg-tags'); | ||||
| @@ -310,10 +309,7 @@ const transformJSXElement = (path, injected) => { | ||||
|   ]); | ||||
| }; | ||||
| 
 | ||||
| module.exports = () => ({ | ||||
|   name: 'babel-plugin-transform-vue-jsx', | ||||
|   inherits: syntaxJsx, | ||||
|   visitor: { | ||||
| module.exports = { | ||||
|   JSXElement: { | ||||
|     exit(path, state) { | ||||
|       if (!state.vueCreateElementInjected) { | ||||
| @@ -342,5 +338,4 @@ module.exports = () => ({ | ||||
|       ); | ||||
|     }, | ||||
|   }, | ||||
|   }, | ||||
| }); | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user