From 4da92f027dfc3082d3c0c422eb45f5069805a3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Tue, 25 Jun 2019 21:04:01 +0200 Subject: [PATCH] feat: Warn on colon shorthand usage on directive fix #10191 --- src/compiler/parser/index.js | 7 +++++++ test/unit/modules/compiler/parser.spec.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index cdeb257eda..a5beec78c8 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -30,6 +30,7 @@ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/ const stripParensRE = /^\(|\)$/g const dynamicArgRE = /^\[.*\]$/ +const colonDirRE = /^:v-/ const argRE = /:(.*)$/ export const bindRE = /^:|^\.|^v-bind:/ const propBindRE = /^\./ @@ -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 diff --git a/test/unit/modules/compiler/parser.spec.js b/test/unit/modules/compiler/parser.spec.js index d6521bbf62..ae3804ead5 100644 --- a/test/unit/modules/compiler/parser.spec.js +++ b/test/unit/modules/compiler/parser.spec.js @@ -530,6 +530,11 @@ describe('parser', () => { expect(ast.props[0].value).toBe('msg') }) + it('v-bind expression on directive', () => { + parse('
', 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('
', baseOptions) expect('The value for a v-bind expression cannot be empty. Found in "v-bind:empty-msg"').toHaveBeenWarned()