8000 do not optimize literal props with filters (fix #2118) · vuejs/vue@224151f · GitHub
[go: up one dir, main page]

Skip to content

Commit 224151f

Browse files
committed
do not optimize literal props with filters (fix #2118)
1 parent bedab9d commit 224151f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/compiler/compile-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function compileProps (el, propOptions) {
8282
value = parsed.expression
8383
prop.filters = parsed.filters
8484
// check binding type
85-
if (isLiteral(value)) {
85+
if (isLiteral(value) && !parsed.filters) {
8686
// for expressions containing literal numbers and
8787
// booleans, there's no need to setup a prop binding,
8888
// so we can optimize them as a one-time set.

test/unit/specs/compiler/compile_spec.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ describe('Compile', function () {
276276
twoWayWarn: null,
277277
testOneTime: null,
278278
optimizeLiteral: null,
279-
optimizeLiteralStr: null
279+
optimizeLiteralStr: null,
280+
literalWithFilter: null
280281
}
281282
el.innerHTML = '<div ' +
282283
'v-bind:test-normal="a" ' +
@@ -286,9 +287,13 @@ describe('Compile', function () {
286287
':optimize-literal-str="\'true\'"' +
287288
':test-two-way.sync="a" ' +
288289
':two-way-warn.sync="a + 1" ' +
289-
':test-one-time.once="a"></div>'
290+
':test-one-time.once="a" ' +
291+
':literal-with-filter="\'HI\' | lowercase"' +
292+
'></div>'
290293
compiler.compileAndLinkProps(vm, el.firstChild, props)
291-
expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
294+
// check bindDir calls:
295+
// skip literal and one time, but not literal with filter
296+
expect(vm._bindDir.calls.count()).toBe(4)
292297
// literal
293298
expect(vm.testLiteral).toBe('1')
294299
expect(vm._data.testLiteral).toBe('1')
@@ -317,6 +322,14 @@ describe('Compile', function () {
317322
expect(prop.mode).toBe(bindingModes.TWO_WAY)
318323
// two way warn
319324
expect(hasWarned('non-settable parent path')).toBe(true)
325+
// literal with filter
326+
args = vm._bindDir.calls.argsFor(3)
327+
prop = args[0].prop
328+
expect(args[0].name).toBe('prop')
329+
expect(prop.path).toBe('literalWithFilter')
330+
expect(prop.parentPath).toBe("'HI'")
331+
expect(prop.filters.length).toBe(1)
332+
expect(prop.mode).toBe(bindingModes.ONE_WAY)
320333
})
321334

322335
it('props on root instance', function () {

0 commit comments

Comments
 (0)
0