feat(compile-core): handle falsy dynamic args for v-on and v-bind (#2393)
fix #2388
This commit is contained in:
@@ -10,6 +10,14 @@ import { CAMELIZE } from '../runtimeHelpers'
|
||||
export const transformBind: DirectiveTransform = (dir, node, context) => {
|
||||
const { exp, modifiers, loc } = dir
|
||||
const arg = dir.arg!
|
||||
|
||||
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
||||
arg.children.unshift(`(`)
|
||||
arg.children.push(`) || ""`)
|
||||
} else if (!arg.isStatic) {
|
||||
arg.content = `${arg.content} || ""`
|
||||
}
|
||||
|
||||
// .prop is no longer necessary due to new patch behavior
|
||||
// .sync is replaced by v-model:arg
|
||||
if (modifiers.includes('camel')) {
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { DirectiveTransform, DirectiveTransformResult } from '../transform'
|
||||
import {
|
||||
DirectiveNode,
|
||||
createCompoundExpression,
|
||||
createObjectProperty,
|
||||
createSimpleExpression,
|
||||
DirectiveNode,
|
||||
ElementTypes,
|
||||
ExpressionNode,
|
||||
NodeTypes,
|
||||
createCompoundExpression,
|
||||
SimpleExpressionNode,
|
||||
ElementTypes
|
||||
SimpleExpressionNode
|
||||
} from '../ast'
|
||||
import { capitalize, camelize } from '@vue/shared'
|
||||
import { camelize, toHandlerKey } from '@vue/shared'
|
||||
import { createCompilerError, ErrorCodes } from '../errors'
|
||||
import { processExpression } from './transformExpression'
|
||||
import { validateBrowserExpression } from '../validateExpression'
|
||||
import { isMemberExpression, hasScopeRef } from '../utils'
|
||||
import { CAPITALIZE } from '../runtimeHelpers'
|
||||
import { hasScopeRef, isMemberExpression } from '../utils'
|
||||
import { TO_HANDLER_KEY } from '../runtimeHelpers'
|
||||
|
||||
const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/
|
||||
|
||||
@@ -43,11 +43,15 @@ export const transformOn: DirectiveTransform = (
|
||||
if (arg.isStatic) {
|
||||
const rawName = arg.content
|
||||
// for all event listeners, auto convert it to camelCase. See issue #2249
|
||||
const normalizedName = capitalize(camelize(rawName))
|
||||
eventName = createSimpleExpression(`on${normalizedName}`, true, arg.loc)
|
||||
eventName = createSimpleExpression(
|
||||
toHandlerKey(camelize(rawName)),
|
||||
true,
|
||||
arg.loc
|
||||
)
|
||||
} else {
|
||||
// #2388
|
||||
eventName = createCompoundExpression([
|
||||
`"on" + ${context.helperString(CAPITALIZE)}(`,
|
||||
`${context.helperString(TO_HANDLER_KEY)}(`,
|
||||
arg,
|
||||
`)`
|
||||
])
|
||||
@@ -55,7 +59,7 @@ export const transformOn: DirectiveTransform = (
|
||||
} else {
|
||||
// already a compound expression.
|
||||
eventName = arg
|
||||
eventName.children.unshift(`"on" + ${context.helperString(CAPITALIZE)}(`)
|
||||
eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`)
|
||||
eventName.children.push(`)`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user