Skip to content

Commit

Permalink
refactor: improve the fix for #4138
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 19, 2021
1 parent a8c3a8a commit 47ba33e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { isNoUnitNumericStyleProp } from './domAttrConfig'

export type NormalizedStyle = Record<string, string | number>

export function normalizeStyle(value: unknown): NormalizedStyle | undefined {
export function normalizeStyle(
value: unknown
): NormalizedStyle | string | undefined {
if (isArray(value)) {
const res: NormalizedStyle = {}
for (let i = 0; i < value.length; i++) {
const item = value[i]
const normalized = normalizeStyle(
isString(item) ? parseStringStyle(item) : item
)
const normalized = isString(item)
? parseStringStyle(item)
: (normalizeStyle(item) as NormalizedStyle)
if (normalized) {
for (const key in normalized) {
res[key] = normalized[key]
Expand All @@ -19,7 +21,7 @@ export function normalizeStyle(value: unknown): NormalizedStyle | undefined {
}
return res
} else if (isString(value)) {
return parseStringStyle(value)
return value
} else if (isObject(value)) {
return value
}
Expand Down

0 comments on commit 47ba33e

Please sign in to comment.