Skip to content

Commit 62b293d

Browse files
committed
make tests pass
1 parent 7f71239 commit 62b293d

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

src/compiler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,11 @@ CompilerProto.defineMeta = function (key, binding) {
778778
* an anonymous computed property
779779
*/
780780
CompilerProto.defineExp = function (key, binding, directive) {
781-
var filters = directive && directive.computeFilters && directive.filters,
782-
exp = filters ? directive.expression : key,
783-
getter = this.expCache[exp]
781+
var computedKey = directive && directive.computedKey,
782+
exp = computedKey ? directive.expression : key,
783+
getter = this.expCache[exp]
784784
if (!getter) {
785-
getter = this.expCache[exp] = ExpParser.parse(key, this, null, filters)
785+
getter = this.expCache[exp] = ExpParser.parse(computedKey || key, this)
786786
}
787787
if (getter) {
788788
this.markComputed(binding, getter)

src/directive.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
var utils = require('./utils'),
2-
directives = require('./directives'),
32
dirId = 1,
43

54
// Regexes!
6-
75
// regex to split multiple directive expressions
86
// split by commas, but ignore commas within quotes, parens and escapes.
97
SPLIT_RE = /(?:['"](?:\\.|[^'"])*['"]|\((?:\\.|[^\)])*\)|\\.|[^,])+/g,
10-
118
// match up to the first single pipe, ignore those within quotes.
129
KEY_RE = /^(?:['"](?:\\.|[^'"])*['"]|\\.|[^\|]|\|\|)+/,
13-
1410
ARG_RE = /^([\w-$ ]+):(.+)$/,
1511
FILTERS_RE = /\|[^\|]+/g,
1612
FILTER_TOKEN_RE = /[^\s']+|'[^']+'|[^\s"]+|"[^"]+"/g,
@@ -63,7 +59,7 @@ function Directive (dirname, definition, expression, rawKey, compiler, node) {
6359
this.arg = parsed.arg
6460

6561
var filters = Directive.parseFilters(this.expression.slice(rawKey.length)),
66-
filter, fn, i, l
62+
filter, fn, i, l, computed
6763
if (filters) {
6864
this.filters = []
6965
for (i = 0, l = filters.length; i < l; i++) {
@@ -73,7 +69,7 @@ function Directive (dirname, definition, expression, rawKey, compiler, node) {
7369
filter.apply = fn
7470
this.filters.push(filter)
7571
if (fn.computed) {
76-
this.computeFilters = true
72+
computed = true
7773
}
7874
}
7975
}
@@ -83,12 +79,13 @@ function Directive (dirname, definition, expression, rawKey, compiler, node) {
8379
this.filters = null
8480
}
8581

86-
if (this.computeFilters) {
87-
this.key = Directive.inlineFilters(this.key, this.filters)
82+
if (computed) {
83+
this.computedKey = Directive.inlineFilters(this.key, this.filters)
84+
this.filters = null
8885
}
8986

9087
this.isExp =
91-
this.computeFilters ||
88+
computed ||
9289
!SINGLE_VAR_RE.test(this.key) ||
9390
NESTING_RE.test(this.key)
9491

@@ -174,7 +171,9 @@ Directive.parseArg = function (rawKey) {
174171
* parse a the filters
175172
*/
176173
Directive.parseFilters = function (exp) {
177-
if (!exp.indexOf('|') < 0) return
174+
if (exp.indexOf('|') < 0) {
175+
return
176+
}
178177
var filters = exp.match(FILTERS_RE),
179178
res, i, l, tokens
180179
if (filters) {

test/functional/fixtures/expression.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<button v-on="click: ok = !ok" class="toggle">toggle</button>
1616
<button v-on="click: noMsg = 'Nah'" class="change">change</button>
1717
</div>
18-
<div id="attrs" data-test="hi {{msg}} ha"></div>
18+
<div id="attrs" data-test="hi {{msg + 'e' | test}} ha"></div>
1919
<div id="html">html {{{html}}} work</div>
2020

2121
<script src="../../../dist/vue.js"></script>
@@ -56,6 +56,11 @@
5656
el: '#attrs',
5757
data: {
5858
msg: 'ho'
59+
},
60+
filters: {
61+
test: function (v) {
62+
return v + 'f'
63+
}
5964
}
6065
})
6166

test/functional/specs/expression.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ casper.test.begin('Expression', 23, function (test) {
1313
test.assertField('four', 'Ho')
1414
// attrs
1515
test.assertEval(function () {
16-
return document.getElementById('attrs').dataset.test === 'hi ho ha'
16+
return document.getElementById('attrs').dataset.test === 'hi hoef ha'
1717
})
1818
})
1919
.thenEvaluate(function () {
@@ -78,7 +78,7 @@ casper.test.begin('Expression', 23, function (test) {
7878
// attr
7979
test.assertEvalEquals(function () {
8080
return document.getElementById('attrs').dataset.test
81-
}, 'hi hoho ha')
81+
}, 'hi hohoef ha')
8282
// html
8383
test.assertEvalEquals(function () {
8484
return document.getElementById('html').innerHTML

test/unit/specs/text-parser.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ describe('Text Parser', function () {
6969

7070
it('should extract and inline any filters', function () {
7171
var res = TextParser.parseAttr('a {{msg | test}} b')
72-
var vm = new Vue({
73-
data: {
74-
msg: 'haha'
75-
},
76-
filters: {
77-
test: function (v) {
78-
return v + '123'
79-
}
80-
}
81-
})
8272
assert.strictEqual(res, '"a "+(this.$compiler.getOption("filters", "test").call(this,msg))+" b"')
8373
})
8474

0 commit comments

Comments
 (0)