Skip to content

Commit 3f4899b

Browse files
authored
Merge pull request #211 from wojtekmaj/no-accumulating-spread
Fix accumulating spread in transform function
2 parents d768110 + 9b6ae6d commit 3f4899b

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

.changeset/calm-clocks-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'css-to-react-native': patch
3+
---
4+
5+
Refactor transform to avoid accumulator-based object merging.

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@ export const getPropertyName = (propName: string): string => {
105105
const transform = (
106106
rules: StyleTuple[],
107107
shorthandBlacklist: string[] = []
108-
): Style =>
109-
rules.reduce<Style>((accum, rule) => {
108+
): Style => {
109+
const result: Style = {}
110+
111+
for (const rule of rules) {
110112
const propertyName = getPropertyName(rule[0])
111113
const value = rule[1]
112114
const allowShorthand = shorthandBlacklist.indexOf(propertyName) === -1
113-
return Object.assign(
114-
accum,
115+
Object.assign(
116+
result,
115117
getStylesForProperty(propertyName, value, allowShorthand)
116118
)
117-
}, {})
119+
}
120+
121+
return result
122+
}
118123

119124
export default transform

0 commit comments

Comments
 (0)