Skip to content

Commit 7244c69

Browse files
committed
fix literal casting in compilation
1 parent fbfcfcc commit 7244c69

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/compiler/compile-props.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ function makePropsLinkFn (props) {
165165
}
166166
} else if (prop.optimizedLiteral) {
167167
// optimized literal, cast it and just set once
168-
raw = _.stripQuotes(raw)
169-
value = _.toBoolean(_.toNumber(raw))
168+
var stripped = _.stripQuotes(raw)
169+
value = stripped === raw
170+
? _.toBoolean(_.toNumber(raw))
171+
: stripped
170172
_.initProp(vm, prop, value)
171173
} else {
172174
// string literal, but we need to cater for

src/compiler/compile.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,6 @@ function compileDirectives (attrs, options) {
662662
}
663663

664664
if (dirDef) {
665-
if (_.isLiteral(value)) {
666-
value = _.stripQuotes(value)
667-
modifiers.literal = true
668-
}
669665
pushDir(dirName, dirDef)
670666
}
671667
}

src/directives/public/for.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,8 @@ module.exports = {
495495
}
496496
return res
497497
} else {
498-
var type = typeof value
499-
if (type === 'number') {
498+
if (typeof value === 'number') {
500499
value = range(value)
501-
} else if (type === 'string') {
502-
value = _.toArray(value)
503500
}
504501
return value || []
505502
}

test/unit/specs/compiler/compile_spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ if (_.inBrowser) {
9090
expect(args[0].name).toBe('b')
9191
expect(args[0].expression).toBe('1')
9292
expect(args[0].def).toBe(defB)
93-
expect(args[0].modifiers.literal).toBe(true)
9493
expect(args[1]).toBe(el.firstChild)
9594
// 4 (explicit literal)
9695
args = vm._bindDir.calls.argsFor(3)
@@ -245,12 +244,14 @@ if (_.inBrowser) {
245244
testTwoWay: null,
246245
twoWayWarn: null,
247246
testOneTime: null,
248-
optimizeLiteral: null
247+
optimizeLiteral: null,
248+
optimizeLiteralStr: null
249249
}
250250
el.innerHTML = '<div ' +
251251
'v-bind:test-normal="a" ' +
252252
'test-literal="1" ' +
253253
':optimize-literal="1" ' +
254+
':optimize-literal-str="\'true\'"' +
254255
':test-two-way.sync="a" ' +
255256
':two-way-warn.sync="a + 1" ' +
256257
':test-one-time.once="a"></div>'
@@ -261,6 +262,8 @@ if (_.inBrowser) {
261262
expect(vm._data.testLiteral).toBe('1')
262263
expect(vm.optimizeLiteral).toBe(1)
263264
expect(vm._data.optimizeLiteral).toBe(1)
265+
expect(vm.optimizeLiteralStr).toBe('true')
266+
expect(vm._data.optimizeLiteralStr).toBe('true')
264267
// one time
265268
expect(vm.testOneTime).toBe('from parent: a')
266269
expect(vm._data.testOneTime).toBe('from parent: a')

0 commit comments

Comments
 (0)