Skip to content

Commit

Permalink
make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 24, 2014
1 parent 7f71239 commit 62b293d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,11 @@ CompilerProto.defineMeta = function (key, binding) {
* an anonymous computed property
*/
CompilerProto.defineExp = function (key, binding, directive) {
var filters = directive && directive.computeFilters && directive.filters,
exp = filters ? directive.expression : key,
getter = this.expCache[exp]
var computedKey = directive && directive.computedKey,
exp = computedKey ? directive.expression : key,
getter = this.expCache[exp]
if (!getter) {
getter = this.expCache[exp] = ExpParser.parse(key, this, null, filters)
getter = this.expCache[exp] = ExpParser.parse(computedKey || key, this)
}
if (getter) {
this.markComputed(binding, getter)
Expand Down
19 changes: 9 additions & 10 deletions src/directive.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
var utils = require('./utils'),
directives = require('./directives'),
dirId = 1,

// Regexes!

// regex to split multiple directive expressions
// split by commas, but ignore commas within quotes, parens and escapes.
SPLIT_RE = /(?:['"](?:\\.|[^'"])*['"]|\((?:\\.|[^\)])*\)|\\.|[^,])+/g,

// match up to the first single pipe, ignore those within quotes.
KEY_RE = /^(?:['"](?:\\.|[^'"])*['"]|\\.|[^\|]|\|\|)+/,

ARG_RE = /^([\w-$ ]+):(.+)$/,
FILTERS_RE = /\|[^\|]+/g,
FILTER_TOKEN_RE = /[^\s']+|'[^']+'|[^\s"]+|"[^"]+"/g,
Expand Down Expand Up @@ -63,7 +59,7 @@ function Directive (dirname, definition, expression, rawKey, compiler, node) {
this.arg = parsed.arg

var filters = Directive.parseFilters(this.expression.slice(rawKey.length)),
filter, fn, i, l
filter, fn, i, l, computed
if (filters) {
this.filters = []
for (i = 0, l = filters.length; i < l; i++) {
Expand All @@ -73,7 +69,7 @@ function Directive (dirname, definition, expression, rawKey, compiler, node) {
filter.apply = fn
this.filters.push(filter)
if (fn.computed) {
this.computeFilters = true
computed = true
}
}
}
Expand All @@ -83,12 +79,13 @@ function Directive (dirname, definition, expression, rawKey, compiler, node) {
this.filters = null
}

if (this.computeFilters) {
this.key = Directive.inlineFilters(this.key, this.filters)
if (computed) {
this.computedKey = Directive.inlineFilters(this.key, this.filters)
this.filters = null
}

this.isExp =
this.computeFilters ||
computed ||
!SINGLE_VAR_RE.test(this.key) ||
NESTING_RE.test(this.key)

Expand Down Expand Up @@ -174,7 +171,9 @@ Directive.parseArg = function (rawKey) {
* parse a the filters
*/
Directive.parseFilters = function (exp) {
if (!exp.indexOf('|') < 0) return
if (exp.indexOf('|') < 0) {
return
}
var filters = exp.match(FILTERS_RE),
res, i, l, tokens
if (filters) {
Expand Down
7 changes: 6 additions & 1 deletion test/functional/fixtures/expression.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<button v-on="click: ok = !ok" class="toggle">toggle</button>
<button v-on="click: noMsg = 'Nah'" class="change">change</button>
</div>
<div id="attrs" data-test="hi {{msg}} ha"></div>
<div id="attrs" data-test="hi {{msg + 'e' | test}} ha"></div>
<div id="html">html {{{html}}} work</div>

<script src="../../../dist/vue.js"></script>
Expand Down Expand Up @@ -56,6 +56,11 @@
el: '#attrs',
data: {
msg: 'ho'
},
filters: {
test: function (v) {
return v + 'f'
}
}
})

Expand Down
4 changes: 2 additions & 2 deletions test/functional/specs/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ casper.test.begin('Expression', 23, function (test) {
test.assertField('four', 'Ho')
// attrs
test.assertEval(function () {
return document.getElementById('attrs').dataset.test === 'hi ho ha'
return document.getElementById('attrs').dataset.test === 'hi hoef ha'
})
})
.thenEvaluate(function () {
Expand Down Expand Up @@ -78,7 +78,7 @@ casper.test.begin('Expression', 23, function (test) {
// attr
test.assertEvalEquals(function () {
return document.getElementById('attrs').dataset.test
}, 'hi hoho ha')
}, 'hi hohoef ha')
// html
test.assertEvalEquals(function () {
return document.getElementById('html').innerHTML
Expand Down
10 changes: 0 additions & 10 deletions test/unit/specs/text-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ describe('Text Parser', function () {

it('should extract and inline any filters', function () {
var res = TextParser.parseAttr('a {{msg | test}} b')
var vm = new Vue({
data: {
msg: 'haha'
},
filters: {
test: function (v) {
return v + '123'
}
}
})
assert.strictEqual(res, '"a "+(this.$compiler.getOption("filters", "test").call(this,msg))+" b"')
})

Expand Down

0 comments on commit 62b293d

Please sign in to comment.