Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Little refactor #132

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const transformInstanceNode = async (
): Promise<ComponentInstance | undefined> => {
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)),
Expand All @@ -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' &&
Expand Down