Browse Source

do not optimize literal props with filters (fix #2118)

Evan You 10 years ago
parent
commit
224151f032
2 changed files with 17 additions and 4 deletions
  1. 1 1
      src/compiler/compile-props.js
  2. 16 3
      test/unit/specs/compiler/compile_spec.js

+ 1 - 1
src/compiler/compile-props.js

@@ -82,7 +82,7 @@ export function compileProps (el, propOptions) {
       value = parsed.expression
       prop.filters = parsed.filters
       // check binding type
-      if (isLiteral(value)) {
+      if (isLiteral(value) && !parsed.filters) {
         // for expressions containing literal numbers and
         // booleans, there's no need to setup a prop binding,
         // so we can optimize them as a one-time set.

+ 16 - 3
test/unit/specs/compiler/compile_spec.js

@@ -276,7 +276,8 @@ describe('Compile', function () {
       twoWayWarn: null,
       testOneTime: null,
       optimizeLiteral: null,
-      optimizeLiteralStr: null
+      optimizeLiteralStr: null,
+      literalWithFilter: null
     }
     el.innerHTML = '<div ' +
       'v-bind:test-normal="a" ' +
@@ -286,9 +287,13 @@ describe('Compile', function () {
       ':optimize-literal-str="\'true\'"' +
       ':test-two-way.sync="a" ' +
       ':two-way-warn.sync="a + 1" ' +
-      ':test-one-time.once="a"></div>'
+      ':test-one-time.once="a" ' +
+      ':literal-with-filter="\'HI\' | lowercase"' +
+      '></div>'
     compiler.compileAndLinkProps(vm, el.firstChild, props)
-    expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
+    // check bindDir calls:
+    // skip literal and one time, but not literal with filter
+    expect(vm._bindDir.calls.count()).toBe(4)
     // literal
     expect(vm.testLiteral).toBe('1')
     expect(vm._data.testLiteral).toBe('1')
@@ -317,6 +322,14 @@ describe('Compile', function () {
     expect(prop.mode).toBe(bindingModes.TWO_WAY)
     // two way warn
     expect(hasWarned('non-settable parent path')).toBe(true)
+    // literal with filter
+    args = vm._bindDir.calls.argsFor(3)
+    prop = args[0].prop
+    expect(args[0].name).toBe('prop')
+    expect(prop.path).toBe('literalWithFilter')
+    expect(prop.parentPath).toBe("'HI'")
+    expect(prop.filters.length).toBe(1)
+    expect(prop.mode).toBe(bindingModes.ONE_WAY)
   })
 
   it('props on root instance', function () {