mirror of https://github.com/vuejs/core.git
refactor: fix v-bind no-exp shorthand for new parser
This commit is contained in:
parent
e5afca6c1e
commit
94c86269d0
|
@ -80,32 +80,16 @@ describe('compiler: transform v-bind', () => {
|
||||||
content: `id`,
|
content: `id`,
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
loc: {
|
loc: {
|
||||||
start: {
|
start: { line: 1, column: 13, offset: 12 },
|
||||||
line: 1,
|
end: { line: 1, column: 15, offset: 14 }
|
||||||
column: 13,
|
|
||||||
offset: 12
|
|
||||||
},
|
|
||||||
end: {
|
|
||||||
line: 1,
|
|
||||||
column: 15,
|
|
||||||
offset: 14
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
content: `id`,
|
content: `id`,
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
loc: {
|
loc: {
|
||||||
start: {
|
start: { line: 1, column: 13, offset: 12 },
|
||||||
line: 1,
|
end: { line: 1, column: 15, offset: 14 }
|
||||||
column: 1,
|
|
||||||
offset: 0
|
|
||||||
},
|
|
||||||
end: {
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
offset: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,7 +3,6 @@ import {
|
||||||
createObjectProperty,
|
createObjectProperty,
|
||||||
createSimpleExpression,
|
createSimpleExpression,
|
||||||
ExpressionNode,
|
ExpressionNode,
|
||||||
locStub,
|
|
||||||
NodeTypes
|
NodeTypes
|
||||||
} from '../ast'
|
} from '../ast'
|
||||||
import { createCompilerError, ErrorCodes } from '../errors'
|
import { createCompilerError, ErrorCodes } from '../errors'
|
||||||
|
@ -18,6 +17,16 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
|
||||||
const { modifiers, loc } = dir
|
const { modifiers, loc } = dir
|
||||||
const arg = dir.arg!
|
const arg = dir.arg!
|
||||||
|
|
||||||
|
// :arg is replaced by :arg="arg"
|
||||||
|
let { exp } = dir
|
||||||
|
if (!exp && arg.type === NodeTypes.SIMPLE_EXPRESSION) {
|
||||||
|
const propName = camelize(arg.content)
|
||||||
|
exp = dir.exp = createSimpleExpression(propName, false, arg.loc)
|
||||||
|
if (!__BROWSER__) {
|
||||||
|
exp = dir.exp = processExpression(exp, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION) {
|
||||||
arg.children.unshift(`(`)
|
arg.children.unshift(`(`)
|
||||||
arg.children.push(`) || ""`)
|
arg.children.push(`) || ""`)
|
||||||
|
@ -48,18 +57,6 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// :arg is replaced by :arg="arg"
|
|
||||||
let { exp } = dir
|
|
||||||
if (!exp && arg.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
||||||
const propName = camelize(arg.loc.source)
|
|
||||||
const simpleExpression = createSimpleExpression(propName, false, {
|
|
||||||
...locStub,
|
|
||||||
source: propName
|
|
||||||
})
|
|
||||||
|
|
||||||
exp = dir.exp = processExpression(simpleExpression, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!exp ||
|
!exp ||
|
||||||
(exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())
|
(exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())
|
||||||
|
|
Loading…
Reference in New Issue