From 5f884985b9f54220fc7d4b059cc0bec8b854b705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Mon, 17 Jun 2024 12:46:10 +0200 Subject: [PATCH] fix get component property definitions (#169) --- .../transformers/transformInstanceNode.ts | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/plugin-src/transformers/transformInstanceNode.ts b/plugin-src/transformers/transformInstanceNode.ts index d9336be..730752a 100644 --- a/plugin-src/transformers/transformInstanceNode.ts +++ b/plugin-src/transformers/transformInstanceNode.ts @@ -90,24 +90,28 @@ const getComponentTextPropertyOverrides = ( node: InstanceNode, primaryComponent: ComponentNode | ComponentSetNode ): ComponentTextPropertyOverride[] => { - const componentPropertyDefinitions = Object.entries( - primaryComponent.componentPropertyDefinitions - ).filter(([, value]) => value.type === 'TEXT'); + try { + const componentPropertyDefinitions = Object.entries( + primaryComponent.componentPropertyDefinitions + ).filter(([, value]) => value.type === 'TEXT'); - const instanceComponentProperties = new Map( - Object.entries(node.componentProperties).filter(([, value]) => value.type === 'TEXT') - ); + const instanceComponentProperties = new Map( + Object.entries(node.componentProperties).filter(([, value]) => value.type === 'TEXT') + ); - return componentPropertyDefinitions - .map(([key, value]) => { - const nodeValue = instanceComponentProperties.get(key); - return { - id: key, - ...value, - value: nodeValue ? nodeValue.value : value.defaultValue - } as ComponentTextPropertyOverride; - }) - .filter(({ value, defaultValue }) => value !== defaultValue); + return componentPropertyDefinitions + .map(([key, value]) => { + const nodeValue = instanceComponentProperties.get(key); + return { + id: key, + ...value, + value: nodeValue ? nodeValue.value : value.defaultValue + } as ComponentTextPropertyOverride; + }) + .filter(({ value, defaultValue }) => value !== defaultValue); + } catch (error) { + return []; + } }; const registerTextVariableOverrides = (