JuniorTour / vue-template-babel-compiler

Enable Optional Chaining(?.), Nullish Coalescing(??) and many new ES syntax for Vue.js SFC based on Babel
https://www.npmjs.com/package/vue-template-babel-compiler
118 stars 9 forks source link

[Fixed Bug] template里面写对象方法的简写形式报错 #42

Open jayzun opened 2 years ago

jayzun commented 2 years ago
<div :rules="[{ transform(value) { return +value} }]"></div>

改成这样就不报错

<div :rules="[{ transform: function(value) { return +value} }]"></div>

报错信息:

[vite-plugin-vue2] /Users/admin/work/code/brick/esop2-support/VueTemplateBabelCompiler: Property key of ObjectMethod expected node to be of a type ["Identifier","StringLiteral","NumericLiteral"] but instead got "MemberExpression"

JuniorTour commented 2 years ago

这是个BUG。感谢你的反馈😊

shouldPrependVm()[objectMethod](https://babeljs.io/docs/en/babel-types#objectmethod)类型的AST节点,错误地返回了 true,给transform()错误地加上了_vm.前置。

我们增加一个 t.isObjectMethod(path.container) 应该能修复问题。

7589f0f50d989df466e46b10c77d089

欢迎你发个 PullRequest 修复这个问题!

你可以参考 CONTRIBUTING.md 调试、增加测试用例、创建 PR.

JuniorTour commented 1 year ago

This issue has been fixed by v2.0, try it by: npm install vue-template-babel-compiler@latest