diff --git a/xml.js b/xml.js index 97328195..5ff0199c 100644 --- a/xml.js +++ b/xml.js @@ -139,12 +139,16 @@ const camelCase = phrase => phrase.replace(/-([a-z])/g, upperCase); export function getStyle(string) { const style = {}; const declarations = string.split(";"); - for (let i = 0, l = declarations.length; i < l; i++) { - const declaration = declarations[i].split(":"); - const property = declaration[0]; - const value = declaration[1]; + const { length } = declarations; + for (let i = 0; i < length; i++) { + const declaration = declarations[i]; + if (declaration.length !== 0) { + const split = declaration.split(":"); + const property = split[0]; + const value = split[1]; style[camelCase(property.trim())] = value.trim(); } + } return style; } @@ -164,7 +168,8 @@ export function astToReact(child, i) { function locate(source, search) { const lines = source.split("\n"); - for (let line = 0, l = lines.length; line < l; line++) { + const nLines = lines.length; + for (let line = 0; line < nLines; line++) { const { length } = lines[line]; if (search < length) { return { line, column: search }; @@ -213,8 +218,8 @@ export function parse(source) { function metadata() { while ( - (i < length && source[i] !== "<") || - !validNameCharacters.test(source[i + 1]) + i + 1 < length && + (source[i] !== "<" || !validNameCharacters.test(source[i + 1])) ) { i++; } @@ -224,7 +229,11 @@ export function parse(source) { function neutral() { let text = ""; - while (i < length && source[i] !== "<") text += source[i++]; + let char; + while (i < length && (char = source[i]) !== "<") { + text += char; + i += 1; + } if (/\S/.test(text)) { children.push(text); @@ -243,9 +252,10 @@ export function parse(source) { if (char === "?") return neutral; //