Skip to content

Commit f962243

Browse files
Update index.js
I don't know why, but sometimes 'stylesheet' comes as an Array like this [{ stylesheet }, { opacity: 0.85 }], instead of an Object, so this throws an error referenced at issue #17 So, this is a workaround, if the stylesheet is an Array, returns the first element, wich is the actual style object.
1 parent cb75911 commit f962243

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ function generateNewStylesheet({ stylesheet, highlighter }) {
3131
if (styleCache.has(stylesheet)) {
3232
return styleCache.get(stylesheet);
3333
}
34+
// I don't know why, but sometimes 'stylesheet' comes as an Array
35+
// like this [{ stylesheet }, { opacity: 0.85 }], instead of an Object,
36+
// so this throws an error referenced at issue #17
37+
// So, this is a workaround, if the stylesheet is an Array,
38+
// returns the first element, wich is the actual style object.
39+
stylesheet = Array.isArray(stylesheet) ? stylesheet[0] : stylesheet;
3440
const transformedStyle = Object.entries(stylesheet).reduce((newStylesheet, [className, style]) => {
3541
newStylesheet[className] = Object.entries(style).reduce((newStyle, [key, value]) => {
3642
if (key === 'overflowX' || key === "overflow") {

0 commit comments

Comments
 (0)