mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 05:33:02 -05:00
🐛 Fix the use of empty styledTextSegments array (#31)
When a TextNode contains empty characters field, getStyledTextSegments returns empty array. This causes a TypeError, when we try to access the properties of the first element of this array. This change adds a check if the first element of the styledTextSegments exists before using its properties. Signed-off-by: Roma <romachne@gmail.com>
This commit is contained in:
parent
c64895f425
commit
7dc730994f
1 changed files with 18 additions and 15 deletions
33
src/code.ts
33
src/code.ts
|
@ -72,21 +72,24 @@ function traverse(node): NodeData {
|
||||||
|
|
||||||
if (node.type == "TEXT") {
|
if (node.type == "TEXT") {
|
||||||
const styledTextSegments = node.getStyledTextSegments(["fontName", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "textCase", "textDecoration", "fills"]);
|
const styledTextSegments = node.getStyledTextSegments(["fontName", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "textCase", "textDecoration", "fills"]);
|
||||||
let font = {
|
|
||||||
fontName: styledTextSegments[0].fontName,
|
if (styledTextSegments[0]) {
|
||||||
fontSize: styledTextSegments[0].fontSize.toString(),
|
let font = {
|
||||||
fontWeight: styledTextSegments[0].fontWeight.toString(),
|
fontName: styledTextSegments[0].fontName,
|
||||||
characters: node.characters,
|
fontSize: styledTextSegments[0].fontSize.toString(),
|
||||||
lineHeight: styledTextSegments[0].lineHeight,
|
fontWeight: styledTextSegments[0].fontWeight.toString(),
|
||||||
letterSpacing: styledTextSegments[0].letterSpacing,
|
characters: node.characters,
|
||||||
fills: styledTextSegments[0].fills,
|
lineHeight: styledTextSegments[0].lineHeight,
|
||||||
textCase: styledTextSegments[0].textCase,
|
letterSpacing: styledTextSegments[0].letterSpacing,
|
||||||
textDecoration: styledTextSegments[0].textDecoration,
|
fills: styledTextSegments[0].fills,
|
||||||
textAlignHorizontal: node.textAlignHorizontal,
|
textCase: styledTextSegments[0].textCase,
|
||||||
textAlignVertical: node.textAlignVertical,
|
textDecoration: styledTextSegments[0].textDecoration,
|
||||||
children: styledTextSegments
|
textAlignHorizontal: node.textAlignHorizontal,
|
||||||
};
|
textAlignVertical: node.textAlignVertical,
|
||||||
result = {...result, ...font};
|
children: styledTextSegments
|
||||||
|
};
|
||||||
|
result = {...result, ...font};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue