Skip to content

Commit

Permalink
fix: fix undefined node without children being counted as a nested ch…
Browse files Browse the repository at this point in the history
…ild (#657)
  • Loading branch information
ChibiBlasphem authored Jan 15, 2025
1 parent 2dde21d commit 1964d56
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type AstNode,
isMainAstNode,
type MainAstBinaryNode,
type MainAstUnaryNode,
Expand All @@ -17,6 +18,10 @@ import { Icon } from 'ui-icons';
import { AstBuilderNode } from './AstBuilderNode';
import { Operator } from './Operator';

function isMainAstNodeWithChildren(astNode: AstNode): boolean {
return isMainAstNode(astNode) && astNode.children.length > 0;
}

export function MainAstBinaryOperatorLine({
treePath,
mainAstNode,
Expand All @@ -30,8 +35,8 @@ export function MainAstBinaryOperatorLine({
}) {
const { setAstNodeAtPath, setOperatorAtPath } = useAstNodeEditorActions();
const hasDirectNestedChildren =
isMainAstNode(mainAstNode.children[0]) &&
isMainAstNode(mainAstNode.children[1]);
isMainAstNodeWithChildren(mainAstNode.children[0]) &&
isMainAstNodeWithChildren(mainAstNode.children[1]);

function removeNesting() {
const nestedChild = mainAstNode.children[0];
Expand Down

0 comments on commit 1964d56

Please sign in to comment.