extend,
looseEqual,
looseIndexOf,
+ looseToNumber,
NOOP,
- toDisplayString,
- toNumber
+ toDisplayString
} from '@vue/shared'
import {
ComponentPublicInstance,
$createElement: () => compatH,
_c: () => compatH,
_o: () => legacyMarkOnce,
- _n: () => toNumber,
+ _n: () => looseToNumber,
_s: () => toDisplayString,
_l: () => renderList,
_t: i => legacyRenderSlot.bind(null, i),
isObject,
isString,
isOn,
- toNumber,
- UnionToIntersection
+ UnionToIntersection,
+ looseToNumber
} from '@vue/shared'
import {
ComponentInternalInstance,
args = rawArgs.map(a => (isString(a) ? a.trim() : a))
}
if (number) {
- args = rawArgs.map(toNumber)
+ args = rawArgs.map(looseToNumber)
}
}
} from '../renderer'
import { queuePostFlushCb } from '../scheduler'
import { filterSingleRoot, updateHOCHostEl } from '../componentRenderUtils'
-import { pushWarningContext, popWarningContext, warn } from '../warning'
+import {
+ pushWarningContext,
+ popWarningContext,
+ warn,
+ assertNumber
+} from '../warning'
import { handleError, ErrorCodes } from '../errorHandling'
export interface SuspenseProps {
} = rendererInternals
const timeout = toNumber(vnode.props && vnode.props.timeout)
+ if (__DEV__) {
+ assertNumber(timeout, `Suspense timeout`)
+ }
+
const suspense: SuspenseBoundary = {
vnode,
parent,
export { createRenderer, createHydrationRenderer } from './renderer'
export { queuePostFlushCb } from './scheduler'
-export { warn } from './warning'
+export { warn, assertNumber } from './warning'
export {
handleError,
callWithErrorHandling,
return raw ? value : [`${key}=`, value]
}
}
+
+/**
+ * @internal
+ */
+export function assertNumber(val: unknown, type: string) {
+ if (!__DEV__) return
+ if (typeof val !== 'number') {
+ warn(`${type} is not a valid number - ` + `got ${JSON.stringify(val)}.`)
+ } else if (isNaN(val)) {
+ warn(`${type} is NaN - ` + 'the duration expression might be incorrect.')
+ }
+}
BaseTransition,
BaseTransitionProps,
h,
- warn,
+ assertNumber,
FunctionalComponent,
compatUtils,
DeprecationTypes
function NumberOf(val: unknown): number {
const res = toNumber(val)
- if (__DEV__) validateDuration(res)
+ if (__DEV__) assertNumber(res, '<transition> explicit duration')
return res
}
-function validateDuration(val: unknown) {
- if (typeof val !== 'number') {
- warn(
- `<transition> explicit duration is not a valid number - ` +
- `got ${JSON.stringify(val)}.`
- )
- } else if (isNaN(val)) {
- warn(
- `<transition> explicit duration is NaN - ` +
- 'the duration expression might be incorrect.'
- )
- }
-}
-
export function addTransitionClass(el: Element, cls: string) {
cls.split(/\s+/).forEach(c => c && el.classList.add(c))
;(
looseEqual,
looseIndexOf,
invokeArrayFns,
- toNumber,
+ looseToNumber,
isSet
} from '@vue/shared'
domValue = domValue.trim()
}
if (castToNumber) {
- domValue = toNumber(domValue)
+ domValue = looseToNumber(domValue)
}
el._assign(domValue)
})
if (trim && el.value.trim() === value) {
return
}
- if ((number || el.type === 'number') && toNumber(el.value) === value) {
+ if (
+ (number || el.type === 'number') &&
+ looseToNumber(el.value) === value
+ ) {
return
}
}
const selectedVal = Array.prototype.filter
.call(el.options, (o: HTMLOptionElement) => o.selected)
.map((o: HTMLOptionElement) =>
- number ? toNumber(getValue(o)) : getValue(o)
+ number ? looseToNumber(getValue(o)) : getValue(o)
)
el._assign(
el.multiple
})
}
-export const toNumber = (val: any): any => {
+/**
+ * "123-foo" will be parsed to 123
+ * This is used for the .number modifier in v-model
+ */
+export const looseToNumber = (val: any): any => {
const n = parseFloat(val)
return isNaN(n) ? val : n
}
+/**
+ * "123-foo" will be returned as-is
+ */
+export const toNumber = (val: any): any => {
+ const n = Number(val)
+ return isNaN(n) ? val : n
+}
+
let _globalThis: any
export const getGlobalThis = (): any => {
return (