Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-sugar-v-bind-sync

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-sugar-v-bind-sync - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

2

lib/index.js

@@ -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,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}`);let p;if(u.node)if(t.isStringLiteral(u.node))p=u.node;else{if(!t.isJSXExpressionContainer(u))throw new Error(`getAttributes (attribute value): ${u.type} is not supported`);p=u.get("expression").node}else p=t.booleanLiteral(!0);const l=a.match(o);if(null!=l){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:l[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))}}}}};
"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}`);let p;if(u.node)if(t.isStringLiteral(u.node))p=u.node;else{if(!t.isJSXExpressionContainer(u))throw new Error(`getAttributes (attribute value): ${u.type} is not supported`);p=u.get("expression").node}else p=t.booleanLiteral(!0);const l=a.match(o);if(null!=l){const r=l[1];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 [${r}] on node [${t}]`)}return{prop:r,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=>{t.isJSXAttribute(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){if(t.isJSXAttribute(e)){const o=r(e);if(o&&!t.isJSXSpreadAttribute(o)){const{prop:r,value:a}=o;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)}`,(n=[(s=a,t.ExpressionStatement(t.AssignmentExpression("=",s,t.Identifier("$$val"))))],t.ArrowFunctionExpression([t.Identifier("$$val")],t.BlockStatement(n)))))}}var n,s},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.3",
"version": "0.2.4",
"description": "Babel syntactic sugar for v-bind sync modifier support in Vue JSX",

@@ -5,0 +5,0 @@ "keywords": [

@@ -22,2 +22,4 @@ import { it, expect } from 'vitest'

<component visible_sync={this.test} on={{click:this.test}}>This will be ok</component>
{/* a sync prop & spread props */}
<component visible_sync={this.test.a} {...{ props: { foo: 'bar' } }}>This will be ok</component>
</div>

@@ -24,0 +26,0 @@ )

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc