Просмотр исходного кода

fix(codegen): support filters with () in older browsers (#7545)

Fix #7544
Make sure no extra , is added at the end of the call so it also work with older browsers
Eduardo San Martin Morote 8 лет назад
Родитель
Сommit
dc97a39c2f

+ 1 - 1
src/compiler/parser/filter-parser.js

@@ -92,6 +92,6 @@ function wrapFilter (exp: string, filter: string): string {
   } else {
     const name = filter.slice(0, i)
     const args = filter.slice(i + 1)
-    return `_f("${name}")(${exp},${args}`
+    return `_f("${name}")(${exp}${args !== ')' ? ',' + args : args}`
   }
 }

+ 7 - 0
test/unit/modules/compiler/codegen.spec.js

@@ -44,6 +44,13 @@ describe('codegen', () => {
     )
   })
 
+  it('generate filters with no arguments', () => {
+    assertCodegen(
+      '<div>{{ d | e() }}</div>',
+      `with(this){return _c('div',[_v(_s(_f("e")(d)))])}`
+    )
+  })
+
   it('generate v-for directive', () => {
     assertCodegen(
       '<div><li v-for="item in items" :key="item.uid"></li></div>',