babel-sugar-v-bind-sync
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,1 +0,1 @@ | ||
"use strict";var e=require("@babel/plugin-syntax-jsx"),n=require("camelcase");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e),o=t(n);const i=/(.*)\_sync/;function s(e,n){return e.ExpressionStatement(e.AssignmentExpression("=",n,e.Identifier("$$val")))}module.exports=function(e){const n=e.types;return{inherits:r.default,visitor:{JSXOpeningElement(e){e.get("attributes").forEach((t=>{try{const r=t.node.name.name.match(i);if(r){const i=r[1];let a;if(t.node.name.name=i,t.traverse({JSXExpressionContainer(e){a=e.node.expression}}),!n.isMemberExpression(a))return void console.error(`You should use MemberExpression with sync modifier, prop [${i}] on node [${e.node.name.name}]`);const u=function(e,n,t){return e.jSXAttribute(e.jSXIdentifier(`on${n}`),e.jSXExpressionContainer(e.ArrowFunctionExpression([e.Identifier("$$val")],e.BlockStatement(t))))}(n,`Update:${o.default(i)}`,[s(n,a)]);t.insertAfter(u)}}catch(e){}}))}}}}; | ||
"use strict";var e=require("@babel/plugin-syntax-jsx"),n=require("camelcase");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e),i=t(n);let o;function s(e,n){return e.ExpressionStatement(e.AssignmentExpression("=",n,e.Identifier("$$val")))}module.exports=function({types:e}){return{inherits:r.default,visitor:{JSXOpeningElement(n,t){const{delimiters:r="_"}=t.opts||{};o=o||new RegExp(`(.*)\\${r}sync`),n.get("attributes").forEach((t=>{try{const r=t.node.name.name.match(o);if(r){const o=r[1];let a;if(t.node.name.name=o,t.traverse({JSXExpressionContainer(e){a=e.node.expression}}),!e.isMemberExpression(a))return void console.error(`You should use MemberExpression with sync modifier, prop [${o}] on node [${n.node.name.name}]`);const u=function(e,n,t){return e.jSXAttribute(e.jSXIdentifier(`on${n}`),e.jSXExpressionContainer(e.ArrowFunctionExpression([e.Identifier("$$val")],e.BlockStatement(t))))}(e,`Update:${i.default(o)}`,[s(e,a)]);t.insertAfter(u)}}catch(e){}}))}}}}; |
{ | ||
"name": "babel-sugar-v-bind-sync", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Babel syntactic sugar for v-bind sync modifier support in Vue JSX", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -15,5 +15,5 @@ # babel-sugar-v-bind-sync | ||
# for yarn: | ||
yarn add babel-sugar-v-bind-sync | ||
yarn add -D babel-sugar-v-bind-sync | ||
# for npm: | ||
npm install babel-sugar-v-bind-sync --save | ||
npm install babel-sugar-v-bind-sync --save-dev | ||
``` | ||
@@ -25,3 +25,3 @@ | ||
{ | ||
"plugins": ["babel-sugar-v-bind-sync"] | ||
"plugins": [["babel-sugar-v-bind-sync", { "delimiters": "_" }]] | ||
} | ||
@@ -32,5 +32,5 @@ ``` | ||
This plugin adds v-bind `sync` feature to the JSX and tries to mirror the same behavior as in vue-template-compiler, with a few differences: | ||
This plugin adds v-bind `sync` modifier to the JSX and tries to mirror the same behavior as in vue-template-compiler, with a few differences: | ||
1. You should use underscore (\_) instead of dot (.) for `sync` modifier (`foo_sync={this.bar}`) | ||
1. You should use underscore (`_`) instead of dot (`.`) for `sync` modifier (`prop_sync={this.bar}`), but you can pass `delimiters` in babel plugin options to change this. | ||
2. It is recommended to use camelCase version of it (`propName_sync`) in JSX, but you can use kebab-case too (`prop-name_sync`). | ||
@@ -42,3 +42,3 @@ | ||
return { | ||
test: 'something', | ||
bar: 'naz', | ||
}; | ||
@@ -49,3 +49,3 @@ }, | ||
<div> | ||
<component visible_sync={this.test} /> | ||
<component foo_sync={this.bar} /> | ||
</div> | ||
@@ -52,0 +52,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4904