diff --git a/src/core/util/props.js b/src/core/util/props.js index 5a90f21b5f0..facea1fa5ba 100644 --- a/src/core/util/props.js +++ b/src/core/util/props.js @@ -8,6 +8,7 @@ import { toRawType, hyphenate, capitalize, + isDate, isPlainObject } from 'shared/util' @@ -166,6 +167,8 @@ function assertType (value: any, type: Function, vm: ?Component): { valid = isPlainObject(value) } else if (expectedType === 'Array') { valid = Array.isArray(value) + } else if (expectedType === 'Date') { + valid = isDate(value) } else { try { valid = value instanceof type diff --git a/src/shared/util.js b/src/shared/util.js index 9f240c77b14..06200ef2184 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -63,6 +63,10 @@ export function isRegExp (v: any): boolean { return _toString.call(v) === '[object RegExp]' } +export function isDate (v: any): boolean { + return v instanceof Date || _toString.call(v) === '[object Date]' +} + /** * Check if val is a valid array index. */ @@ -294,7 +298,7 @@ export function looseEqual (a: any, b: any): boolean { return a.length === b.length && a.every((e, i) => { return looseEqual(e, b[i]) }) - } else if (a instanceof Date && b instanceof Date) { + } else if (isDate(a) && isDate(b)) { return a.getTime() === b.getTime() } else if (!isArrayA && !isArrayB) { const keysA = Object.keys(a) diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index 33094be9c33..4a537d997d6 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -1666,6 +1666,20 @@ describe('SSR: renderToString', () => { done() }) }) + + it('should not warn for Date prop when it comes from another context', done => { + const date = VM.runInNewContext('new Date()') + new Vue({ + props: { + date: Date, + }, + propsData: { + date + } + }) + expect('Invalid prop: type check failed for prop "date". Expected Date, got Date').not.toHaveBeenWarned() + done() + }) }) function renderVmWithOptions (options, cb) {