diff --git a/src/compiler/compile.js b/src/compiler/compile.js index 3abaeb5dd..22e7640ce 100644 --- a/src/compiler/compile.js +++ b/src/compiler/compile.js @@ -553,13 +553,24 @@ function compileDirectives (attrs, options) { // Core directive if (name.indexOf(config.prefix) === 0) { dirName = name.slice(config.prefix.length) + + // check literal + if (dirName.charAt(dirName.length - 1) === '.') { + isLiteral = true + dirName = dirName.slice(0, -1) + } else { + isLiteral = false + } + dirDef = resolveAsset(options, 'directives', dirName) if (process.env.NODE_ENV !== 'production') { _.assertAsset(dirDef, 'directive', dirName) } if (dirDef) { - isLiteral = _.isLiteral(value) - if (isLiteral) value = _.stripQuotes(value) + if (!isLiteral && _.isLiteral(value)) { + value = _.stripQuotes(value) + isLiteral = true + } pushDir(dirName, dirDef, { literal: isLiteral }) diff --git a/test/unit/specs/compiler/compile_spec.js b/test/unit/specs/compiler/compile_spec.js index 5373878b8..85fcf58cd 100644 --- a/test/unit/specs/compiler/compile_spec.js +++ b/test/unit/specs/compiler/compile_spec.js @@ -49,7 +49,7 @@ if (_.inBrowser) { it('normal directives', function () { el.setAttribute('v-a', 'b') - el.innerHTML = '
hello
' + el.innerHTML = 'hello
' var defA = { priority: 1 } var defB = { priority: 2 } var options = _.mergeOptions(Vue.options, { @@ -80,16 +80,17 @@ if (_.inBrowser) { expect(args[0].expression).toBe('a') expect(args[0].def).toBe(defA) expect(args[1]).toBe(el.firstChild) - // 3 + // 3 (expression literal) args = vm._bindDir.calls.argsFor(isAttrReversed ? 1 : 2) expect(args[0].name).toBe('b') - expect(args[0].expression).toBe('b') + expect(args[0].expression).toBe('1') expect(args[0].def).toBe(defB) + expect(args[0].literal).toBe(true) expect(args[1]).toBe(el.firstChild) - // 4 + // 4 (explicit literal) args = vm._bindDir.calls.argsFor(3) expect(args[0].name).toBe('b') - expect(args[0].expression).toBe('1') + expect(args[0].expression).toBe('hi') expect(args[0].def).toBe(defB) expect(args[0].literal).toBe(true) expect(args[1]).toBe(el.lastChild)