feat(compile-core): handle falsy dynamic args for v-on and v-bind (#2393)

fix #2388
This commit is contained in:
ᴜɴвʏтᴇ
2020-10-20 05:15:53 +08:00
committed by GitHub
parent 7390487c7d
commit 052a621762
15 changed files with 96 additions and 71 deletions

View File

@@ -71,7 +71,7 @@ describe('compiler: transform v-bind', () => {
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
expect(props.properties[0]).toMatchObject({
key: {
content: `id`,
content: `id || ""`,
isStatic: false
},
value: {
@@ -130,7 +130,7 @@ describe('compiler: transform v-bind', () => {
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
expect(props.properties[0]).toMatchObject({
key: {
content: `_${helperNameMap[CAMELIZE]}(foo)`,
content: `_${helperNameMap[CAMELIZE]}(foo || "")`,
isStatic: false
},
value: {
@@ -149,10 +149,12 @@ describe('compiler: transform v-bind', () => {
key: {
children: [
`_${helperNameMap[CAMELIZE]}(`,
`(`,
{ content: `_ctx.foo` },
`(`,
{ content: `_ctx.bar` },
`)`,
`) || ""`,
`)`
]
},

View File

@@ -1,14 +1,14 @@
import {
baseParse as parse,
transform,
ElementNode,
ObjectExpression,
CompilerOptions,
ElementNode,
ErrorCodes,
NodeTypes,
VNodeCall,
TO_HANDLER_KEY,
helperNameMap,
CAPITALIZE
NodeTypes,
ObjectExpression,
transform,
VNodeCall
} from '../../src'
import { transformOn } from '../../src/transforms/vOn'
import { transformElement } from '../../src/transforms/transformElement'
@@ -76,7 +76,7 @@ describe('compiler: transform v-on', () => {
key: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`"on" + _${helperNameMap[CAPITALIZE]}(`,
`_${helperNameMap[TO_HANDLER_KEY]}(`,
{ content: `event` },
`)`
]
@@ -101,7 +101,7 @@ describe('compiler: transform v-on', () => {
key: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`"on" + _${helperNameMap[CAPITALIZE]}(`,
`_${helperNameMap[TO_HANDLER_KEY]}(`,
{ content: `_ctx.event` },
`)`
]
@@ -126,7 +126,7 @@ describe('compiler: transform v-on', () => {
key: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`"on" + _${helperNameMap[CAPITALIZE]}(`,
`_${helperNameMap[TO_HANDLER_KEY]}(`,
{ content: `_ctx.event` },
`(`,
{ content: `_ctx.foo` },