0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -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:
romachne 2023-11-03 13:35:17 +03:00 committed by GitHub
parent c64895f425
commit 7dc730994f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,6 +72,8 @@ 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"]);
if (styledTextSegments[0]) {
let font = { let font = {
fontName: styledTextSegments[0].fontName, fontName: styledTextSegments[0].fontName,
fontSize: styledTextSegments[0].fontSize.toString(), fontSize: styledTextSegments[0].fontSize.toString(),
@ -88,6 +90,7 @@ function traverse(node): NodeData {
}; };
result = {...result, ...font}; result = {...result, ...font};
} }
}
return result; return result;
} }