From 97f300865b3a21356551bc25b0d6727424b2be85 Mon Sep 17 00:00:00 2001 From: Anzor Date: Wed, 6 Sep 2017 09:16:30 -0400 Subject: [PATCH] Remove reliance on for..of Fixes https://github.com/sabeurthabti/react-native-css/issues/60 --- src/index.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index d66831c..d188236 100644 --- a/src/index.js +++ b/src/index.js @@ -62,10 +62,13 @@ export default function toJSS(css) { const { stylesheet } = ParseCSS(utils.clean(stylesheetString)); const JSONResult = {}; - for (const rule of stylesheet.rules) { + for (let ruleIter = 0; ruleIter < stylesheet.rules.length; ruleIter++) { + const rule = stylesheet.rules[ruleIter]; + if (rule.type !== 'rule') continue; - for (let selector of rule.selectors) { + for (let selectorIter = 0; selectorIter < rule.selectors.length; selectorIter++) { + let selector = rule.selectors[selectorIter]; selector = selector.replace(/\.|#/g, ''); let styles; @@ -89,8 +92,9 @@ export default function toJSS(css) { styles = (JSONResult[selector] = JSONResult[selector] || {}); } + for (let declarationIter = 0; declarationIter < rule.declarations.length; declarationIter++) { + const declaration = rule.declarations[declarationIter]; - for (const declaration of rule.declarations) { if (declaration.type !== 'declaration') continue; const value = declaration.value; @@ -140,26 +144,26 @@ export default function toJSS(css) { }); const length = values.length; + const horizontalPositionProps = ['Left', 'Right']; if (length === 1) { styles[toCamelCase(property)] = values[0]; } if (length === 2) { - for (const prop of ['Top', 'Bottom']) { + const verticalPositionProps = ['Top', 'Bottom']; + verticalPositionProps.forEach((prop) => { styles[directionToPropertyName(property, prop)] = values[0]; - } - - for (const prop of ['Left', 'Right']) { + }); + horizontalPositionProps.forEach((prop) => { styles[directionToPropertyName(property, prop)] = values[1]; - } + }); } if (length === 3) { - for (const prop of ['Left', 'Right']) { + horizontalPositionProps.forEach((prop) => { styles[directionToPropertyName(property, prop)] = values[1]; - } - + }); styles[directionToPropertyName(property, 'Top')] = values[0]; styles[directionToPropertyName(property, 'Bottom')] = values[2]; }