Skip to content

Commit 4da92f0

Browse files
committed
feat: Warn on colon shorthand usage on directive
fix vuejs#10191
1 parent 3b8925b commit 4da92f0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: src/compiler/parser/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
3030
const stripParensRE = /^\(|\)$/g
3131
const dynamicArgRE = /^\[.*\]$/
3232

33+
const colonDirRE = /^:v-/
3334
const argRE = /:(.*)$/
3435
export const bindRE = /^:|^\.|^v-bind:/
3536
const propBindRE = /^\./
@@ -761,6 +762,12 @@ function processAttrs (el) {
761762
for (i = 0, l = list.length; i < l; i++) {
762763
name = rawName = list[i].name
763764
value = list[i].value
765+
// :v-if or similar
766+
if (process.env.NODE_ENV !== 'production' && colonDirRE.test(name)) {
767+
warn(
768+
`A v-bind shorthand directive was used on another Vue directive. Did you want to write '${name.substr(1)}="${value}"'?`
769+
)
770+
}
764771
if (dirRE.test(name)) {
765772
// mark element as dynamic
766773
el.hasBindings = true

Diff for: test/unit/modules/compiler/parser.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ describe('parser', () => {
530530
expect(ast.props[0].value).toBe('msg')
531531
})
532532

533+
it('v-bind expression on directive', () => {
534+
parse('<div :v-if="foo"></div>', baseOptions)
535+
expect(`A v-bind shorthand directive was used on another Vue directive. Did you want to write 'v-if="foo"'?`).toHaveBeenWarned()
536+
})
537+
533538
it('empty v-bind expression', () => {
534539
parse('<div :empty-msg=""></div>', baseOptions)
535540
expect('The value for a v-bind expression cannot be empty. Found in "v-bind:empty-msg"').toHaveBeenWarned()

0 commit comments

Comments
 (0)