From e536c741654f6a92da6fec7478d95a7fa75f1aa3 Mon Sep 17 00:00:00 2001 From: Rik van Duijn Date: Wed, 19 Jul 2017 17:46:13 +0200 Subject: [PATCH 1/3] Fix order of cascading style inheritance --- __tests__/__snapshots__/HTMLView-test.js.snap | 61 ++++++++++---- .../__snapshots__/Example-test.js.snap | 80 ++++++++++++------- htmlToElement.js | 5 +- 3 files changed, 102 insertions(+), 44 deletions(-) diff --git a/__tests__/__snapshots__/HTMLView-test.js.snap b/__tests__/__snapshots__/HTMLView-test.js.snap index 2569123..7f5806d 100644 --- a/__tests__/__snapshots__/HTMLView-test.js.snap +++ b/__tests__/__snapshots__/HTMLView-test.js.snap @@ -34,6 +34,7 @@ exports[` can use a custom node class 1`] = ` null, Array [ Object {}, + Object {}, ], ] } @@ -58,6 +59,7 @@ exports[` can use a custom node class 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -75,6 +77,7 @@ exports[` can use a custom node class 1`] = ` null, Array [ Object {}, + Object {}, ], ] } @@ -119,6 +122,7 @@ exports[` can use a custom renderer 1`] = ` null, Array [ Object {}, + Object {}, ], ] } @@ -183,6 +187,7 @@ exports[` can use custom node props 1`] = ` null, Array [ Object {}, + Object {}, ], ] } @@ -207,6 +212,7 @@ exports[` can use custom node props 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -224,6 +230,7 @@ exports[` can use custom node props 1`] = ` null, Array [ Object {}, + Object {}, ], ] } @@ -268,6 +275,7 @@ exports[` should not render extra linebreaks if configured not to 1`] null, Array [ Object {}, + Object {}, ], ] } @@ -289,11 +297,12 @@ exports[` should not render extra linebreaks if configured not to 1`] Array [ null, Array [ + Object {}, + Object {}, Object { "fontSize": 30, "fontWeight": "500", }, - Object {}, ], ] } @@ -310,6 +319,7 @@ exports[` should not render extra linebreaks if configured not to 1`] null, Array [ Object {}, + Object {}, ], ] } @@ -333,6 +343,7 @@ exports[` should not render extra linebreaks if configured not to 1`] Array [ Object {}, Object {}, + Object {}, ], ] } @@ -356,6 +367,7 @@ exports[` should not render extra linebreaks if configured not to 1`] Array [ Object {}, Object {}, + Object {}, ], ] } @@ -374,6 +386,7 @@ exports[` should not render extra linebreaks if configured not to 1`] null, Array [ Object {}, + Object {}, ], ] } @@ -469,11 +482,12 @@ exports[` should render an empty element 1`] = ` Array [ null, Array [ + Object {}, + Object {}, Object { "color": "#007AFF", "fontWeight": "500", }, - Object {}, ], ] } @@ -512,6 +526,7 @@ exports[` should render ol numbers 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -538,6 +553,7 @@ exports[` should render ol numbers 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -584,6 +600,7 @@ exports[` should render shoddy html including headings, links, bold, null, Array [ Object {}, + Object {}, ], ] } @@ -607,6 +624,7 @@ exports[` should render shoddy html including headings, links, bold, Array [ Object {}, Object {}, + Object {}, ], ] } @@ -628,12 +646,13 @@ exports[` should render shoddy html including headings, links, bold, Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 30, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -653,6 +672,7 @@ exports[` should render shoddy html including headings, links, bold, Array [ Object {}, Object {}, + Object {}, ], ] } @@ -677,6 +697,7 @@ exports[` should render shoddy html including headings, links, bold, Object {}, Object {}, Object {}, + Object {}, ], ] } @@ -698,12 +719,13 @@ exports[` should render shoddy html including headings, links, bold, Array [ null, Array [ - Object { - "fontStyle": "italic", - }, Object {}, Object {}, Object {}, + Object {}, + Object { + "fontStyle": "italic", + }, ], ] } @@ -726,15 +748,16 @@ exports[` should render shoddy html including headings, links, bold, Array [ null, Array [ + Object {}, + Object {}, + Object {}, + Object {}, Object { - "fontWeight": "500", + "fontStyle": "italic", }, Object { - "fontStyle": "italic", + "fontWeight": "500", }, - Object {}, - Object {}, - Object {}, ], ] } @@ -758,6 +781,7 @@ exports[` should render shoddy html including headings, links, bold, Array [ Object {}, Object {}, + Object {}, ], ] } @@ -782,6 +806,7 @@ exports[` should render shoddy html including headings, links, bold, Object {}, Object {}, Object {}, + Object {}, ], ] } @@ -803,13 +828,14 @@ exports[` should render shoddy html including headings, links, bold, Array [ null, Array [ + Object {}, + Object {}, + Object {}, + Object {}, Object { "color": "#007AFF", "fontWeight": "500", }, - Object {}, - Object {}, - Object {}, ], ] } @@ -828,6 +854,7 @@ exports[` should render shoddy html including headings, links, bold, Object {}, Object {}, Object {}, + Object {}, ], ] } @@ -849,6 +876,7 @@ exports[` should render shoddy html including headings, links, bold, Array [ Object {}, Object {}, + Object {}, ], ] } @@ -866,6 +894,7 @@ exports[` should render shoddy html including headings, links, bold, null, Array [ Object {}, + Object {}, ], ] } @@ -938,6 +967,7 @@ exports[` should render ul bullets 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -964,6 +994,7 @@ exports[` should render ul bullets 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } diff --git a/example/__tests__/__snapshots__/Example-test.js.snap b/example/__tests__/__snapshots__/Example-test.js.snap index c133973..6d77bc5 100644 --- a/example/__tests__/__snapshots__/Example-test.js.snap +++ b/example/__tests__/__snapshots__/Example-test.js.snap @@ -42,6 +42,7 @@ exports[` should render 1`] = ` null, Array [ Object {}, + Object {}, ], ] } @@ -65,6 +66,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -92,14 +94,15 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { - "fontStyle": "italic", + "fontWeight": "500", }, Object { - "fontWeight": "500", + "fontStyle": "italic", }, - Object {}, - Object {}, ], ] } @@ -118,6 +121,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -142,6 +146,7 @@ exports[` should render 1`] = ` Object {}, Object {}, Object {}, + Object {}, ], ] } @@ -163,12 +168,13 @@ exports[` should render 1`] = ` Array [ null, Array [ - Object { - "fontStyle": "italic", - }, Object {}, Object {}, Object {}, + Object {}, + Object { + "fontStyle": "italic", + }, ], ] } @@ -191,15 +197,16 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, + Object {}, Object { - "fontWeight": "500", + "fontStyle": "italic", }, Object { - "fontStyle": "italic", + "fontWeight": "500", }, - Object {}, - Object {}, - Object {}, ], ] } @@ -223,6 +230,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -247,6 +255,7 @@ exports[` should render 1`] = ` Object {}, Object {}, Object {}, + Object {}, ], ] } @@ -268,13 +277,14 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, + Object {}, Object { "color": "#007AFF", "fontWeight": "500", }, - Object {}, - Object {}, - Object {}, ], ] } @@ -293,6 +303,7 @@ exports[` should render 1`] = ` Object {}, Object {}, Object {}, + Object {}, ], ] } @@ -314,6 +325,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -347,6 +359,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -369,12 +382,13 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 36, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -394,6 +408,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -415,12 +430,13 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 30, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -440,6 +456,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -461,12 +478,13 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 24, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -486,6 +504,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -507,12 +526,13 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 18, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -532,6 +552,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -553,12 +574,13 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 14, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -578,6 +600,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -599,12 +622,13 @@ exports[` should render 1`] = ` Array [ null, Array [ + Object {}, + Object {}, + Object {}, Object { "fontSize": 12, "fontWeight": "500", }, - Object {}, - Object {}, ], ] } @@ -622,6 +646,7 @@ exports[` should render 1`] = ` Array [ Object {}, Object {}, + Object {}, ], ] } @@ -657,6 +682,7 @@ exports[` should render 1`] = ` null, Array [ Object {}, + Object {}, ], ] } diff --git a/htmlToElement.js b/htmlToElement.js index 84c72ec..7c20d65 100644 --- a/htmlToElement.js +++ b/htmlToElement.js @@ -43,9 +43,10 @@ export default function htmlToElement(rawHtml, customOpts = {}, done) { }; function inheritedStyle(parent) { - if (!parent) { return null; } + if (!parent) return null; const style = [opts.styles[parent.name] || {}]; - return parent.parent ? style.concat(inheritedStyle(parent.parent)) : style; + const parentStyle = inheritedStyle(parent.parent) || [{}]; + return parentStyle.concat(style); } function domToElement(dom, parent) { From 7eebbcacfa8f068d3b8757358b5b4b2360aeb2a4 Mon Sep 17 00:00:00 2001 From: Rik van Duijn Date: Sat, 22 Jul 2017 20:16:20 +0200 Subject: [PATCH 2/3] Refactor inheritedStyle to combine objects --- __tests__/__snapshots__/HTMLView-test.js.snap | 222 ++++------------- .../__snapshots__/Example-test.js.snap | 232 +++++------------- htmlToElement.js | 6 +- 3 files changed, 106 insertions(+), 354 deletions(-) diff --git a/__tests__/__snapshots__/HTMLView-test.js.snap b/__tests__/__snapshots__/HTMLView-test.js.snap index 7f5806d..bfedcfb 100644 --- a/__tests__/__snapshots__/HTMLView-test.js.snap +++ b/__tests__/__snapshots__/HTMLView-test.js.snap @@ -32,10 +32,7 @@ exports[` can use a custom node class 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -56,11 +53,7 @@ exports[` can use a custom node class 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -75,10 +68,7 @@ exports[` can use a custom node class 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -120,10 +110,7 @@ exports[` can use a custom renderer 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -185,10 +172,7 @@ exports[` can use custom node props 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -209,11 +193,7 @@ exports[` can use custom node props 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -228,10 +208,7 @@ exports[` can use custom node props 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -273,10 +250,7 @@ exports[` should not render extra linebreaks if configured not to 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -296,14 +270,10 @@ exports[` should not render extra linebreaks if configured not to 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - Object { - "fontSize": 30, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 30, + "fontWeight": "500", + }, ] } > @@ -317,10 +287,7 @@ exports[` should not render extra linebreaks if configured not to 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -340,11 +307,7 @@ exports[` should not render extra linebreaks if configured not to 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -364,11 +327,7 @@ exports[` should not render extra linebreaks if configured not to 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -384,10 +343,7 @@ exports[` should not render extra linebreaks if configured not to 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -481,14 +437,10 @@ exports[` should render an empty element 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object { - "color": "#007AFF", - "fontWeight": "500", - }, - ], + Object { + "color": "#007AFF", + "fontWeight": "500", + }, ] } > @@ -523,11 +475,7 @@ exports[` should render ol numbers 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -550,11 +498,7 @@ exports[` should render ol numbers 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -598,10 +542,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -621,11 +562,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -645,15 +582,10 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 30, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 30, + "fontWeight": "500", + }, ] } > @@ -669,11 +601,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -693,12 +621,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -718,15 +641,9 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - Object { - "fontStyle": "italic", - }, - ], + Object { + "fontStyle": "italic", + }, ] } > @@ -747,18 +664,10 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - Object { - "fontStyle": "italic", - }, - Object { - "fontWeight": "500", - }, - ], + Object { + "fontStyle": "italic", + "fontWeight": "500", + }, ] } > @@ -778,11 +687,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -802,12 +707,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -827,16 +727,10 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - Object { - "color": "#007AFF", - "fontWeight": "500", - }, - ], + Object { + "color": "#007AFF", + "fontWeight": "500", + }, ] } > @@ -850,12 +744,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -873,11 +762,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -892,10 +777,7 @@ exports[` should render shoddy html including headings, links, bold, style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -964,11 +846,7 @@ exports[` should render ul bullets 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -991,11 +869,7 @@ exports[` should render ul bullets 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > diff --git a/example/__tests__/__snapshots__/Example-test.js.snap b/example/__tests__/__snapshots__/Example-test.js.snap index 6d77bc5..58e84a1 100644 --- a/example/__tests__/__snapshots__/Example-test.js.snap +++ b/example/__tests__/__snapshots__/Example-test.js.snap @@ -40,10 +40,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -63,11 +60,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -93,17 +86,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontWeight": "500", - }, - Object { - "fontStyle": "italic", - }, - ], + Object { + "fontStyle": "italic", + "fontWeight": "500", + }, ] } > @@ -118,11 +104,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -142,12 +124,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -167,15 +144,9 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - Object { - "fontStyle": "italic", - }, - ], + Object { + "fontStyle": "italic", + }, ] } > @@ -196,18 +167,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - Object { - "fontStyle": "italic", - }, - Object { - "fontWeight": "500", - }, - ], + Object { + "fontStyle": "italic", + "fontWeight": "500", + }, ] } > @@ -227,11 +190,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -251,12 +210,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -276,16 +230,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - Object { - "color": "#007AFF", - "fontWeight": "500", - }, - ], + Object { + "color": "#007AFF", + "fontWeight": "500", + }, ] } > @@ -299,12 +247,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -322,11 +265,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -356,11 +295,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -381,15 +316,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 36, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 36, + "fontWeight": "500", + }, ] } > @@ -405,11 +335,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -429,15 +355,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 30, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 30, + "fontWeight": "500", + }, ] } > @@ -453,11 +374,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -477,15 +394,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 24, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 24, + "fontWeight": "500", + }, ] } > @@ -501,11 +413,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -525,15 +433,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 18, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 18, + "fontWeight": "500", + }, ] } > @@ -549,11 +452,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -573,15 +472,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 14, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 14, + "fontWeight": "500", + }, ] } > @@ -597,11 +491,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -621,15 +511,10 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - Object { - "fontSize": 12, - "fontWeight": "500", - }, - ], + Object { + "fontSize": 12, + "fontWeight": "500", + }, ] } > @@ -643,11 +528,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - Object {}, - ], + Object {}, ] } > @@ -680,10 +561,7 @@ exports[` should render 1`] = ` style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > diff --git a/htmlToElement.js b/htmlToElement.js index 7c20d65..461dadd 100644 --- a/htmlToElement.js +++ b/htmlToElement.js @@ -44,9 +44,9 @@ export default function htmlToElement(rawHtml, customOpts = {}, done) { function inheritedStyle(parent) { if (!parent) return null; - const style = [opts.styles[parent.name] || {}]; - const parentStyle = inheritedStyle(parent.parent) || [{}]; - return parentStyle.concat(style); + const style = opts.styles[parent.name] || {}; + const parentStyle = inheritedStyle(parent.parent) || {}; + return {...parentStyle, ...style}; } function domToElement(dom, parent) { From e899763d88c8a350bbc6956b58915207501ff2d3 Mon Sep 17 00:00:00 2001 From: Rik van Duijn Date: Sat, 22 Jul 2017 20:28:01 +0200 Subject: [PATCH 3/3] Fix snapshots --- __tests__/__snapshots__/HTMLView-test.js.snap | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/__tests__/__snapshots__/HTMLView-test.js.snap b/__tests__/__snapshots__/HTMLView-test.js.snap index 13966d0..2d784a0 100644 --- a/__tests__/__snapshots__/HTMLView-test.js.snap +++ b/__tests__/__snapshots__/HTMLView-test.js.snap @@ -242,9 +242,7 @@ exports[` should handle additional text nodes between list items 1`] style={ Array [ null, - Array [ - Object {}, - ], + Object {}, ] } > @@ -266,10 +264,7 @@ exports[` should handle additional text nodes between list items 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -285,9 +280,7 @@ exports[` should handle additional text nodes between list items 1`] style={ Array [ null, - Array [ - Object {}, - ], + Object {}, ] } > @@ -309,10 +302,7 @@ exports[` should handle additional text nodes between list items 1`] style={ Array [ null, - Array [ - Object {}, - Object {}, - ], + Object {}, ] } > @@ -328,9 +318,7 @@ exports[` should handle additional text nodes between list items 1`] style={ Array [ null, - Array [ - Object {}, - ], + Object {}, ] } >