Skip to content

Commit

Permalink
fix error on ast state machine
Browse files Browse the repository at this point in the history
better
  • Loading branch information
Pascal-Delange committed Nov 21, 2024
1 parent ddff6fb commit 9d98843
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/app-builder/src/services/editor/ast-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ export function useAstNodeEditor({
name,
};
if (isUnaryMainAstOperatorFunction(name)) {
const children = newNode.children.slice(0, 1);
newNode.children = children;
newNode.children = newNChildren(1, newNode.children);
} else if (isBinaryMainAstOperatorFunction(name)) {
newNode.children.push(NewUndefinedAstNode());
newNode.children = newNChildren(2, newNode.children);
}
set({
rootAstNode: setAtPath(rootAstNode, path, newNode),
Expand Down Expand Up @@ -134,6 +133,13 @@ export function useAstNodeEditor({
return store;
}

function newNChildren(n: number, currentChildren: AstNode[]) {
return Array.from(
{ length: n },
(_, i) => currentChildren[i] ?? NewUndefinedAstNode(),
);
}

export function AstNodeEditorProvider({
children,
store,
Expand Down

0 comments on commit 9d98843

Please sign in to comment.