babel-sugar-v-bind-sync
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("@babel/plugin-syntax-jsx"),t=require("camelcase");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e),i=r(t);const s=["on"],o=/(.*)\_sync/;module.exports=e=>{const t=e.types;function r(e){return t.ExpressionStatement(t.AssignmentExpression("=",e,t.Identifier("$$val")))}function a(e,r=[]){const n=e.get("name");let i,a;if(a=t.isJSXNamespacedName(n)?`${n.get("namespace.name").node}:${n.get("name.name").node}`:n.get("name").node,s.includes(a)&&t.isJSXExpressionContainer(e.get("value")))return t.JSXSpreadAttribute(t.objectExpression([t.objectProperty(t.stringLiteral(a),e.get("value").node.expression)]));i=s.find((e=>a.startsWith(e))),a=a.replace(new RegExp(`^${i}-?`),""),a=a[0].toLowerCase()+a.substr(1);const u=e.get("value");if(!t.isJSXExpressionContainer(u))throw new Error(`getAttribute (attribute value): should be an JSXExpressionContainer but got ${u.type}`);const p=u.get("expression").node,c=a.match(o);if(null!=c){if(!t.isMemberExpression(p)){const t=e.get("parent").get("name.name").node;throw new Error(`getAttribute (attribute value): You should use MemberExpression with sync modifier, prop [${prop}] on node [${t}]`)}return{prop:c[1],value:p}}i&&(!function(e,r,n){if(e[r]){let i=!1;t.isObjectProperty(n)&&"on"===r&&(e[r].properties.forEach((e=>{t.isObjectProperty(e)&&e.key.value===n.key.value&&(t.isArrayExpression(e.value)?e.value.elements.push(n.value):e.value=t.arrayExpression([e.value,n.value]),i=!0)})),i||e[r].properties.push(n))}else e[r]=t.objectExpression([n])}(r,i,t.objectProperty(t.stringLiteral(a),p)),e.remove())}function u(e){const r={};return e.forEach((e=>{a(e,r)})),!!Object.entries(r).length&&function(e){return t.objectExpression(Object.entries(e).map((([e,r])=>t.objectProperty(t.stringLiteral(e),r))))}(r)}return{inherits:n.default,visitor:{JSXAttribute(e){const n=a(e);if(n&&!t.isJSXSpreadAttribute(n)){const{prop:o,value:a}=n;e.replaceWith(t.jSXAttribute(t.jSXIdentifier(o),t.jSXExpressionContainer(a))),e.parent.attributes.push(function(e,r){return t.jSXAttribute(t.jSXIdentifier(e),t.jSXExpressionContainer(r))}(`onUpdate:${i.default(o)}`,(s=a,t.ArrowFunctionExpression([t.Identifier("$$val")],t.BlockStatement([r(s)])))))}var s},JSXOpeningElement:{exit(e){const r=u(e.get("attributes"));r&&e.node.attributes.push(t.JSXSpreadAttribute(r))}}}}}; | ||
"use strict";var e=require("@babel/plugin-syntax-jsx"),t=require("camelcase");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e),i=r(t);const s=["on"],o=/(.*)\_sync/;module.exports=e=>{const t=e.types;function r(e,r=[]){const n=e.get("name");let i,a;if(a=t.isJSXNamespacedName(n)?`${n.get("namespace.name").node}:${n.get("name.name").node}`:n.get("name").node,s.includes(a)&&t.isJSXExpressionContainer(e.get("value")))return t.JSXSpreadAttribute(t.objectExpression([t.objectProperty(t.stringLiteral(a),e.get("value").node.expression)]));i=s.find((e=>a.startsWith(e))),a=a.replace(new RegExp(`^${i}-?`),""),a=a[0].toLowerCase()+a.substr(1);const u=e.get("value");if(s.includes(i)&&!t.isJSXExpressionContainer(u))throw new Error(`getAttribute (attribute value): should be an JSXExpressionContainer but got ${u.type}`);const p=u.get("expression").node,c=a.match(o);if(null!=c){if(!t.isMemberExpression(p)){const t=e.get("parent").get("name.name").node;throw new Error(`getAttribute (attribute value): You should use MemberExpression with sync modifier, prop [${prop}] on node [${t}]`)}return{prop:c[1],value:p}}i&&(!function(e,r,n){if(e[r]){let i=!1;t.isObjectProperty(n)&&"on"===r&&(e[r].properties.forEach((e=>{t.isObjectProperty(e)&&e.key.value===n.key.value&&(t.isArrayExpression(e.value)?e.value.elements.push(n.value):e.value=t.arrayExpression([e.value,n.value]),i=!0)})),i||e[r].properties.push(n))}else e[r]=t.objectExpression([n])}(r,i,t.objectProperty(t.stringLiteral(a),p)),e.remove())}function a(e){const n={};return e.forEach((e=>{r(e,n)})),!!Object.entries(n).length&&function(e){return t.objectExpression(Object.entries(e).map((([e,r])=>t.objectProperty(t.stringLiteral(e),r))))}(n)}return{inherits:n.default,visitor:{JSXAttribute(e){const n=r(e);if(n&&!t.isJSXSpreadAttribute(n)){const{prop:r,value:a}=n;e.replaceWith(t.jSXAttribute(t.jSXIdentifier(r),t.jSXExpressionContainer(a))),e.parent.attributes.push(function(e,r){return t.jSXAttribute(t.jSXIdentifier(e),t.jSXExpressionContainer(r))}(`onUpdate:${i.default(r)}`,(s=[(o=a,t.ExpressionStatement(t.AssignmentExpression("=",o,t.Identifier("$$val"))))],t.ArrowFunctionExpression([t.Identifier("$$val")],t.BlockStatement(s)))))}var s,o},JSXOpeningElement:{exit(e){const r=a(e.get("attributes"));r&&e.node.attributes.push(t.JSXSpreadAttribute(r))}}}}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "babel-sugar-v-bind-sync", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Babel syntactic sugar for v-bind sync modifier support in Vue JSX", | ||
@@ -22,12 +22,12 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.16.7", | ||
"@babel/preset-env": "^7.16.7", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@vue/babel-plugin-transform-vue-jsx": "^1.2.1", | ||
"parcel": "^2.2.0", | ||
"prismjs": "^1.26.0", | ||
"regenerator-runtime": "^0.13.9", | ||
"rollup": "^2.63.0", | ||
"rollup-plugin-terser": "^7.0.2" | ||
"@babel/core": "7.17.7", | ||
"@babel/preset-env": "7.16.11", | ||
"@rollup/plugin-babel": "5.3.1", | ||
"@vue/babel-plugin-transform-vue-jsx": "1.2.1", | ||
"parcel": "2.3.2", | ||
"prismjs": "1.27.0", | ||
"regenerator-runtime": "0.13.9", | ||
"rollup": "2.70.1", | ||
"rollup-plugin-terser": "7.0.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
14268
9
44