Skip to content

Commit f070560

Browse files
committed
fix: handle nullish dynamic event name with a modifier
1 parent 4fea167 commit f070560

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

packages/compiler-core/src/runtimeHelpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export const CAPITALIZE: unique symbol = Symbol(__DEV__ ? `capitalize` : ``)
6363
export const TO_HANDLER_KEY: unique symbol = Symbol(
6464
__DEV__ ? `toHandlerKey` : ``,
6565
)
66+
export const CHECK_DYNAMIC_EVENT: unique symbol = Symbol(
67+
__DEV__ ? `checkDynamicEvent` : ``,
68+
)
6669
export const SET_BLOCK_TRACKING: unique symbol = Symbol(
6770
__DEV__ ? `setBlockTracking` : ``,
6871
)
@@ -115,6 +118,7 @@ export const helperNameMap: Record<symbol, string> = {
115118
[CAMELIZE]: `camelize`,
116119
[CAPITALIZE]: `capitalize`,
117120
[TO_HANDLER_KEY]: `toHandlerKey`,
121+
[CHECK_DYNAMIC_EVENT]: `checkDynamicEvent`,
118122
[SET_BLOCK_TRACKING]: `setBlockTracking`,
119123
[PUSH_SCOPE_ID]: `pushScopeId`,
120124
[POP_SCOPE_ID]: `popScopeId`,

packages/compiler-dom/src/transforms/vOn.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CHECK_DYNAMIC_EVENT,
23
CompilerDeprecationTypes,
34
type DirectiveTransform,
45
type ExpressionNode,
@@ -144,7 +145,11 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
144145
const modifierPostfix = eventOptionModifiers.map(capitalize).join('')
145146
key = isStaticExp(key)
146147
? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
147-
: createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`])
148+
: createCompoundExpression([
149+
`${context.helperString(CHECK_DYNAMIC_EVENT)}(`,
150+
key,
151+
`,"${modifierPostfix}")`,
152+
])
148153
}
149154

150155
return {

packages/runtime-core/src/helpers/toHandlers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ export function toHandlers(
2323
}
2424
return ret
2525
}
26+
27+
export function checkDynamicEvent(
28+
eventName: string,
29+
modifierPostfix: string,
30+
): string {
31+
if (eventName != null && eventName !== '') return eventName + modifierPostfix
32+
return ''
33+
}

packages/runtime-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export {
358358
withScopeId,
359359
} from './componentRenderContext'
360360
export { renderList } from './helpers/renderList'
361-
export { toHandlers } from './helpers/toHandlers'
361+
export { toHandlers, checkDynamicEvent } from './helpers/toHandlers'
362362
export { renderSlot } from './helpers/renderSlot'
363363
export { createSlots } from './helpers/createSlots'
364364
export { withMemo, isMemoSame } from './helpers/withMemo'

0 commit comments

Comments
 (0)