Skip to content
Merged
Changes from all 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
14 changes: 9 additions & 5 deletions packages/app-backend-vue3/src/components/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BackendContext } from '@vue-devtools/app-backend-api'
import { getInstanceName, getUniqueComponentId } from './util'
import { camelize, StateEditor, SharedData } from '@vue-devtools/shared-utils'
import { camelize, StateEditor, SharedData, kebabize } from '@vue-devtools/shared-utils'
import { ComponentInstance, CustomState, HookPayloads, Hooks, InspectedComponentData } from '@vue/devtools-api'
import { returnError } from '../util'

Expand Down Expand Up @@ -371,20 +371,24 @@ function processRefs (instance) {
function processEventListeners (instance) {
const emitsDefinition = instance.type.emits
const declaredEmits = Array.isArray(emitsDefinition) ? emitsDefinition : Object.keys(emitsDefinition ?? {})
const declaredEmitsMap = declaredEmits.reduce((emitsMap, key) => {
emitsMap[kebabize(key)] = key
return emitsMap
}, {})
const keys = Object.keys(instance.vnode.props ?? {})
const result = []
for (const key of keys) {
const [prefix, ...eventNameParts] = key.split(/(?=[A-Z])/)
if (prefix === 'on') {
const eventName = eventNameParts.join('-').toLowerCase()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line makes the eventName kebabized.

But the variable declaredEmits is a mixed case array, which will cause a mismatch.

const isDeclared = declaredEmits.includes(eventName)
const normalizedEventName = declaredEmitsMap[eventName]
result.push({
type: 'event listeners',
key: eventName,
key: normalizedEventName || eventName,
value: {
_custom: {
display: isDeclared ? '✅ Declared' : '⚠️ Not declared',
tooltip: !isDeclared ? `The event <code>${eventName}</code> is not declared in the <code>emits</code> option. It will leak into the component's attributes (<code>$attrs</code>).` : null,
display: normalizedEventName ? '✅ Declared' : '⚠️ Not declared',
tooltip: !normalizedEventName ? `The event <code>${eventName}</code> is not declared in the <code>emits</code> option. It will leak into the component's attributes (<code>$attrs</code>).` : null,
},
},
})
Expand Down