Skip to content

Commit

Permalink
feat: Warn on colon shorthand usage on directive
Browse files Browse the repository at this point in the history
  • Loading branch information
afontcu committed Jun 25, 2019
1 parent 3b8925b commit 4da92f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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 directive was used on another Vue directive. Did you want to write '${name.substr(1)}="${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('v-bind expression on directive', () => {
parse('<div :v-if="foo"></div>', baseOptions)
expect(`A v-bind shorthand directive was used on another Vue directive. Did you want to write '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

0 comments on commit 4da92f0

Please sign in to comment.