Skip to content

Commit

Permalink
fix: fix modifier parsing for dynamic argument with deep path (vuejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shasharoman authored and Lostlover committed Dec 10, 2019
1 parent 7aae458 commit 06cd275
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const dynamicArgRE = /^\[.*\]$/
const argRE = /:(.*)$/
export const bindRE = /^:|^\.|^v-bind:/
const propBindRE = /^\./
const modifierRE = /\.[^.]+/g
const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g

const slotRE = /^v-slot(:|$)|^#/

Expand Down
78 changes: 78 additions & 0 deletions test/unit/features/options/directives.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,82 @@ describe('Options directives', () => {
}).$mount()
vm.key = 'bar'
})

it('deep object like `deep.a` as dynamic arguments', done => {
const vm = new Vue({
template: `<div v-my:[deep.a]="1"/>`,
data: {
deep: {
a: 'foo'
}
},
directives: {
my: {
bind(el, binding) {
expect(binding.arg).toBe('foo')
},
update(el, binding) {
expect(binding.arg).toBe('bar')
expect(binding.oldArg).toBe('foo')
done()
}
}
}
}).$mount()
vm.deep.a = 'bar'
})

it('deep object like `deep.a.b` as dynamic arguments', done => {
const vm = new Vue({
template: `<div v-my:[deep.a.b]="1"/>`,
data: {
deep: {
a: {
b: 'foo'
}
}
},
directives: {
my: {
bind(el, binding) {
expect(binding.arg).toBe('foo')
},
update(el, binding) {
expect(binding.arg).toBe('bar')
expect(binding.oldArg).toBe('foo')
done()
}
}
}
}).$mount()
vm.deep.a.b = 'bar'
})

it('deep object as dynamic arguments with modifiers', done => {
const vm = new Vue({
template: `<div v-my:[deep.a.b].x.y="1"/>`,
data: {
deep: {
a: {
b: 'foo'
}
}
},
directives: {
my: {
bind(el, binding) {
expect(binding.arg).toBe('foo')
expect(binding.modifiers.x).toBe(true)
expect(binding.modifiers.y).toBe(true)
},
update(el, binding) {
expect(binding.arg).toBe('bar')
expect(binding.oldArg).toBe('foo')
done()
}
}
}
}).$mount()
vm.deep.a.b = 'bar'
})
})

0 comments on commit 06cd275

Please sign in to comment.