fix(runtime-core): fix emit listener check on kebab-case events (#2542)
fix #2540
This commit is contained in:
parent
2ab8c41a1a
commit
3532b2b021
@ -283,12 +283,23 @@ describe('component: emit', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('isEmitListener', () => {
|
test('isEmitListener', () => {
|
||||||
const options = { click: null }
|
const options = {
|
||||||
|
click: null,
|
||||||
|
'test-event': null,
|
||||||
|
fooBar: null,
|
||||||
|
FooBaz: null
|
||||||
|
}
|
||||||
expect(isEmitListener(options, 'onClick')).toBe(true)
|
expect(isEmitListener(options, 'onClick')).toBe(true)
|
||||||
expect(isEmitListener(options, 'onclick')).toBe(false)
|
expect(isEmitListener(options, 'onclick')).toBe(false)
|
||||||
expect(isEmitListener(options, 'onBlick')).toBe(false)
|
expect(isEmitListener(options, 'onBlick')).toBe(false)
|
||||||
// .once listeners
|
// .once listeners
|
||||||
expect(isEmitListener(options, 'onClickOnce')).toBe(true)
|
expect(isEmitListener(options, 'onClickOnce')).toBe(true)
|
||||||
expect(isEmitListener(options, 'onclickOnce')).toBe(false)
|
expect(isEmitListener(options, 'onclickOnce')).toBe(false)
|
||||||
|
// kebab-case option
|
||||||
|
expect(isEmitListener(options, 'onTestEvent')).toBe(true)
|
||||||
|
// camelCase option
|
||||||
|
expect(isEmitListener(options, 'onFooBar')).toBe(true)
|
||||||
|
// PascalCase option
|
||||||
|
expect(isEmitListener(options, 'onFooBaz')).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -201,9 +201,10 @@ export function isEmitListener(
|
|||||||
if (!options || !isOn(key)) {
|
if (!options || !isOn(key)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
key = key.replace(/Once$/, '')
|
key = key.slice(2).replace(/Once$/, '')
|
||||||
return (
|
return (
|
||||||
hasOwn(options, key[2].toLowerCase() + key.slice(3)) ||
|
hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
|
||||||
hasOwn(options, key.slice(2))
|
hasOwn(options, hyphenate(key)) ||
|
||||||
|
hasOwn(options, key)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user