fix(Transition): fix validate duration (#1188)

This commit is contained in:
underfin 2020-05-18 22:09:10 +08:00 committed by GitHub
parent 8e30d0c74c
commit d73a508a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import {
getCurrentInstance, getCurrentInstance,
callWithAsyncErrorHandling callWithAsyncErrorHandling
} from '@vue/runtime-core' } from '@vue/runtime-core'
import { isObject } from '@vue/shared' import { isObject, toNumber } from '@vue/shared'
import { ErrorCodes } from 'packages/runtime-core/src/errorHandling' import { ErrorCodes } from 'packages/runtime-core/src/errorHandling'
const TRANSITION = 'transition' const TRANSITION = 'transition'
@ -165,15 +165,15 @@ function normalizeDuration(
if (duration == null) { if (duration == null) {
return null return null
} else if (isObject(duration)) { } else if (isObject(duration)) {
return [toNumber(duration.enter), toNumber(duration.leave)] return [NumberOf(duration.enter), NumberOf(duration.leave)]
} else { } else {
const n = toNumber(duration) const n = NumberOf(duration)
return [n, n] return [n, n]
} }
} }
function toNumber(val: unknown): number { function NumberOf(val: unknown): number {
const res = Number(val || 0) const res = toNumber(val)
if (__DEV__) validateDuration(res) if (__DEV__) validateDuration(res)
return res return res
} }

View File

@ -6,7 +6,13 @@ import {
warn warn
} from '@vue/runtime-core' } from '@vue/runtime-core'
import { addEventListener } from '../modules/events' import { addEventListener } from '../modules/events'
import { isArray, looseEqual, looseIndexOf, invokeArrayFns } from '@vue/shared' import {
isArray,
looseEqual,
looseIndexOf,
invokeArrayFns,
toNumber
} from '@vue/shared'
type AssignerFn = (value: any) => void type AssignerFn = (value: any) => void
@ -33,11 +39,6 @@ function trigger(el: HTMLElement, type: string) {
el.dispatchEvent(e) el.dispatchEvent(e)
} }
function toNumber(val: string): number | string {
const n = parseFloat(val)
return isNaN(n) ? val : n
}
type ModelDirective<T> = ObjectDirective<T & { _assign: AssignerFn }> type ModelDirective<T> = ObjectDirective<T & { _assign: AssignerFn }>
// We are exporting the v-model runtime directly as vnode hooks so that it can // We are exporting the v-model runtime directly as vnode hooks so that it can

View File

@ -125,3 +125,8 @@ export const def = (obj: object, key: string | symbol, value: any) => {
value value
}) })
} }
export const toNumber = (val: any): any => {
const n = parseFloat(val)
return isNaN(n) ? val : n
}