Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#9577): support deep object as dynamic arguments #9585

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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
shasharoman marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -906,7 +906,7 @@ function parseModifiers (name: string): Object | void {
const match = name.match(modifierRE)
if (match) {
const ret = {}
match.forEach(m => { ret[m.slice(1)] = true })
match[0].slice(1).split('.').forEach(item => ret[item] = true)
return ret
}
}
Expand Down
50 changes: 50 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,54 @@ 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'
shasharoman marked this conversation as resolved.
Show resolved Hide resolved
})
shasharoman marked this conversation as resolved.
Show resolved Hide resolved
})