From ee4f9e7e9c2733329513b574f51b6e6dab6931d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Mart=C3=ADnez?= Date: Thu, 27 Jun 2019 03:02:30 +0200 Subject: [PATCH] feat(events): add .emit event modifier fix #9325 --- src/compiler/codegen/events.js | 1 + test/unit/features/directives/on.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index fc817c03d52..f95ea10a4a8 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -42,6 +42,7 @@ const genGuard = condition => `if(${condition})return null;` const modifierCode: { [key: string]: string } = { stop: '$event.stopPropagation();', prevent: '$event.preventDefault();', + emit: '$emit(arguments.callee.name, ...arguments)', self: genGuard(`$event.target !== $event.currentTarget`), ctrl: genGuard(`!$event.ctrlKey`), shift: genGuard(`!$event.shiftKey`), diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index b7801a82f22..1abdbbacbb9 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -102,6 +102,28 @@ describe('Directive v-on', () => { expect(spy).toHaveBeenCalledWith(true) }) + it('should support the .emit event modifier', () => { + vm = new Vue({ + el, + template: '', + methods: { foo: spy }, + components: { + bar: { + template: '', + components: { + emitter: { + template: '
', + mounted() { + this.$emit('custom', 'a', 'b') + } + } + } + } + } + }) + expect(spy).toHaveBeenCalledWith('a', 'b') + }) + it('should support capture', () => { const callOrder = [] vm = new Vue({