Skip to content

Commit c113b85

Browse files
committed
support .= literal syntax
1 parent 1c73ce5 commit c113b85

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/compiler/compile.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,24 @@ function compileDirectives (attrs, options) {
553553
// Core directive
554554
if (name.indexOf(config.prefix) === 0) {
555555
dirName = name.slice(config.prefix.length)
556+
557+
// check literal
558+
if (dirName.charAt(dirName.length - 1) === '.') {
559+
isLiteral = true
560+
dirName = dirName.slice(0, -1)
561+
} else {
562+
isLiteral = false
563+
}
564+
556565
dirDef = resolveAsset(options, 'directives', dirName)
557566
if (process.env.NODE_ENV !== 'production') {
558567
_.assertAsset(dirDef, 'directive', dirName)
559568
}
560569
if (dirDef) {
561-
isLiteral = _.isLiteral(value)
562-
if (isLiteral) value = _.stripQuotes(value)
570+
if (!isLiteral && _.isLiteral(value)) {
571+
value = _.stripQuotes(value)
572+
isLiteral = true
573+
}
563574
pushDir(dirName, dirDef, {
564575
literal: isLiteral
565576
})

test/unit/specs/compiler/compile_spec.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if (_.inBrowser) {
4949

5050
it('normal directives', function () {
5151
el.setAttribute('v-a', 'b')
52-
el.innerHTML = '<p v-a="a" v-b="b">hello</p><div v-b="1"></div>'
52+
el.innerHTML = '<p v-a="a" v-b="1">hello</p><div v-b.="hi"></div>'
5353
var defA = { priority: 1 }
5454
var defB = { priority: 2 }
5555
var options = _.mergeOptions(Vue.options, {
@@ -80,16 +80,17 @@ if (_.inBrowser) {
8080
expect(args[0].expression).toBe('a')
8181
expect(args[0].def).toBe(defA)
8282
expect(args[1]).toBe(el.firstChild)
83-
// 3
83+
// 3 (expression literal)
8484
args = vm._bindDir.calls.argsFor(isAttrReversed ? 1 : 2)
8585
expect(args[0].name).toBe('b')
86-
expect(args[0].expression).toBe('b')
86+
expect(args[0].expression).toBe('1')
8787
expect(args[0].def).toBe(defB)
88+
expect(args[0].literal).toBe(true)
8889
expect(args[1]).toBe(el.firstChild)
89-
// 4
90+
// 4 (explicit literal)
9091
args = vm._bindDir.calls.argsFor(3)
9192
expect(args[0].name).toBe('b')
92-
expect(args[0].expression).toBe('1')
93+
expect(args[0].expression).toBe('hi')
9394
expect(args[0].def).toBe(defB)
9495
expect(args[0].literal).toBe(true)
9596
expect(args[1]).toBe(el.lastChild)

0 commit comments

Comments
 (0)