diff --git a/src/compiler/compile.js b/src/compiler/compile.js index 45a6b890dc2..bf258cb7ab6 100644 --- a/src/compiler/compile.js +++ b/src/compiler/compile.js @@ -14,7 +14,8 @@ import { checkComponentAttr, findRef, defineReactive, - getAttr + getAttr, + camelize } from '../util/index' // special binding prefixes @@ -716,6 +717,11 @@ function compileDirectives (attrs, options) { pushDir(dirName, internalDirectives[dirName]) } else { arg = dirName + // support for shorthand expression (#2843) + //
=>
+ if (!value) { + value = camelize(dirName, true) + } pushDir('bind', publicDirectives.bind) } } else diff --git a/src/util/lang.js b/src/util/lang.js index 29e450fa5a2..fe2ca88b5a5 100644 --- a/src/util/lang.js +++ b/src/util/lang.js @@ -174,8 +174,9 @@ export function stripQuotes (str) { */ var camelizeRE = /-(\w)/g -export function camelize (str) { - return str.replace(camelizeRE, toUpper) +var camelizeCleanupRE = /\W+(\w)?/ +export function camelize (str, cleanup) { + return str.replace(cleanup ? camelizeCleanupRE : camelizeRE, toUpper) } function toUpper (_, c) { diff --git a/test/unit/specs/compiler/compile_spec.js b/test/unit/specs/compiler/compile_spec.js index fb8a934e4ab..537af31b838 100644 --- a/test/unit/specs/compiler/compile_spec.js +++ b/test/unit/specs/compiler/compile_spec.js @@ -112,6 +112,9 @@ describe('Compile', function () { el.setAttribute(':class', 'a') el.setAttribute(':style', 'b') el.setAttribute(':title', 'c') + el.setAttribute(':content', '') + el.setAttribute(':data-content', '') + el.setAttribute(':ns:attr', '') // The order of setAttribute is not guaranteed to be the same with // the order of attribute enumberation, therefore we need to save @@ -135,6 +138,27 @@ 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 + }, + ':ns:attr': { + name: 'bind', + attr: ':ns:attr', + expression: 'nsAttr', + arg: 'ns:attr', + def: publicDirectives.bind } } var expects = [].map.call(el.attributes, function (attr) { @@ -143,7 +167,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(6) expects.forEach(function (e, i) { var args = vm._bindDir.calls.argsFor(i)