├── .circleci └── config.yml ├── .gitignore ├── .prettierignore ├── .vscode └── settings.json ├── CHANGELOG.md ├── README.md ├── lerna.json ├── package.json ├── packages ├── babel-helper-vue-jsx-merge-props │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ └── test.js ├── babel-plugin-transform-vue-jsx │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ ├── functional.js │ │ └── snapshot.js ├── babel-preset-jsx │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ └── src │ │ └── index.js ├── babel-sugar-composition-api-inject-h │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ └── test.js ├── babel-sugar-composition-api-render-instance │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ └── test.js ├── babel-sugar-functional-vue │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ └── test.js ├── babel-sugar-inject-h │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ └── test.js ├── babel-sugar-v-model │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ ├── functional.js │ │ └── snapshot.js ├── babel-sugar-v-on │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── rollup.config.js │ ├── rollup.config.testing.js │ ├── src │ │ └── index.js │ └── test │ │ ├── functional.js │ │ └── snapshot.js └── playground │ ├── .gitignore │ ├── index.html │ ├── index.ts │ ├── options.ts │ ├── package.json │ ├── style.css │ ├── tsconfig.json │ └── vite.config.ts ├── scripts └── gen-release-notes.js └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | # specify the version you desire here 6 | - image: circleci/node:lts 7 | user: node 8 | 9 | working_directory: /home/node/repo 10 | 11 | steps: 12 | - checkout 13 | 14 | # Download and cache dependencies 15 | - restore_cache: 16 | keys: 17 | - v2-dependencies-{{ checksum "yarn.lock" }} 18 | 19 | - run: yarn install --pure-lockfile 20 | 21 | - save_cache: 22 | paths: 23 | - node_modules 24 | - ~/.cache/yarn 25 | key: v2-dependencies-{{ checksum "yarn.lock" }} 26 | 27 | # run tests! 28 | - run: yarn test 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # vuepress build output 64 | .vuepress/dist 65 | 66 | # webstorm 67 | .idea 68 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "prettier.eslintIntegration": false, 4 | "prettier.arrowParens": "avoid", 5 | "prettier.bracketSpacing": true, 6 | "prettier.ignorePath": ".prettierignore", 7 | "prettier.printWidth": 120, 8 | "prettier.semi": false, 9 | "prettier.singleQuote": true, 10 | "prettier.tabWidth": 2, 11 | "prettier.trailingComma": "all" 12 | } 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [1.4.0](https://github.com/vuejs/jsx-vue2/compare/v1.3.1...v1.4.0) (2022-08-25) 2 | 3 | ## other 4 | 5 | #### Features 6 | 7 | * Make `importSource` API configurable ([#291](https://github.com/vuejs/jsx-vue2/issues/291)) ([60da266](https://github.com/vuejs/jsx-vue2/commit/60da266)) 8 | 9 | 10 | 11 | # [1.3.1](https://github.com/vuejs/jsx-vue2/compare/v1.3.0...v1.3.1) (2022-07-21) 12 | 13 | ## other 14 | 15 | #### Bug Fixes 16 | 17 | * relax the vue peer dependency version requirement ([8b5f023](https://github.com/vuejs/jsx-vue2/commit/8b5f023)) 18 | 19 | 20 | 21 | # [1.3.0](https://github.com/vuejs/jsx-vue2/compare/v1.2.4...v1.3.0) (2022-07-06) 22 | 23 | ## other 24 | 25 | #### Features 26 | 27 | * add importSource option ([#284](https://github.com/vuejs/jsx-vue2/issues/284)) ([abffc65](https://github.com/vuejs/jsx-vue2/commit/abffc65)) 28 | * rework the `compositionAPI` option of the preset to support Vue 2.7 ([e7d094e](https://github.com/vuejs/jsx-vue2/commit/e7d094e)) 29 | 30 | 31 | 32 | # [1.2.4](https://github.com/vuejs/jsx-vue2/compare/v1.2.3...v1.2.4) (2020-10-27) 33 | 34 | ## other 35 | 36 | #### Bug Fixes 37 | 38 | * **composition-api-render-instance:** store currentInstance in variable for render instance ([#168](https://github.com/vuejs/jsx-vue2/issues/168)) ([a3525bf](https://github.com/vuejs/jsx-vue2/commit/a3525bf)) 39 | 40 | 41 | 42 | # [1.2.3](https://github.com/vuejs/jsx-vue2/compare/v1.2.2...v1.2.3) (2020-10-20) 43 | 44 | ## other 45 | 46 | #### Bug Fixes 47 | 48 | * v-model/v-on should apply before arrow-functions transform ([#167](https://github.com/vuejs/jsx-vue2/issues/167)) ([319932e](https://github.com/vuejs/jsx-vue2/commit/319932e)), closes [#87](https://github.com/vuejs/jsx-vue2/issues/87) [/github.com/vuejs/jsx/issues/165#issuecomment-712603569](https://github.com//github.com/vuejs/jsx/issues/165/issues/issuecomment-712603569) 49 | 50 | 51 | 52 | # [1.2.2](https://github.com/vuejs/jsx-vue2/compare/v1.2.1...v1.2.2) (2020-10-17) 53 | 54 | ## other 55 | 56 | #### Bug Fixes 57 | 58 | * functional-vue & inject-h should traverse before JSX plugin ([#166](https://github.com/vuejs/jsx-vue2/issues/166)) ([8969609](https://github.com/vuejs/jsx-vue2/commit/8969609)), closes [#165](https://github.com/vuejs/jsx-vue2/issues/165) 59 | 60 | 61 | 62 | # [1.2.1](https://github.com/vuejs/jsx-vue2/compare/v1.2.0...v1.2.1) (2020-10-16) 63 | 64 | ## other 65 | 66 | #### Bug Fixes 67 | 68 | * add composition-api packages to dependencies ([cd9db9f](https://github.com/vuejs/jsx-vue2/commit/cd9db9f)) 69 | 70 | 71 | 72 | # [1.2.0](https://github.com/vuejs/jsx-vue2/compare/v1.1.2...v1.2.0) (2020-10-16) 73 | 74 | ## other 75 | 76 | #### Features 77 | 78 | * add [@vue](https://github.com/vue)/composition-api support ([#142](https://github.com/vuejs/jsx-vue2/issues/142)) ([ecc6ed6](https://github.com/vuejs/jsx-vue2/commit/ecc6ed6)) 79 | * allow prior babel plugins to traverse JSX tree throughly, close [#86](https://github.com/vuejs/jsx-vue2/issues/86) ([b49fa8a](https://github.com/vuejs/jsx-vue2/commit/b49fa8a)) 80 | * change all sugar plugins to work without pre-traversing the Program ([0943580](https://github.com/vuejs/jsx-vue2/commit/0943580)) 81 | 82 | 83 | 84 | # [1.1.2](https://github.com/vuejs/jsx-vue2/compare/v1.1.1...v1.1.2) (2019-11-09) 85 | 86 | ## other 87 | 88 | #### Bug Fixes 89 | 90 | * add [@babel](https://github.com/babel)/core to peerDependencies ([f60f316](https://github.com/vuejs/jsx-vue2/commit/f60f316)) 91 | 92 | 93 | 94 | # [1.1.1](https://github.com/vuejs/jsx-vue2/compare/v1.1.0...v1.1.1) (2019-10-11) 95 | 96 | ## other 97 | 98 | #### Bug Fixes 99 | 100 | * **v-model:** create non-existent properties as reactive ([05b9b3a](https://github.com/vuejs/jsx-vue2/commit/05b9b3a)) 101 | 102 | 103 | 104 | # [1.1.0](https://github.com/vuejs/jsx-vue2/compare/v1.0.0...v1.1.0) (2019-07-23) 105 | 106 | ## other 107 | 108 | #### Bug Fixes 109 | 110 | * support for `.passive` modifier ([01177c8](https://github.com/vuejs/jsx-vue2/commit/01177c8)) 111 | 112 | 113 | 114 | # [1.0.0](https://github.com/vuejs/jsx-vue2/compare/v1.0.0-beta.3...v1.0.0) (2019-05-08) 115 | 116 | ## other 117 | 118 | #### Bug Fixes 119 | 120 | * Support props with underscore, close [#55](https://github.com/vuejs/jsx-vue2/issues/55) ([852481c](https://github.com/vuejs/jsx-vue2/commit/852481c)) 121 | 122 | 123 | 124 | # [1.0.0-beta.3](https://github.com/vuejs/jsx-vue2/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2019-03-22) 125 | 126 | ## other 127 | 128 | #### Bug Fixes 129 | 130 | * filter out jsx comments in `getChildren` ([7f0c84c](https://github.com/vuejs/jsx-vue2/commit/7f0c84c)), closes [#46](https://github.com/vuejs/jsx-vue2/issues/46) 131 | * fix incorrect repository urls ([99380b3](https://github.com/vuejs/jsx-vue2/commit/99380b3)) 132 | 133 | 134 | 135 | # [1.0.0-beta.2](https://github.com/vuejs/jsx-vue2/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2019-01-11) 136 | 137 | ## other 138 | 139 | #### Bug Fixes 140 | 141 | * remove extraneous peer deps ([29414a7](https://github.com/vuejs/jsx-vue2/commit/29414a7)) 142 | * Trim whitespaces properly, fix [#37](https://github.com/vuejs/jsx-vue2/issues/37) ([54c75ee](https://github.com/vuejs/jsx-vue2/commit/54c75ee)) 143 | #### Features 144 | 145 | * Support root-level attributes, close [#32](https://github.com/vuejs/jsx-vue2/issues/32) ([96b182c](https://github.com/vuejs/jsx-vue2/commit/96b182c)) 146 | 147 | 148 | 149 | # 1.0.0-beta.1 (2018-12-25) 150 | 151 | ## other 152 | 153 | #### Bug Fixes 154 | 155 | * Add events at the begining of argument list ([0604214](https://github.com/vuejs/jsx-vue2/commit/0604214)) 156 | * Add staticClass as root attribute ([cd3bab1](https://github.com/vuejs/jsx-vue2/commit/cd3bab1)) 157 | * Do not trim all spaces ([c5ebfac](https://github.com/vuejs/jsx-vue2/commit/c5ebfac)) 158 | * Fix failing tests ([21213df](https://github.com/vuejs/jsx-vue2/commit/21213df)) 159 | * Force html & svg tags to always be treated as string tags ([12a311e](https://github.com/vuejs/jsx-vue2/commit/12a311e)) 160 | * proper support for camelCase ([a903610](https://github.com/vuejs/jsx-vue2/commit/a903610)) 161 | * Support camelCase directives ([6a43377](https://github.com/vuejs/jsx-vue2/commit/6a43377)) 162 | * Support default export in functional component ([7e6f893](https://github.com/vuejs/jsx-vue2/commit/7e6f893)) 163 | * throw an error if v-model is used with a string ([82d6bcb](https://github.com/vuejs/jsx-vue2/commit/82d6bcb)) 164 | #### Features 165 | 166 | * Add release utilities ([4bb22fb](https://github.com/vuejs/jsx-vue2/commit/4bb22fb)) 167 | * add support for argument and modifiers for directives ([0085b8f](https://github.com/vuejs/jsx-vue2/commit/0085b8f)) 168 | * change the syntax for argument and modifiers ([b1c8036](https://github.com/vuejs/jsx-vue2/commit/b1c8036)) 169 | * Event modifiers for v-on ([cef09bb](https://github.com/vuejs/jsx-vue2/commit/cef09bb)) 170 | * implement babel preset ([1137c1d](https://github.com/vuejs/jsx-vue2/commit/1137c1d)) 171 | * Support vModel in kebab-case components ([dc0e29f](https://github.com/vuejs/jsx-vue2/commit/dc0e29f)) 172 | * Treat string as component if declared in scope ([51ca488](https://github.com/vuejs/jsx-vue2/commit/51ca488)) 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Babel Preset JSX 2 | 3 | > [!CAUTION] 4 | > Vue 2 has reached EOL, and this project is no longer actively maintained. 5 | 6 | Configurable Babel preset to add Vue JSX support. See the [configuration options here](./packages/babel-preset-jsx). 7 | 8 | ## Compatibility 9 | 10 | This repo is only compatible with: 11 | 12 | - **Babel 7+**. For Babel 6 support, use [vuejs/babel-plugin-transform-vue-jsx](https://github.com/vuejs/babel-plugin-transform-vue-jsx) 13 | - **Vue 2+**. JSX is not supported for older versions. For Vue 3 support, please use [`@vue/babel-plugin-jsx`](https://github.com/vuejs/babel-plugin-jsx). 14 | 15 | ## Installation 16 | 17 | Install the preset with: 18 | 19 | ```bash 20 | npm install @vue/babel-preset-jsx @vue/babel-helper-vue-jsx-merge-props 21 | ``` 22 | 23 | Then add the preset to `babel.config.js`: 24 | 25 | ```js 26 | module.exports = { 27 | presets: ['@vue/babel-preset-jsx'], 28 | } 29 | ``` 30 | 31 | ## Syntax 32 | 33 | ### Content 34 | 35 | ```jsx 36 | render() { 37 | return

