Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit cfdb0f0

Browse files
Jevon617sxzz
authored andcommitted
feat(runtime-vapor): emit function add dev warnning
1 parent 2f3627a commit cfdb0f0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/runtime-vapor/src/componentEmits.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
type StaticProps,
2424
getDynamicPropValue,
2525
} from './componentProps'
26+
import { warn } from './warning'
2627

2728
export type ObjectEmitsOptions = Record<
2829
string,
@@ -54,6 +55,33 @@ export function emit(
5455
) {
5556
if (instance.isUnmounted) return
5657
// TODO
58+
if (__DEV__) {
59+
const {
60+
emitsOptions,
61+
propsOptions: [propsOptions],
62+
} = instance
63+
if (emitsOptions) {
64+
if (!(event in emitsOptions)) {
65+
if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
66+
warn(
67+
`Component emitted event "${event}" but it is neither declared in ` +
68+
`the emits option nor as an "${toHandlerKey(event)}" prop.`,
69+
)
70+
}
71+
} else {
72+
const validator = emitsOptions[event]
73+
if (isFunction(validator)) {
74+
const isValid = validator(...rawArgs)
75+
if (!isValid) {
76+
warn(
77+
`Invalid event arguments: event validation failed for event "${event}".`,
78+
)
79+
}
80+
}
81+
}
82+
}
83+
}
84+
5785
const { rawProps, emitsOptions } = instance
5886
const hasDynamicProps = rawProps.some(isFunction)
5987
const events: Record<string, (...args: any[]) => any> = {}

0 commit comments

Comments
 (0)