]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(Transition): fix validate duration (#1188)
authorunderfin <2218301630@qq.com>
Mon, 18 May 2020 14:09:10 +0000 (22:09 +0800)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 14:09:10 +0000 (10:09 -0400)
packages/runtime-dom/src/components/Transition.ts
packages/runtime-dom/src/directives/vModel.ts
packages/shared/src/index.ts

index c2d52dc0201d8e44f3322e30a7660778cd2a4dd8..20e18f832e8c6f39f62e7b7304d399e2b3a7bfce 100644 (file)
@@ -7,7 +7,7 @@ import {
   getCurrentInstance,
   callWithAsyncErrorHandling
 } from '@vue/runtime-core'
-import { isObject } from '@vue/shared'
+import { isObject, toNumber } from '@vue/shared'
 import { ErrorCodes } from 'packages/runtime-core/src/errorHandling'
 
 const TRANSITION = 'transition'
@@ -165,15 +165,15 @@ function normalizeDuration(
   if (duration == null) {
     return null
   } else if (isObject(duration)) {
-    return [toNumber(duration.enter), toNumber(duration.leave)]
+    return [NumberOf(duration.enter), NumberOf(duration.leave)]
   } else {
-    const n = toNumber(duration)
+    const n = NumberOf(duration)
     return [n, n]
   }
 }
 
-function toNumber(val: unknown): number {
-  const res = Number(val || 0)
+function NumberOf(val: unknown): number {
+  const res = toNumber(val)
   if (__DEV__) validateDuration(res)
   return res
 }
index 090f27ce1a340ff7ea5685d554bebf194ff46603..2bc4287a5332facb4ce7c158d5d240b5294d0835 100644 (file)
@@ -6,7 +6,13 @@ import {
   warn
 } from '@vue/runtime-core'
 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
 
@@ -33,11 +39,6 @@ function trigger(el: HTMLElement, type: string) {
   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 }>
 
 // We are exporting the v-model runtime directly as vnode hooks so that it can
index 066132c8a9a013341012cf9ff403811f2b89548a..8d67e586d576111415e55e627afcaaf69988e415 100644 (file)
@@ -125,3 +125,8 @@ export const def = (obj: object, key: string | symbol, value: any) => {
     value
   })
 }
+
+export const toNumber = (val: any): any => {
+  const n = parseFloat(val)
+  return isNaN(n) ? val : n
+}