From d22fe39a76dced4004cf738829a64e2001ed1110 Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 10:49:51 +0800 Subject: [PATCH 1/9] feat(renderList): `v-for` render non-integer range number close #2245 --- .../runtime-core/__tests__/helpers/renderList.spec.ts | 8 ++++++++ packages/runtime-core/src/helpers/renderList.ts | 1 + packages/server-renderer/__tests__/ssrRenderList.spec.ts | 5 +++++ packages/server-renderer/src/helpers/ssrRenderList.ts | 3 ++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index e28c6a004ce..cfa68604d87 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -21,6 +21,14 @@ describe('renderList', () => { ]) }) + it('should render integers 1 through N when given a non-integer N', () => { + expect(renderList(3.1, (item, index) => `node ${index}: ${item}`)).toEqual([ + 'node 0: 1', + 'node 1: 2', + 'node 2: 3' + ]) + }) + it('should render properties in an object', () => { expect( renderList( diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index f8238a46a16..3886e29a6d6 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -60,6 +60,7 @@ export function renderList( ret[i] = renderItem(source[i], i) } } else if (typeof source === 'number') { + source = Math.floor(source) ret = new Array(source) for (let i = 0; i < source; i++) { ret[i] = renderItem(i + 1, i) diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index e0dab83117b..9ded62267bb 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -24,6 +24,11 @@ describe('ssr: renderList', () => { expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) }) + it('should render integers 1 through N when given a non-integer N', () => { + ssrRenderList(3.1, (item, index) => stack.push(`node ${index}: ${item}`)) + expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) + }) + it('should render properties in an object', () => { ssrRenderList({ a: 1, b: 2, c: 3 }, (item, key, index) => stack.push(`node ${index}/${key}: ${item}`) diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index 67c27294358..837ec0472fb 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -9,7 +9,8 @@ export function ssrRenderList( renderItem(source[i], i) } } else if (typeof source === 'number') { - for (let i = 0; i < source; i++) { + source = Math.floor(source) + for (let i = 0; i < (source as number); i++) { renderItem(i + 1, i) } } else if (isObject(source)) { From 40be0e7a879fb595542ec080975761e29e58aadd Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 12:05:39 +0800 Subject: [PATCH 2/9] fix: fix edge case --- packages/runtime-core/__tests__/helpers/renderList.spec.ts | 2 +- packages/runtime-core/src/helpers/renderList.ts | 3 +-- packages/server-renderer/__tests__/ssrRenderList.spec.ts | 2 +- packages/server-renderer/src/helpers/ssrRenderList.ts | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index cfa68604d87..4ada4fb00fa 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -22,7 +22,7 @@ describe('renderList', () => { }) it('should render integers 1 through N when given a non-integer N', () => { - expect(renderList(3.1, (item, index) => `node ${index}: ${item}`)).toEqual([ + expect(renderList(2.1, (item, index) => `node ${index}: ${item}`)).toEqual([ 'node 0: 1', 'node 1: 2', 'node 2: 3' diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 3886e29a6d6..35d5418a89b 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -60,8 +60,7 @@ export function renderList( ret[i] = renderItem(source[i], i) } } else if (typeof source === 'number') { - source = Math.floor(source) - ret = new Array(source) + ret = new Array(Math.ceil(source)) for (let i = 0; i < source; i++) { ret[i] = renderItem(i + 1, i) } diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index 9ded62267bb..fdfbfd93d45 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -25,7 +25,7 @@ describe('ssr: renderList', () => { }) it('should render integers 1 through N when given a non-integer N', () => { - ssrRenderList(3.1, (item, index) => stack.push(`node ${index}: ${item}`)) + ssrRenderList(2.1, (item, index) => stack.push(`node ${index}: ${item}`)) expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) }) diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index 837ec0472fb..67c27294358 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -9,8 +9,7 @@ export function ssrRenderList( renderItem(source[i], i) } } else if (typeof source === 'number') { - source = Math.floor(source) - for (let i = 0; i < (source as number); i++) { + for (let i = 0; i < source; i++) { renderItem(i + 1, i) } } else if (isObject(source)) { From 253398a2c37a6668fa1735de405ce8fe1cd5ae98 Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 15:56:29 +0800 Subject: [PATCH 3/9] refactor: warn for `v-for` has non-integer range value --- .../runtime-core/__tests__/helpers/renderList.spec.ts | 11 +++++------ packages/runtime-core/src/helpers/renderList.ts | 9 +++++++-- .../server-renderer/__tests__/ssrRenderList.spec.ts | 7 +++++++ packages/server-renderer/src/helpers/ssrRenderList.ts | 7 ++++++- packages/shared/src/index.ts | 2 ++ 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index 4ada4fb00fa..fe4033320b5 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -21,12 +21,11 @@ describe('renderList', () => { ]) }) - it('should render integers 1 through N when given a non-integer N', () => { - expect(renderList(2.1, (item, index) => `node ${index}: ${item}`)).toEqual([ - 'node 0: 1', - 'node 1: 2', - 'node 2: 3' - ]) + it('should warn when given a non-integer N', () => { + renderList(3.1, () => {}) + expect( + 'Please give a non-integer value for v-for range.' + ).toHaveBeenWarned() }) it('should render properties in an object', () => { diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 35d5418a89b..5cb131e8342 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -1,5 +1,6 @@ import { VNodeChild } from '../vnode' -import { isArray, isString, isObject } from '@vue/shared' +import { isArray, isString, isObject, isInteger } from '@vue/shared' +import { warn } from '../warning' /** * v-for string @@ -60,7 +61,11 @@ export function renderList( ret[i] = renderItem(source[i], i) } } else if (typeof source === 'number') { - ret = new Array(Math.ceil(source)) + if (__DEV__ && isInteger(source)) { + warn('Please give a non-integer value for v-for range.') + return [] + } + ret = new Array(source) for (let i = 0; i < source; i++) { ret[i] = renderItem(i + 1, i) } diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index fdfbfd93d45..d9f3c607653 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -29,6 +29,13 @@ describe('ssr: renderList', () => { expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) }) + it('should warn when given a non-integer N', () => { + ssrRenderList(3.1, () => {}) + expect( + 'Please give a non-integer value for v-for range.' + ).toHaveBeenWarned() + }) + it('should render properties in an object', () => { ssrRenderList({ a: 1, b: 2, c: 3 }, (item, key, index) => stack.push(`node ${index}/${key}: ${item}`) diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index 67c27294358..ccdd66cdebd 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -1,4 +1,5 @@ -import { isArray, isString, isObject } from '@vue/shared' +import { isArray, isString, isObject, isInteger } from '@vue/shared' +import { warn } from '@vue/runtime-core' export function ssrRenderList( source: unknown, @@ -9,6 +10,10 @@ export function ssrRenderList( renderItem(source[i], i) } } else if (typeof source === 'number') { + if (__DEV__ && isInteger(source)) { + warn('Please give a non-integer value for v-for range.') + return [] + } for (let i = 0; i < source; i++) { renderItem(i + 1, i) } diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 46f1a462c9e..b31f442a826 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -92,6 +92,8 @@ export const isIntegerKey = (key: unknown) => key[0] !== '-' && '' + parseInt(key, 10) === key +export const isInteger = (val: number): boolean => val !== Math.ceil(val) + export const isReservedProp = /*#__PURE__*/ makeMap( 'key,ref,' + 'onVnodeBeforeMount,onVnodeMounted,' + From d5a975f53d1ca4ae8641426a23b3841244ac7769 Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 15:58:02 +0800 Subject: [PATCH 4/9] fix: remove ssr return value --- packages/server-renderer/src/helpers/ssrRenderList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index ccdd66cdebd..fe4ceb3e529 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -12,7 +12,7 @@ export function ssrRenderList( } else if (typeof source === 'number') { if (__DEV__ && isInteger(source)) { warn('Please give a non-integer value for v-for range.') - return [] + return } for (let i = 0; i < source; i++) { renderItem(i + 1, i) From 1bb6ec289c760fc99a34bcfd9c82d2aa89eda81d Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 15:59:20 +0800 Subject: [PATCH 5/9] fix: remove unused test --- packages/server-renderer/__tests__/ssrRenderList.spec.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index d9f3c607653..824c9a9ed88 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -24,11 +24,6 @@ describe('ssr: renderList', () => { expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) }) - it('should render integers 1 through N when given a non-integer N', () => { - ssrRenderList(2.1, (item, index) => stack.push(`node ${index}: ${item}`)) - expect(stack).toEqual(['node 0: 1', 'node 1: 2', 'node 2: 3']) - }) - it('should warn when given a non-integer N', () => { ssrRenderList(3.1, () => {}) expect( From 6aedbce5b8c6a537ad7dfd16f16e1f335903da0f Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 16:05:00 +0800 Subject: [PATCH 6/9] fix: use `Number.isInteger` --- packages/runtime-core/src/helpers/renderList.ts | 4 ++-- packages/server-renderer/src/helpers/ssrRenderList.ts | 4 ++-- packages/shared/src/index.ts | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 5cb131e8342..ccee24ce00c 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -1,5 +1,5 @@ import { VNodeChild } from '../vnode' -import { isArray, isString, isObject, isInteger } from '@vue/shared' +import { isArray, isString, isObject } from '@vue/shared' import { warn } from '../warning' /** @@ -61,7 +61,7 @@ export function renderList( ret[i] = renderItem(source[i], i) } } else if (typeof source === 'number') { - if (__DEV__ && isInteger(source)) { + if (__DEV__ && Number.isInteger(source)) { warn('Please give a non-integer value for v-for range.') return [] } diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index fe4ceb3e529..989a79256b7 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -1,4 +1,4 @@ -import { isArray, isString, isObject, isInteger } from '@vue/shared' +import { isArray, isString, isObject } from '@vue/shared' import { warn } from '@vue/runtime-core' export function ssrRenderList( @@ -10,7 +10,7 @@ export function ssrRenderList( renderItem(source[i], i) } } else if (typeof source === 'number') { - if (__DEV__ && isInteger(source)) { + if (__DEV__ && Number.isInteger(source)) { warn('Please give a non-integer value for v-for range.') return } diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index b31f442a826..46f1a462c9e 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -92,8 +92,6 @@ export const isIntegerKey = (key: unknown) => key[0] !== '-' && '' + parseInt(key, 10) === key -export const isInteger = (val: number): boolean => val !== Math.ceil(val) - export const isReservedProp = /*#__PURE__*/ makeMap( 'key,ref,' + 'onVnodeBeforeMount,onVnodeMounted,' + From a6ecfbe069a541968e6b21cbef2c6b806efd87ac Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 16:19:27 +0800 Subject: [PATCH 7/9] fix: fix test --- packages/runtime-core/__tests__/helpers/renderList.spec.ts | 2 +- packages/runtime-core/src/helpers/renderList.ts | 4 ++-- packages/server-renderer/__tests__/ssrRenderList.spec.ts | 2 +- packages/server-renderer/src/helpers/ssrRenderList.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index fe4033320b5..e2d79ca2ebd 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -24,7 +24,7 @@ describe('renderList', () => { it('should warn when given a non-integer N', () => { renderList(3.1, () => {}) expect( - 'Please give a non-integer value for v-for range.' + 'Please give an non-integer value for v-for range.' ).toHaveBeenWarned() }) diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index ccee24ce00c..a55498baa93 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -61,8 +61,8 @@ export function renderList( ret[i] = renderItem(source[i], i) } } else if (typeof source === 'number') { - if (__DEV__ && Number.isInteger(source)) { - warn('Please give a non-integer value for v-for range.') + if (__DEV__ && !Number.isInteger(source)) { + warn('Please give an non-integer value for v-for range.') return [] } ret = new Array(source) diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index 824c9a9ed88..69611c2bf0c 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -27,7 +27,7 @@ describe('ssr: renderList', () => { it('should warn when given a non-integer N', () => { ssrRenderList(3.1, () => {}) expect( - 'Please give a non-integer value for v-for range.' + 'Please give an non-integer value for v-for range.' ).toHaveBeenWarned() }) diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index 989a79256b7..9ce800a9487 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -10,8 +10,8 @@ export function ssrRenderList( renderItem(source[i], i) } } else if (typeof source === 'number') { - if (__DEV__ && Number.isInteger(source)) { - warn('Please give a non-integer value for v-for range.') + if (__DEV__ && !Number.isInteger(source)) { + warn('Please give an non-integer value for v-for range.') return } for (let i = 0; i < source; i++) { From 4a0e512e00c8bc6e0bfd2babe9dac7f35b5ec8e7 Mon Sep 17 00:00:00 2001 From: underfin Date: Sun, 27 Sep 2020 16:28:36 +0800 Subject: [PATCH 8/9] fix: fix warn words --- packages/runtime-core/__tests__/helpers/renderList.spec.ts | 4 +--- packages/runtime-core/src/helpers/renderList.ts | 2 +- packages/server-renderer/__tests__/ssrRenderList.spec.ts | 4 +--- packages/server-renderer/src/helpers/ssrRenderList.ts | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index e2d79ca2ebd..5b43440a3f6 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -23,9 +23,7 @@ describe('renderList', () => { it('should warn when given a non-integer N', () => { renderList(3.1, () => {}) - expect( - 'Please give an non-integer value for v-for range.' - ).toHaveBeenWarned() + expect('Please give an integer value for v-for range.').toHaveBeenWarned() }) it('should render properties in an object', () => { diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index a55498baa93..51d3546be20 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -62,7 +62,7 @@ export function renderList( } } else if (typeof source === 'number') { if (__DEV__ && !Number.isInteger(source)) { - warn('Please give an non-integer value for v-for range.') + warn('Please give an integer value for v-for range.') return [] } ret = new Array(source) diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index 69611c2bf0c..ed6bd7cc776 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -26,9 +26,7 @@ describe('ssr: renderList', () => { it('should warn when given a non-integer N', () => { ssrRenderList(3.1, () => {}) - expect( - 'Please give an non-integer value for v-for range.' - ).toHaveBeenWarned() + expect('Please give an integer value for v-for range.').toHaveBeenWarned() }) it('should render properties in an object', () => { diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index 9ce800a9487..c2652b6d033 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -11,7 +11,7 @@ export function ssrRenderList( } } else if (typeof source === 'number') { if (__DEV__ && !Number.isInteger(source)) { - warn('Please give an non-integer value for v-for range.') + warn('Please give an integer value for v-for range.') return } for (let i = 0; i < source; i++) { From 7a7086072f2800aaddacc578683b4850c7361e1f Mon Sep 17 00:00:00 2001 From: underfin Date: Mon, 28 Sep 2020 09:47:46 +0800 Subject: [PATCH 9/9] fix: better warn --- packages/runtime-core/__tests__/helpers/renderList.spec.ts | 4 +++- packages/runtime-core/src/helpers/renderList.ts | 2 +- packages/server-renderer/__tests__/ssrRenderList.spec.ts | 4 +++- packages/server-renderer/src/helpers/ssrRenderList.ts | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/__tests__/helpers/renderList.spec.ts b/packages/runtime-core/__tests__/helpers/renderList.spec.ts index 5b43440a3f6..48b2930c11f 100644 --- a/packages/runtime-core/__tests__/helpers/renderList.spec.ts +++ b/packages/runtime-core/__tests__/helpers/renderList.spec.ts @@ -23,7 +23,9 @@ describe('renderList', () => { it('should warn when given a non-integer N', () => { renderList(3.1, () => {}) - expect('Please give an integer value for v-for range.').toHaveBeenWarned() + expect( + `The v-for range expect an integer value but got 3.1.` + ).toHaveBeenWarned() }) it('should render properties in an object', () => { diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 51d3546be20..de4ab8afa7f 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -62,7 +62,7 @@ export function renderList( } } else if (typeof source === 'number') { if (__DEV__ && !Number.isInteger(source)) { - warn('Please give an integer value for v-for range.') + warn(`The v-for range expect an integer value but got ${source}.`) return [] } ret = new Array(source) diff --git a/packages/server-renderer/__tests__/ssrRenderList.spec.ts b/packages/server-renderer/__tests__/ssrRenderList.spec.ts index ed6bd7cc776..59b5d2ddf27 100644 --- a/packages/server-renderer/__tests__/ssrRenderList.spec.ts +++ b/packages/server-renderer/__tests__/ssrRenderList.spec.ts @@ -26,7 +26,9 @@ describe('ssr: renderList', () => { it('should warn when given a non-integer N', () => { ssrRenderList(3.1, () => {}) - expect('Please give an integer value for v-for range.').toHaveBeenWarned() + expect( + `The v-for range expect an integer value but got 3.1.` + ).toHaveBeenWarned() }) it('should render properties in an object', () => { diff --git a/packages/server-renderer/src/helpers/ssrRenderList.ts b/packages/server-renderer/src/helpers/ssrRenderList.ts index c2652b6d033..bde28f25759 100644 --- a/packages/server-renderer/src/helpers/ssrRenderList.ts +++ b/packages/server-renderer/src/helpers/ssrRenderList.ts @@ -11,7 +11,7 @@ export function ssrRenderList( } } else if (typeof source === 'number') { if (__DEV__ && !Number.isInteger(source)) { - warn('Please give an integer value for v-for range.') + warn(`The v-for range expect an integer value but got ${source}.`) return } for (let i = 0; i < source; i++) {