hello

38 | } 39 | ``` 40 | 41 | with dynamic content: 42 | 43 | ```jsx 44 | render() { 45 | return

hello { this.message }

46 | } 47 | ``` 48 | 49 | when self-closing: 50 | 51 | ```jsx 52 | render() { 53 | return 54 | } 55 | ``` 56 | 57 | with a component: 58 | 59 | ```jsx 60 | import MyComponent from './my-component' 61 | 62 | export default { 63 | render() { 64 | return hello 65 | }, 66 | } 67 | ``` 68 | 69 | ### Attributes/Props 70 | 71 | ```jsx 72 | render() { 73 | return 74 | } 75 | ``` 76 | 77 | with a dynamic binding: 78 | 79 | ```jsx 80 | render() { 81 | return 85 | } 86 | ``` 87 | 88 | with the spread operator (object needs to be compatible with [Vue Data Object](https://v2.vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth)): 89 | 90 | ```jsx 91 | render() { 92 | const inputAttrs = { 93 | type: 'email', 94 | placeholder: 'Enter your email' 95 | } 96 | 97 | return 98 | } 99 | ``` 100 | 101 | ### Slots 102 | 103 | named slots: 104 | 105 | ```jsx 106 | render() { 107 | return ( 108 | 109 |
header
110 | 111 |
112 | ) 113 | } 114 | ``` 115 | 116 | scoped slots: 117 | 118 | ```jsx 119 | render() { 120 | const scopedSlots = { 121 | header: () =>
header
, 122 | footer: () => 123 | } 124 | 125 | return 126 | } 127 | ``` 128 | 129 | ### Directives 130 | 131 | ```jsx 132 | 133 | ``` 134 | 135 | with a modifier: 136 | 137 | ```jsx 138 | 139 | ``` 140 | 141 | with an argument: 142 | 143 | ```jsx 144 | 145 | ``` 146 | 147 | with an argument and modifiers: 148 | 149 | ```jsx 150 | 151 | ``` 152 | 153 | v-html: 154 | 155 | ```jsx 156 |

