Skip to content

Commit

Permalink
Merge pull request #43 from dandanDQ/main
Browse files Browse the repository at this point in the history
fix: support object method #42
  • Loading branch information
JuniorTour committed Jul 18, 2022
2 parents 8b7451f + 04371c0 commit a17048f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function shouldPrependVm(path) {
&& !t$1.isObjectPattern(parent.parent) // skip globals + commonly used shorthands
&& !hash[nodeName] // not cur function param
&& !(scope !== null && scope !== void 0 && (_scope$block$params = scope.block.params) !== null && _scope$block$params !== void 0 && _scope$block$params.find(node => node.name === nodeName)) // not already in scope
&& !inScope(scope, nodeName)) {
&& !inScope(scope, nodeName) && !t$1.isObjectMethod(path.container)) {
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/utils/shouldPrependVM.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function shouldPrependVm(path) {
&& !scope?.block.params?.find(node => node.name === nodeName)
// not already in scope
&& !inScope(scope, nodeName)
&& !t.isObjectMethod(path.container)
) {
return true
}
Expand Down
12 changes: 12 additions & 0 deletions test/compileRender.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,15 @@ test('spread should allowArrayLike ', () => {

expect(vm.$el.innerHTML).toMatch('1')
})

test('should work for object method', () => {
const vm = new Vue({
...compileAsFunctions(`
<div>
<h1 :rules="[{ transform(value) { return +value} }]">object method worked</h1>
</div>
`),
}).$mount()

expect(vm.$el.innerHTML).toMatch(`<h1 rules=\"[object Object]\">object method worked</h1>`)
})

0 comments on commit a17048f

Please sign in to comment.