diff --git a/packages/babel-sugar-functional-vue/src/index.js b/packages/babel-sugar-functional-vue/src/index.js
index 985a85f..55c5513 100644
--- a/packages/babel-sugar-functional-vue/src/index.js
+++ b/packages/babel-sugar-functional-vue/src/index.js
@@ -1,22 +1,5 @@
import syntaxJsx from '@babel/plugin-syntax-jsx'
-/**
- * Check if expression is in method
- * @param t
- * @param path
- * @param parentLimitPath
- * @returns boolean
- */
-const isInMethod = (t, path, parentLimitPath) => {
- if (!path || path === parentLimitPath) {
- return false
- }
- if (t.isObjectMethod(path)) {
- return true
- }
- return isInMethod(t, path.parentPath, parentLimitPath)
-}
-
/**
* Check path has JSX
* @param t
@@ -25,13 +8,24 @@ const isInMethod = (t, path, parentLimitPath) => {
*/
const hasJSX = (t, path) => {
let hasJSX = false
+ let parentScope
path.traverse({
JSXElement(elPath) {
- if (!isInMethod(t, elPath, path)) {
+ if (parentScope === elPath.scope) {
hasJSX = true
}
},
+
+ ArrowFunctionExpression(blockPath) {
+ const isParent = blockPath.parentPath === path
+
+ if (!isParent) {
+ return
+ }
+
+ parentScope = blockPath.scope
+ },
})
return hasJSX
diff --git a/packages/babel-sugar-functional-vue/test/test.js b/packages/babel-sugar-functional-vue/test/test.js
index abee254..12ccd96 100644
--- a/packages/babel-sugar-functional-vue/test/test.js
+++ b/packages/babel-sugar-functional-vue/test/test.js
@@ -75,6 +75,23 @@ const tests = [
}
});`,
+ },
+ {
+ name: 'Wrapper of function does not compile',
+ from: `const Wrapped = () => wrap(() => )`,
+ to: `const Wrapped = () => wrap(() => );`,
+ },
+ {
+ name: 'If JSX in function arguments does not compile',
+ from: `const Wrapped = (jsx = () => ) => jsx`,
+ to: `const Wrapped = (jsx = () => ) => jsx;`,
+ },
+ {
+ name: 'If JSX in nested function does not compile',
+ from: `const Wrapped = () => function () { return }`,
+ to: `const Wrapped = () => function () {
+ return ;
+};`,
},
{
name: 'Default export',