Skip to content

Commit eb593b1

Browse files
committed
fix unit tests for latest syntax
1 parent b18252f commit eb593b1

File tree

11 files changed

+51
-45
lines changed

11 files changed

+51
-45
lines changed

src/compiler/compile.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var resolveAsset = _.resolveAsset
99
var componentDef = require('../directives/component')
1010

1111
// special binding prefixes
12-
var bindRE = /^:/
12+
var bindRE = /^:|^v-bind:/
1313
var onRE = /^@/
1414
var argRE = /:(.*)$/
1515
var nodeRefRE = /^\$\$\./
@@ -269,7 +269,7 @@ function compileElement (el, options) {
269269
if (el.tagName === 'TEXTAREA') {
270270
var tokens = textParser.parse(el.value)
271271
if (tokens) {
272-
el.setAttribute('bind-value', textParser.tokensToExp(tokens))
272+
el.setAttribute(':value', textParser.tokensToExp(tokens))
273273
el.value = ''
274274
}
275275
}
@@ -546,6 +546,21 @@ function compileDirectives (attrs, options) {
546546
attr = attrs[i]
547547
name = attr.name
548548
value = attr.value
549+
550+
// special case for transition
551+
if (
552+
name === 'transition' ||
553+
name === ':transition' ||
554+
name === (config.prefix + 'bind:transition')
555+
) {
556+
dirs.push({
557+
name: 'transition',
558+
arg: bindRE.test(name),
559+
descriptors: [newDirParser.parse(value)],
560+
def: options.directives.transition
561+
})
562+
} else
563+
549564
// Core directive
550565
if (name.indexOf(config.prefix) === 0) {
551566
// check literal
@@ -605,16 +620,6 @@ function compileDirectives (attrs, options) {
605620
})
606621
} else
607622

608-
// special case for transition
609-
if (name === 'transition' || name === 'bind-transition' || name === ':transition') {
610-
dirs.push({
611-
name: 'transition',
612-
arg: bindRE.test(name),
613-
descriptors: [newDirParser.parse(value)],
614-
def: options.directives.transition
615-
})
616-
} else
617-
618623
// attribute bindings
619624
if (bindRE.test(name)) {
620625
var attributeName = name.replace(bindRE, '')

src/compiler/transclude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function isFragment (el) {
155155
// alternative component syntax
156156
el.hasAttribute('is') ||
157157
el.hasAttribute(':is') ||
158-
el.hasAttribute('bind-is') ||
158+
el.hasAttribute(config.prefix + 'bind:is') ||
159159
el.hasAttribute(config.prefix + 'component') ||
160160
// repeat block
161161
el.hasAttribute(config.prefix + 'repeat') ||

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Directive.prototype._teardown = function () {
303303
function removeBindAttr (el, name) {
304304
var attr = el.hasAttribute(':' + name)
305305
? ':' + name
306-
: 'bind-' + name
306+
: config.prefix + 'bind:' + name
307307
el.removeAttribute(attr)
308308
}
309309

src/util/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ exports.getBindAttr = function (node, name) {
7070
var attr = ':' + name
7171
var val = node.getAttribute(attr)
7272
if (val === null) {
73-
attr = 'bind-' + name
73+
attr = config.prefix + 'bind:' + name
7474
val = node.getAttribute(attr)
7575
}
7676
if (val !== null) {

test/unit/specs/compiler/compile_spec.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ if (_.inBrowser) {
6666
linker(vm, el)
6767
expect(directiveBind.calls.count()).toBe(4)
6868
expect(vm._bindDir.calls.count()).toBe(4)
69-
expect(vm._bindDir).toHaveBeenCalledWith('a', el, descriptorB, defA, undefined, undefined, undefined, undefined, false)
70-
expect(vm._bindDir).toHaveBeenCalledWith('a', el.firstChild, descriptorA, defA, undefined, undefined, undefined, undefined, false)
71-
expect(vm._bindDir).toHaveBeenCalledWith('b', el.firstChild, descriptorB, defB, undefined, undefined, undefined, undefined, false)
72-
expect(vm._bindDir).toHaveBeenCalledWith('b', el.lastChild, descriptorB, defB, undefined, undefined, undefined, undefined, true)
69+
expect(vm._bindDir).toHaveBeenCalledWith('a', el, descriptorB, defA, undefined, undefined, undefined, null, false)
70+
expect(vm._bindDir).toHaveBeenCalledWith('a', el.firstChild, descriptorA, defA, undefined, undefined, undefined, null, false)
71+
expect(vm._bindDir).toHaveBeenCalledWith('b', el.firstChild, descriptorB, defB, undefined, undefined, undefined, null, false)
72+
expect(vm._bindDir).toHaveBeenCalledWith('b', el.lastChild, descriptorB, defB, undefined, undefined, undefined, null, true)
7373
// check the priority sorting
7474
// the "b"s should be called first!
7575
expect(directiveBind.calls.argsFor(0)[0]).toBe('b')
@@ -78,10 +78,10 @@ if (_.inBrowser) {
7878
expect(directiveBind.calls.argsFor(3)[0]).toBe('a')
7979
})
8080

81-
it('bind- syntax', function () {
82-
el.setAttribute('bind-class', 'a')
83-
el.setAttribute('bind-style', 'b')
84-
el.setAttribute('bind-title', 'c')
81+
it('v-bind shorthand', function () {
82+
el.setAttribute(':class', 'a')
83+
el.setAttribute(':style', 'b')
84+
el.setAttribute(':title', 'c')
8585
var descA = newDirParser.parse('a')
8686
var descB = newDirParser.parse('b')
8787
var descC = newDirParser.parse('c')
@@ -93,8 +93,9 @@ if (_.inBrowser) {
9393
expect(vm._bindDir).toHaveBeenCalledWith('attr', el, descC, Vue.options.directives.attr, undefined, undefined, undefined, 'title', undefined)
9494
})
9595

96-
it('on- syntax', function () {
97-
el.setAttribute('on-click', 'a++')
96+
it('v-on shorthand', function () {
97+
el.innerHTML = '<a @click="a++"></a>'
98+
el = el.firstChild
9899
var desc = newDirParser.parse('a++')
99100
var linker = compile(el, Vue.options)
100101
linker(vm, el)
@@ -309,12 +310,12 @@ if (_.inBrowser) {
309310
{ name: 'optimizeLiteral' }
310311
]
311312
el.innerHTML = '<div ' +
312-
'bind-test-normal="a" ' +
313+
'v-bind:test-normal="a" ' +
313314
'test-literal="1" ' +
314-
'bind-optimize-literal="1" ' +
315-
'bind-test-two-way@="a" ' +
316-
'bind-two-way-warn@="a + 1" ' +
317-
'bind-test-one-time*="a"></div>'
315+
':optimize-literal="1" ' +
316+
':test-two-way@="a" ' +
317+
':two-way-warn@="a + 1" ' +
318+
':test-one-time*="a"></div>'
318319
compiler.compileAndLinkProps(vm, el.firstChild, props)
319320
expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
320321
// literal

test/unit/specs/directives/component_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ if (_.inBrowser) {
157157
it('dynamic (new syntax)', function (done) {
158158
var vm = new Vue({
159159
el: el,
160-
template: '<component bind-is="view" bind-view="view"></component>',
160+
template: '<component v-bind:is="view" :view="view"></component>',
161161
data: {
162162
view: 'view-a'
163163
},
@@ -415,7 +415,7 @@ if (_.inBrowser) {
415415
data: {
416416
view: 'view-a'
417417
},
418-
template: '<component bind-is="view"></component>',
418+
template: '<component :is="view"></component>',
419419
components: {
420420
'view-a': {
421421
template: 'AAA',
@@ -498,7 +498,7 @@ if (_.inBrowser) {
498498
data: {
499499
view: 'view-a'
500500
},
501-
template: '<component bind-is="view" keep-alive></component>',
501+
template: '<component :is="view" keep-alive></component>',
502502
components: {
503503
'view-a': {
504504
template: 'AAA',

test/unit/specs/directives/model_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ if (_.inBrowser) {
118118
expression2: 'string2'
119119
},
120120
template:
121-
'<input type="radio" value="1" v-model="test" name="test" bind-value="true">' +
122-
'<input type="radio" value="0" v-model="test" name="test" bind-value="false">' +
123-
'<input type="radio" value="1" v-model="test2" name="test2" bind-value="expression1">' +
124-
'<input type="radio" value="0" v-model="test2" name="test2" bind-value="expression2">'
121+
'<input type="radio" value="1" v-model="test" name="test" v-bind:value="true">' +
122+
'<input type="radio" value="0" v-model="test" name="test" v-bind:value="false">' +
123+
'<input type="radio" value="1" v-model="test2" name="test2" :value="expression1">' +
124+
'<input type="radio" value="0" v-model="test2" name="test2" :value="expression2">'
125125
})
126126
expect(el.childNodes[0].checked).toBe(false)
127127
expect(el.childNodes[1].checked).toBe(true)
@@ -203,7 +203,7 @@ if (_.inBrowser) {
203203
expression1: 'aTrueValue',
204204
expression2: 'aFalseValue'
205205
},
206-
template: '<input type="checkbox" v-model="test" bind-true-value="expression1" bind-false-value="expression2">'
206+
template: '<input type="checkbox" v-model="test" v-bind:true-value="expression1" :false-value="expression2">'
207207
})
208208
expect(vm.test).toBe('')
209209
el.firstChild.click()
@@ -635,7 +635,7 @@ if (_.inBrowser) {
635635
},
636636
template:
637637
'<select v-model="test">' +
638-
'<option v-for="op in opts" bind-value="op.value">{{op.text}}</option>' +
638+
'<option v-for="op in opts" :value="op.value">{{op.text}}</option>' +
639639
'</select>'
640640
})
641641
var select = el.firstChild

test/unit/specs/directives/on_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if (_.inBrowser) {
7474
it('with key filter (new syntax)', function (done) {
7575
new Vue({
7676
el: el,
77-
template: '<a on-keyup-enter="test">{{a}}</a>',
77+
template: '<a @keyup:enter="test">{{a}}</a>',
7878
data: {a: 1},
7979
methods: {
8080
test: function () {

test/unit/specs/directives/prop_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ if (_.inBrowser) {
9999
a: 'A'
100100
}
101101
},
102-
template: '<test bind-testt@="test" :bb@="b" :a@=" test.a " v-ref="child"></test>',
102+
template: '<test v-bind:testt@="test" :bb@="b" :a@=" test.a " v-ref="child"></test>',
103103
components: {
104104
test: {
105105
props: ['testt', 'bb', 'a'],
@@ -631,7 +631,7 @@ if (_.inBrowser) {
631631
it('new syntax with filters', function (done) {
632632
var vm = new Vue({
633633
el: el,
634-
template: '<test bind-name="a | test"></test>',
634+
template: '<test v-bind:name="a | test"></test>',
635635
data: {
636636
a: 123
637637
},

test/unit/specs/directives/ref_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (_.inBrowser) {
3939
el: el,
4040
components: components,
4141
data: { test: 'test' },
42-
template: '<component bind-is="test" $.test></component>'
42+
template: '<component :is="test" $.test></component>'
4343
})
4444
expect(vm.$.test.$options.id).toBe('test')
4545
vm.test = 'test2'
@@ -57,7 +57,7 @@ if (_.inBrowser) {
5757
var vm = new Vue({
5858
el: el,
5959
data: { view: 'one' },
60-
template: '{{$.test.value}}<component bind-is="view" $.test></component>',
60+
template: '{{$.test.value}}<component :is="view" $.test></component>',
6161
components: {
6262
one: {
6363
id: 'one',

0 commit comments

Comments
 (0)