diff --git a/src/code.ts b/src/code.ts index 13c2bed..67c748c 100644 --- a/src/code.ts +++ b/src/code.ts @@ -72,21 +72,24 @@ function traverse(node): NodeData { if (node.type == "TEXT") { const styledTextSegments = node.getStyledTextSegments(["fontName", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "textCase", "textDecoration", "fills"]); - let font = { - fontName: styledTextSegments[0].fontName, - fontSize: styledTextSegments[0].fontSize.toString(), - fontWeight: styledTextSegments[0].fontWeight.toString(), - characters: node.characters, - lineHeight: styledTextSegments[0].lineHeight, - letterSpacing: styledTextSegments[0].letterSpacing, - fills: styledTextSegments[0].fills, - textCase: styledTextSegments[0].textCase, - textDecoration: styledTextSegments[0].textDecoration, - textAlignHorizontal: node.textAlignHorizontal, - textAlignVertical: node.textAlignVertical, - children: styledTextSegments - }; - result = {...result, ...font}; + + if (styledTextSegments[0]) { + let font = { + fontName: styledTextSegments[0].fontName, + fontSize: styledTextSegments[0].fontSize.toString(), + fontWeight: styledTextSegments[0].fontWeight.toString(), + characters: node.characters, + lineHeight: styledTextSegments[0].lineHeight, + letterSpacing: styledTextSegments[0].letterSpacing, + fills: styledTextSegments[0].fills, + textCase: styledTextSegments[0].textCase, + textDecoration: styledTextSegments[0].textDecoration, + textAlignHorizontal: node.textAlignHorizontal, + textAlignVertical: node.textAlignVertical, + children: styledTextSegments + }; + result = {...result, ...font}; + } } return result;