Skip to content

Commit 060c3b9

Browse files
shasharomanyyx990803
authored andcommitted
fix: fix modifier parsing for dynamic argument with deep path (#9585)
fix #9577
1 parent 2ec5b64 commit 060c3b9

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/compiler/parser/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const dynamicArgRE = /^\[.*\]$/
3333
const argRE = /:(.*)$/
3434
export const bindRE = /^:|^\.|^v-bind:/
3535
const propBindRE = /^\./
36-
const modifierRE = /\.[^.]+/g
36+
const modifierRE = /\.[^.\]]+(?=[^\]]*$)/g
3737

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

test/unit/features/options/directives.spec.js

+78
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,82 @@ describe('Options directives', () => {
287287
}).$mount()
288288
vm.key = 'bar'
289289
})
290+
291+
it('deep object like `deep.a` as dynamic arguments', done => {
292+
const vm = new Vue({
293+
template: `<div v-my:[deep.a]="1"/>`,
294+
data: {
295+
deep: {
296+
a: 'foo'
297+
}
298+
},
299+
directives: {
300+
my: {
301+
bind(el, binding) {
302+
expect(binding.arg).toBe('foo')
303+
},
304+
update(el, binding) {
305+
expect(binding.arg).toBe('bar')
306+
expect(binding.oldArg).toBe('foo')
307+
done()
308+
}
309+
}
310+
}
311+
}).$mount()
312+
vm.deep.a = 'bar'
313+
})
314+
315+
it('deep object like `deep.a.b` as dynamic arguments', done => {
316+
const vm = new Vue({
317+
template: `<div v-my:[deep.a.b]="1"/>`,
318+
data: {
319+
deep: {
320+
a: {
321+
b: 'foo'
322+
}
323+
}
324+
},
325+
directives: {
326+
my: {
327+
bind(el, binding) {
328+
expect(binding.arg).toBe('foo')
329+
},
330+
update(el, binding) {
331+
expect(binding.arg).toBe('bar')
332+
expect(binding.oldArg).toBe('foo')
333+
done()
334+
}
335+
}
336+
}
337+
}).$mount()
338+
vm.deep.a.b = 'bar'
339+
})
340+
341+
it('deep object as dynamic arguments with modifiers', done => {
342+
const vm = new Vue({
343+
template: `<div v-my:[deep.a.b].x.y="1"/>`,
344+
data: {
345+
deep: {
346+
a: {
347+
b: 'foo'
348+
}
349+
}
350+
},
351+
directives: {
352+
my: {
353+
bind(el, binding) {
354+
expect(binding.arg).toBe('foo')
355+
expect(binding.modifiers.x).toBe(true)
356+
expect(binding.modifiers.y).toBe(true)
357+
},
358+
update(el, binding) {
359+
expect(binding.arg).toBe('bar')
360+
expect(binding.oldArg).toBe('foo')
361+
done()
362+
}
363+
}
364+
}
365+
}).$mount()
366+
vm.deep.a.b = 'bar'
367+
})
290368
})

0 commit comments

Comments
 (0)