fix(runtime-core): ensure consistent behavior between dev/prod on invalid v-for range

close #5867
This commit is contained in:
Evan You 2022-05-06 16:49:15 +08:00
parent 4e7b36f5c3
commit 67099fe202
2 changed files with 3 additions and 2 deletions

View File

@ -22,7 +22,9 @@ describe('renderList', () => {
}) })
it('should warn when given a non-integer N', () => { it('should warn when given a non-integer N', () => {
renderList(3.1, () => {}) try {
renderList(3.1, () => {})
} catch (e) {}
expect( expect(
`The v-for range expect an integer value but got 3.1.` `The v-for range expect an integer value but got 3.1.`
).toHaveBeenWarned() ).toHaveBeenWarned()

View File

@ -67,7 +67,6 @@ export function renderList(
} else if (typeof source === 'number') { } else if (typeof source === 'number') {
if (__DEV__ && !Number.isInteger(source)) { if (__DEV__ && !Number.isInteger(source)) {
warn(`The v-for range expect an integer value but got ${source}.`) warn(`The v-for range expect an integer value but got ${source}.`)
return []
} }
ret = new Array(source) ret = new Array(source)
for (let i = 0; i < source; i++) { for (let i = 0; i < source; i++) {