├── .travis.yml ├── test ├── snapshots │ ├── test.js.snap │ └── test.js.md └── test.js ├── .vscode └── settings.json ├── package.json ├── README.md ├── LICENSE ├── .gitignore └── index.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7" -------------------------------------------------------------------------------- /test/snapshots/test.js.snap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickmessing/babel-plugin-jsx-v-model/HEAD/test/snapshots/test.js.snap -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.svn": true, 6 | "**/.hg": true, 7 | "**/CVS": true, 8 | "**/.DS_Store": true 9 | }, 10 | "editor.formatOnSave": true, 11 | "prettier.singleQuote": true, 12 | "editor.tabSize": 2, 13 | "prettier.trailingComma": "none", 14 | "prettier.printWidth": 120, 15 | "prettier.semi": false 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-jsx-v-model", 3 | "version": "2.0.3", 4 | "description": "JSX v-model transform", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "ava", 8 | "coverage": "nyc --reporter=lcov npm test" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/nickmessing/babel-plugin-jsx-v-model.git" 13 | }, 14 | "keywords": [ 15 | "Vue", 16 | "jsx", 17 | "v-model" 18 | ], 19 | "author": "Nicolai Moraru ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/nickmessing/babel-plugin-jsx-v-model/issues" 23 | }, 24 | "homepage": "https://github.com/nickmessing/babel-plugin-jsx-v-model#readme", 25 | "dependencies": { 26 | "babel-plugin-syntax-jsx": "^6.18.0", 27 | "html-tags": "^2.0.0", 28 | "svg-tags": "^1.0.0" 29 | }, 30 | "devDependencies": { 31 | "ava": "^0.21.0", 32 | "babel-core": "^6.25.0", 33 | "nyc": "^11.0.3" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/nickmessing/babel-plugin-jsx-v-model.svg?branch=master)](https://travis-ci.org/nickmessing/babel-plugin-jsx-v-model) 2 | 3 | ## DEPRECATED: Check https://github.com/vuejs/jsx instead 4 | 5 | ## JSX v-model for Vue JSX 6 | 7 | This babel plugin adds some syntactic sugar to JSX. 8 | 9 | ### Usage: 10 | 11 | ```bash 12 | npm i babel-plugin-jsx-v-model -D 13 | ``` 14 | 15 | Then add `jsx-v-model` to your `.babelrc` file under `plugins` 16 | 17 | example .babelrc: 18 | ```json 19 | { 20 | "presets": ["es2015"], 21 | "plugins": ["jsx-v-model", "transform-vue-jsx"] 22 | } 23 | ``` 24 | 25 | code: 26 | ```js 27 | Vue.component('hello-world', { 28 | data: () => ({ 29 | text: 'Hello World!' 30 | }), 31 | render () { 32 | return ( 33 |
34 | 35 | {this.text} 36 |
37 | ) 38 | } 39 | }) 40 | ``` 41 | 42 | Behaviour is similar to vue template's [v-model](https://vuejs.org/v2/api/#v-model). 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Nick Messing 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.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 (http://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 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | import { transform } from 'babel-core' 3 | 4 | const transpile = src => { 5 | return transform(src, { 6 | plugins: './index' 7 | }).code.trim() 8 | } 9 | 10 | const testTranspile = (title, code) => { 11 | test(title, t => { 12 | const compiled = transpile(code) 13 | 14 | t.snapshot(code, 'Initial code') 15 | t.snapshot(compiled, 'Compiled code') 16 | }) 17 | } 18 | 19 | const testError = (title, code) => { 20 | test(title, t => { 21 | const error = t.throws(() => transpile(code), SyntaxError) 22 | 23 | t.snapshot(code, 'Initial code') 24 | t.snapshot(error.message, 'Error mesage') 25 | }) 26 | } 27 | 28 | testError( 29 | 'Error: input[type={dynamic}, v-model]', 30 | ` 31 | 35 | ` 36 | ) 37 | testError( 38 | 'Error: input[v-model:invalidModifier]', 39 | ` 40 | 43 | ` 44 | ) 45 | testError( 46 | 'Error: input[v-model, v-model]', 47 | ` 48 | 52 | ` 53 | ) 54 | testError( 55 | 'Error: input[v-model="string literal"]', 56 | ` 57 | 60 | ` 61 | ) 62 | testError( 63 | 'Error: input[v-model={identifier}]', 64 | ` 65 | 68 | ` 69 | ) 70 | testError( 71 | 'Error: h3', 72 | ` 73 |

76 | ` 77 | ) 78 | testError( 79 | 'Error: select[v-model:trim]', 80 | ` 81 | 93 | ` 94 | ) 95 | testError( 96 | 'Error: input[type="radio",v-model:trim]', 97 | ` 98 | 102 | ` 103 | ) 104 | testError( 105 | 'Error: input[type="file",v-model]', 106 | ` 107 | 111 | ` 112 | ) 113 | 114 | testTranspile( 115 | 'Ignores namespaced attributes', 116 | ` 117 | 120 | ` 121 | ) 122 | testTranspile( 123 | 'textarea[v-model]', 124 | ` 125 |