test: tests for v-on transform

This commit is contained in:
Evan You
2019-09-24 22:39:20 -04:00
parent 597ada36ed
commit 84909648e7
8 changed files with 182 additions and 26 deletions

View File

@@ -15,7 +15,11 @@ import {
IfBranchNode
} from './ast'
import { SourceMapGenerator, RawSourceMap } from 'source-map'
import { advancePositionWithMutation, assert } from './utils'
import {
advancePositionWithMutation,
assert,
isSimpleIdentifier
} from './utils'
import { isString, isArray } from '@vue/shared'
import {
RENDER_LIST,
@@ -325,7 +329,7 @@ function genExpressionAsPropertyKey(
push(`]`)
} else if (isStatic) {
// only quote keys if necessary
const text = /^\d|[^\w]/.test(content) ? JSON.stringify(content) : content
const text = isSimpleIdentifier(content) ? content : JSON.stringify(content)
push(text, node)
} else {
push(`[${content}]`, node)
@@ -366,9 +370,10 @@ function genIfBranch(
if (condition) {
// v-if or v-else-if
const { push, indent, deindent, newline } = context
push(`(`)
const needsQuote = !isSimpleIdentifier(condition.content)
needsQuote && push(`(`)
genExpression(condition, context)
push(`)`)
needsQuote && push(`)`)
indent()
context.indentLevel++
push(`? `)