Pārlūkot izejas kodu

make tests pass

Evan You 12 gadi atpakaļ
vecāks
revīzija
62b293de07

+ 4 - 4
src/compiler.js

@@ -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)

+ 9 - 10
src/directive.js

@@ -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,
@@ -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++) {
@@ -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
                 }
             }
         }
@@ -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)
 
@@ -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) {

+ 6 - 1
test/functional/fixtures/expression.html

@@ -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>
@@ -56,6 +56,11 @@
         el: '#attrs',
         data: {
             msg: 'ho'
+        },
+        filters: {
+            test: function (v) {
+                return v + 'f'
+            }
         }
     })
 

+ 2 - 2
test/functional/specs/expression.js

@@ -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 () {
@@ -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

+ 0 - 10
test/unit/specs/text-parser.js

@@ -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"')
         })