Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
const stripParensRE = /^\(|\)$/g
const dynamicArgRE = /^\[.*\]$/

const colonDirRE = /^:v-/
const argRE = /:(.*)$/
export const bindRE = /^:|^\.|^v-bind:/
const propBindRE = /^\./
Expand Down Expand Up @@ -761,6 +762,12 @@ function processAttrs (el) {
for (i = 0, l = list.length; i < l; i++) {
name = rawName = list[i].name
value = list[i].value
// :v-if or similar
if (process.env.NODE_ENV !== 'production' && colonDirRE.test(name)) {
warn(
`A v-bind shorthand was used on another Vue directive. Did you mean '${name.substr(1)}="${value}"' instead of '${name}="${value}"'?`
)
}
if (dirRE.test(name)) {
// mark element as dynamic
el.hasBindings = true
Expand Down
5 changes: 5 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ describe('parser', () => {
expect(ast.props[0].value).toBe('msg')
})

it('warns when using v-bind shorthand on a directive', () => {
parse('<div :v-if="foo"></div>', baseOptions)
expect(`A v-bind shorthand was used on another Vue directive. Did you mean 'v-if="foo"' instead of ':v-if="foo"'?`).toHaveBeenWarned()
})

it('empty v-bind expression', () => {
parse('<div :empty-msg=""></div>', baseOptions)
expect('The value for a v-bind expression cannot be empty. Found in "v-bind:empty-msg"').toHaveBeenWarned()
Expand Down