@vue/babel-sugar-composition-api-render-instance
Advanced tools
Comparing version 1.2.1 to 1.2.4
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var syntaxJsx=_interopDefault(require("@babel/plugin-syntax-jsx"));const autoImportGetCurrentInstance=(e,t)=>{const n=t.get("body").filter(e=>e.isImportDeclaration()).map(e=>e.node);const i=n.filter(e=>"@vue/composition-api"===e.source.value);const o=i.some(t=>t.specifiers.some(t=>e.isImportSpecifier(t)&&"getCurrentInstance"===t.local.name));if(!o){const n=e.importSpecifier(e.identifier("getCurrentInstance"),e.identifier("getCurrentInstance"));i.length>0?i[0].specifiers.push(n):t.unshiftContainer("body",e.importDeclaration([n],e.stringLiteral("@vue/composition-api")))}};var index=({types:t})=>({inherits:syntaxJsx,visitor:{Program(e){e.traverse({"ObjectMethod|ObjectProperty"(n){"setup"===n.node.key.name&&n.traverse({JSXAttribute(n){const i=n.get("name");["v-on","on-input","on-change","model"].includes(i.node.name)&&n.traverse({MemberExpression(n){const i=n.get("object"),o=n.get("property");t.isThisExpression(i)&&t.isIdentifier(o)&&["$","_"].includes(o.node.name[0])&&(autoImportGetCurrentInstance(t,e),i.replaceWith(t.callExpression(t.identifier("getCurrentInstance"),[])))}})}})}})}}});module.exports=index; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var syntaxJsx=_interopDefault(require("@babel/plugin-syntax-jsx"));const autoImportGetCurrentInstance=(e,t)=>{const n=t.get("body").filter(e=>e.isImportDeclaration()).map(e=>e.node);const i=n.filter(e=>"@vue/composition-api"===e.source.value);const o=i.some(t=>t.specifiers.some(t=>e.isImportSpecifier(t)&&"getCurrentInstance"===t.local.name));if(!o){const n=e.importSpecifier(e.identifier("getCurrentInstance"),e.identifier("getCurrentInstance"));i.length>0?i[0].specifiers.push(n):t.unshiftContainer("body",e.importDeclaration([n],e.stringLiteral("@vue/composition-api")))}},injectInstanceId="__currentInstance";var index=({types:t})=>({inherits:syntaxJsx,visitor:{Program(e){e.traverse({"ObjectMethod|ObjectProperty"(n){if("setup"===n.node.key.name){let i=!1;n.traverse({JSXAttribute(o){const r=o.get("name");["v-on","on-input","on-change","model"].includes(r.node.name)&&o.traverse({MemberExpression(o){const r=o.get("object"),s=o.get("property");t.isThisExpression(r)&&t.isIdentifier(s)&&["$","_"].includes(s.node.name[0])&&(autoImportGetCurrentInstance(t,e),i||(n.node.value.body.body.unshift(t.variableDeclaration("const",[t.variableDeclarator(t.identifier(injectInstanceId),t.callExpression(t.identifier("getCurrentInstance"),[]))])),i=!0),r.replaceWith(t.identifier(injectInstanceId)))}})}})}}})}}});module.exports=index; |
{ | ||
"name": "@vue/babel-sugar-composition-api-render-instance", | ||
"version": "1.2.1", | ||
"version": "1.2.4", | ||
"description": "Babel syntactic sugar for replaceing `this` with `getCurrentInstance()` in Vue JSX with @vue/composition-api", | ||
@@ -45,3 +45,3 @@ "main": "dist/plugin.js", | ||
}, | ||
"gitHead": "ebe50c0f20b991fca6588cab93965629ffbcf64f" | ||
"gitHead": "3a12ae2c13de6fdb47dce4394d26c74e048a25b6" | ||
} |
@@ -40,3 +40,5 @@ ## @vue/babel-sugar-composition-api-render-instance | ||
defineComponent({ | ||
setup: () => <MyComponent vModel={a.b} /> | ||
setup() { | ||
return () => <MyComponent vModel={a.b} /> | ||
} | ||
}) | ||
@@ -49,8 +51,10 @@ ``` | ||
defineComponent({ | ||
setup: () => <MyComponent model={{ | ||
value: a.b, | ||
callback: $$v => { | ||
this.$set(a, "b", $$v); | ||
} | ||
}} />; | ||
setup() { | ||
return () => <MyComponent model={{ | ||
value: a.b, | ||
callback: $$v => { | ||
this.$set(a, "b", $$v); | ||
} | ||
}} /> | ||
} | ||
}) | ||
@@ -65,9 +69,13 @@ ``` | ||
defineComponent({ | ||
setup: () => <MyComponent model={{ | ||
value: a.b, | ||
callback: $$v => { | ||
getCurrentInstance().$set(a, "b", $$v); | ||
} | ||
}} />; | ||
setup() { | ||
const __currentInstance = getCurrentInstance(); | ||
return () => <MyComponent model={{ | ||
value: a.b, | ||
callback: $$v => { | ||
__currentInstance.$set(a, "b", $$v); | ||
} | ||
}} /> | ||
} | ||
}) | ||
``` |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
4515
6
79