Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Jun 3, 2024
1 parent dfb209b commit 05e49a9
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@ export const transformInstanceNode = async (
): Promise<ComponentInstance | undefined> => {
const mainComponent = await node.getMainComponentAsync();

/**
* 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)
*/
if (!mainComponent || mainComponent.remote || mainComponent.parent === null) {
return;
}

/**
* Main component can be in a ComponentSet removed from the page or external design system.
*/
if (
mainComponent.parent?.type === 'COMPONENT_SET' &&
(mainComponent.parent.parent === null || mainComponent.parent.remote)
) {
if (!mainComponent || !isNodeProcessable(node, mainComponent)) {
return;
}

Expand All @@ -59,6 +42,24 @@ export const transformInstanceNode = async (
};
};

const isNodeProcessable = (node: SceneNode, mainComponent: ComponentNode | undefined): 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 ||
mainComponent.remote ||
mainComponent.parent === null ||
(mainComponent.parent?.type === 'COMPONENT_SET' &&
(mainComponent.parent.parent === null || mainComponent.parent.remote))
);
};

const isComponentRoot = (node: InstanceNode): boolean => {
let parent = node.parent;
while (parent !== null) {
Expand Down

0 comments on commit 05e49a9

Please sign in to comment.