Skip to content

Commit d73a508

Browse files
authored
fix(Transition): fix validate duration (#1188)
1 parent 8e30d0c commit d73a508

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

packages/runtime-dom/src/components/Transition.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getCurrentInstance,
88
callWithAsyncErrorHandling
99
} from '@vue/runtime-core'
10-
import { isObject } from '@vue/shared'
10+
import { isObject, toNumber } from '@vue/shared'
1111
import { ErrorCodes } from 'packages/runtime-core/src/errorHandling'
1212

1313
const TRANSITION = 'transition'
@@ -165,15 +165,15 @@ function normalizeDuration(
165165
if (duration == null) {
166166
return null
167167
} else if (isObject(duration)) {
168-
return [toNumber(duration.enter), toNumber(duration.leave)]
168+
return [NumberOf(duration.enter), NumberOf(duration.leave)]
169169
} else {
170-
const n = toNumber(duration)
170+
const n = NumberOf(duration)
171171
return [n, n]
172172
}
173173
}
174174

175-
function toNumber(val: unknown): number {
176-
const res = Number(val || 0)
175+
function NumberOf(val: unknown): number {
176+
const res = toNumber(val)
177177
if (__DEV__) validateDuration(res)
178178
return res
179179
}

packages/runtime-dom/src/directives/vModel.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import {
66
warn
77
} from '@vue/runtime-core'
88
import { addEventListener } from '../modules/events'
9-
import { isArray, looseEqual, looseIndexOf, invokeArrayFns } from '@vue/shared'
9+
import {
10+
isArray,
11+
looseEqual,
12+
looseIndexOf,
13+
invokeArrayFns,
14+
toNumber
15+
} from '@vue/shared'
1016

1117
type AssignerFn = (value: any) => void
1218

@@ -33,11 +39,6 @@ function trigger(el: HTMLElement, type: string) {
3339
el.dispatchEvent(e)
3440
}
3541

36-
function toNumber(val: string): number | string {
37-
const n = parseFloat(val)
38-
return isNaN(n) ? val : n
39-
}
40-
4142
type ModelDirective<T> = ObjectDirective<T & { _assign: AssignerFn }>
4243

4344
// We are exporting the v-model runtime directly as vnode hooks so that it can

packages/shared/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ export const def = (obj: object, key: string | symbol, value: any) => {
125125
value
126126
})
127127
}
128+
129+
export const toNumber = (val: any): any => {
130+
const n = parseFloat(val)
131+
return isNaN(n) ? val : n
132+
}

0 commit comments

Comments
 (0)