As asked
You are given the root of a Figma document node tree where each node has a type (FRAME, GROUP, TEXT, RECTANGLE, etc.) and optionally a list of children. Write a function that returns all TEXT nodes whose characters field matches a given regular expression.
Sample answer outline
A strong answer uses BFS or DFS to traverse the tree, checks the type field before accessing characters, and handles missing or empty children gracefully without throwing. The candidate should note that DFS via recursion risks stack overflow on pathologically deep trees and offer an iterative BFS alternative. A great answer also considers the case where children arrays are lazily loaded and how you would handle async fetching in a real Figma plugin context.
Reference implementation (typescript)
interface FigmaNode {
id: string;
type: string;
characters?: string;
children?: FigmaNode[];
}
function findTextNodes(
root: FigmaNode,
pattern: RegExp
): FigmaNode[] {
// your implementation
}Expect these follow-ups
- How would you modify this to also return the full ancestor path from the root to each matching node?
- If you needed to replace the matched text in-place, how would you do that safely without corrupting the tree?