157 | ``` 158 | 159 | ### Functional Components 160 | 161 | Transpiles arrow functions that return JSX into functional components, when they are either default exports: 162 | 163 | ```jsx 164 | export default ({ props }) =>

hello {props.message}

165 | ``` 166 | 167 | or PascalCase variable declarations: 168 | 169 | ```jsx 170 | const HelloWorld = ({ props }) =>

hello {props.message}

171 | ``` 172 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "2.9.1", 3 | "packages": [ 4 | "packages/*" 5 | ], 6 | "version": "1.4.0", 7 | "npmClient": "yarn" 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "license": "MIT", 4 | "workspaces": [ 5 | "packages/*" 6 | ], 7 | "scripts": { 8 | "test": "lerna run test", 9 | "release:note": "node scripts/gen-release-notes.js run", 10 | "release:build": "lerna run build", 11 | "prerelease": "yarn release:build", 12 | "postrelease": "yarn release:note", 13 | "release": "lerna publish" 14 | }, 15 | "devDependencies": { 16 | "@lerna-lite/cli": "^1.9.0", 17 | "@lerna-lite/run": "^1.9.0", 18 | "@vue/conventional-changelog": "^0.1.1", 19 | "conventional-changelog": "^2.0.3", 20 | "execa": "^1.0.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/babel-helper-vue-jsx-merge-props/.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | -------------------------------------------------------------------------------- /packages/babel-helper-vue-jsx-merge-props/README.md: -------------------------------------------------------------------------------- 1 | ## @vue/babel-helper-vue-jsx-merge-props 2 | 3 | A package used internally by vue jsx transformer to merge props spread. It is required to merge some prop trees like this: 4 | 5 | ```js 6 | import mergeProps from '@vue/babel-helper-vue-jsx-merge-props' 7 | 8 | const MyComponent = { 9 | render(h) { 10 | // original: