Skip to content

Add support for v-bind:content shorthand (fixes #2843) #2858

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion src/compiler/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
checkComponentAttr,
findRef,
defineReactive,
getAttr
getAttr,
camelize
} from '../util/index'

// special binding prefixes
Expand Down Expand Up @@ -716,6 +717,11 @@ function compileDirectives (attrs, options) {
pushDir(dirName, internalDirectives[dirName])
} else {
arg = dirName
// support for shorthand expression (#2843)
// <div v-bind:content> => <div v-bind:content="content">
if (!value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this? We don't want this to happen when the value is null or undefined?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is what you mean, but value is the expression, not the return value of the expression. So you can still do v-bind:content="null".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that's the rawValue. My bad!

value = camelize(dirName)
}
pushDir('bind', publicDirectives.bind)
}
} else
Expand Down
18 changes: 17 additions & 1 deletion test/unit/specs/compiler/compile_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ describe('Compile', function () {
el.setAttribute(':class', 'a')
el.setAttribute(':style', 'b')
el.setAttribute(':title', 'c')
el.setAttribute(':content', '')
el.setAttribute(':data-content', '')

// The order of setAttribute is not guaranteed to be the same with
// the order of attribute enumberation, therefore we need to save
Expand All @@ -135,6 +137,20 @@ describe('Compile', function () {
expression: 'c',
arg: 'title',
def: publicDirectives.bind
},
':content': {
name: 'bind',
attr: ':content',
expression: 'content',
arg: 'content',
def: publicDirectives.bind
},
':data-content': {
name: 'bind',
attr: ':data-content',
expression: 'dataContent',
arg: 'data-content',
def: publicDirectives.bind
}
}
var expects = [].map.call(el.attributes, function (attr) {
Expand All @@ -143,7 +159,7 @@ describe('Compile', function () {

var linker = compile(el, Vue.options)
linker(vm, el)
expect(vm._bindDir.calls.count()).toBe(3)
expect(vm._bindDir.calls.count()).toBe(5)

expects.forEach(function (e, i) {
var args = vm._bindDir.calls.argsFor(i)
Expand Down