refactor(compiler): improve member expression check for v-on & v-model
This commit is contained in:
@@ -203,7 +203,7 @@ export function processExpression(
|
||||
|
||||
let ret
|
||||
if (children.length) {
|
||||
ret = createCompoundExpression(children)
|
||||
ret = createCompoundExpression(children, node.loc)
|
||||
} else {
|
||||
ret = node
|
||||
}
|
||||
|
||||
@@ -7,21 +7,23 @@ import {
|
||||
Property
|
||||
} from '../ast'
|
||||
import { createCompilerError, ErrorCodes } from '../errors'
|
||||
import { isEmptyExpression } from '../utils'
|
||||
import { isMemberExpression } from '../utils'
|
||||
|
||||
export const transformModel: DirectiveTransform = (dir, node, context) => {
|
||||
const { exp, arg } = dir
|
||||
if (!exp) {
|
||||
context.onError(createCompilerError(ErrorCodes.X_V_MODEL_NO_EXPRESSION))
|
||||
|
||||
context.onError(
|
||||
createCompilerError(ErrorCodes.X_V_MODEL_NO_EXPRESSION, dir.loc)
|
||||
)
|
||||
return createTransformProps()
|
||||
}
|
||||
|
||||
if (isEmptyExpression(exp)) {
|
||||
const expString =
|
||||
exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content : exp.loc.source
|
||||
if (!isMemberExpression(expString)) {
|
||||
context.onError(
|
||||
createCompilerError(ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION)
|
||||
createCompilerError(ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION, exp.loc)
|
||||
)
|
||||
|
||||
return createTransformProps()
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
import { capitalize } from '@vue/shared'
|
||||
import { createCompilerError, ErrorCodes } from '../errors'
|
||||
import { processExpression } from './transformExpression'
|
||||
import { isMemberExpression } from '../utils'
|
||||
|
||||
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/
|
||||
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
|
||||
|
||||
// v-on without arg is handled directly in ./element.ts due to it affecting
|
||||
// codegen for the entire props object. This transform here is only for v-on
|
||||
@@ -49,7 +49,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
||||
// skipped by transformExpression as a special case.
|
||||
let exp: ExpressionNode = dir.exp as SimpleExpressionNode
|
||||
const isInlineStatement = !(
|
||||
simplePathRE.test(exp.content) || fnExpRE.test(exp.content)
|
||||
isMemberExpression(exp.content) || fnExpRE.test(exp.content)
|
||||
)
|
||||
// process the expression since it's been skipped
|
||||
if (!__BROWSER__ && context.prefixIdentifiers) {
|
||||
|
||||
Reference in New Issue
Block a user