Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(warn): Warn on colon shorthand usage on directive (fix #10191) #10199

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

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 directive was used on another Vue directive. Did you want to write '${name.substr(1)}="${value}"'?`
afontcu marked this conversation as resolved.
Show resolved Hide resolved
)
}
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', () => {
afontcu marked this conversation as resolved.
Show resolved Hide resolved
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