Skip to content

Commit

Permalink
fix(runtime-core): fix erraneous emits warnings w/ mixins
Browse files Browse the repository at this point in the history
fix #2651
  • Loading branch information
yyx990803 committed Mar 26, 2021
1 parent d5824b9 commit 60d777d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/runtime-core/__tests__/componentEmits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ describe('component: emit', () => {
expect(`event validation failed for event "foo"`).toHaveBeenWarned()
})

// #2651
test('should not attach normalized object when mixins do not contain emits', () => {
const Foo = defineComponent({
mixins: [{}],
render() {},
created() {
this.$emit('foo')
}
})
render(h(Foo), nodeOps.createElement('div'))
expect(
`Component emitted event "foo" but it is neither declared`
).not.toHaveBeenWarned()
})

test('.once', () => {
const Foo = defineComponent({
render() {},
Expand Down
7 changes: 5 additions & 2 deletions packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ export function normalizeEmitsOptions(
let hasExtends = false
if (__FEATURE_OPTIONS_API__ && !isFunction(comp)) {
const extendEmits = (raw: ComponentOptions) => {
hasExtends = true
extend(normalized, normalizeEmitsOptions(raw, appContext, true))
const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true)
if (normalizedFromExtend) {
hasExtends = true
extend(normalized, normalizedFromExtend)
}
}
if (!asMixin && appContext.mixins.length) {
appContext.mixins.forEach(extendEmits)
Expand Down

0 comments on commit 60d777d

Please sign in to comment.