From a4113382bb1d0d252425cb3cd1e86568fa659830 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Mon, 3 Jun 2024 13:52:50 +0200 Subject: [PATCH] Little refactor (#132) --- .../transformers/transformInstanceNode.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugin-src/transformers/transformInstanceNode.ts b/plugin-src/transformers/transformInstanceNode.ts index 45c22bc..66578ee 100644 --- a/plugin-src/transformers/transformInstanceNode.ts +++ b/plugin-src/transformers/transformInstanceNode.ts @@ -20,14 +20,14 @@ export const transformInstanceNode = async ( ): Promise => { const mainComponent = await node.getMainComponentAsync(); - if (!isNodeProcessable(node, mainComponent)) { + if (mainComponent === null || isUnprocessableComponent(mainComponent)) { return; } return { type: 'instance', name: node.name, - mainComponentFigmaId: mainComponent?.id ?? '', + mainComponentFigmaId: mainComponent.id, isComponentRoot: isComponentRoot(node), ...transformFigmaIds(node), ...(await transformFills(node)), @@ -42,17 +42,15 @@ export const transformInstanceNode = async ( }; }; -const isNodeProcessable = (node: SceneNode, mainComponent: ComponentNode | null): boolean => { - /** - * We do not want to process component instances in the following scenarios: - * - * 1. If the component does not have a main component. - * 2. If the component comes from an external design system. - * 3. If th component does not have a parent. (it's been removed) - * 4. Main component can be in a ComponentSet removed from the page or external design system. - */ - return !( - !mainComponent || +/** + * We do not want to process component instances in the following scenarios: + * + * 1. If the component comes from an external design system. + * 2. If the component does not have a parent. (it's been removed) + * 3. Main component can be in a ComponentSet (the same logic applies to the parent). + */ +const isUnprocessableComponent = (mainComponent: ComponentNode): boolean => { + return ( mainComponent.remote || mainComponent.parent === null || (mainComponent.parent?.type === 'COMPONENT_SET' &&