From 146d2a22ee4918642af916d86704b438ad585cfd Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 5 Nov 2025 16:18:34 -0800 Subject: [PATCH] get rid of all those Comments --- src/compiler/compiler.ts | 4 ++-- src/compiler/utils.ts | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index 2e62450..429a94b 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -657,7 +657,7 @@ export class Compiler { } case terms.Array: { - const children = getAllChildren(node).filter((n) => n.type.id !== terms.Comment) + const children = getAllChildren(node) // We can easily parse [=] as an empty dict, but `[ = ]` is tougher. // = can be a valid word, and is also valid inside words, so for now we cheat @@ -676,7 +676,7 @@ export class Compiler { } case terms.Dict: { - const children = getAllChildren(node).filter((n) => n.type.id !== terms.Comment) + const children = getAllChildren(node) const instructions: ProgramItem[] = [] children.forEach((node) => { diff --git a/src/compiler/utils.ts b/src/compiler/utils.ts index ed0dfcc..20afa96 100644 --- a/src/compiler/utils.ts +++ b/src/compiler/utils.ts @@ -22,7 +22,8 @@ export const getAllChildren = (node: SyntaxNode): SyntaxNode[] => { children.push(child) child = child.nextSibling } - return children + + return children.filter((n) => n.type.id !== terms.Comment) } export const getBinaryParts = (node: SyntaxNode) => { @@ -50,13 +51,15 @@ export const getAssignmentParts = (node: SyntaxNode) => { // array destructuring if (left && left.type.id === terms.Array) { - const identifiers = getAllChildren(left).filter(child => child.type.id === terms.Identifier) + const identifiers = getAllChildren(left).filter((child) => child.type.id === terms.Identifier) return { arrayPattern: identifiers, right } } if (!left || left.type.id !== terms.AssignableIdentifier) { throw new CompilerError( - `Assign left child must be an AssignableIdentifier or Array, got ${left ? left.type.name : 'none'}`, + `Assign left child must be an AssignableIdentifier or Array, got ${ + left ? left.type.name : 'none' + }`, node.from, node.to ) @@ -71,7 +74,9 @@ export const getCompoundAssignmentParts = (node: SyntaxNode) => { if (!left || left.type.id !== terms.AssignableIdentifier) { throw new CompilerError( - `CompoundAssign left child must be an AssignableIdentifier, got ${left ? left.type.name : 'none'}`, + `CompoundAssign left child must be an AssignableIdentifier, got ${ + left ? left.type.name : 'none' + }`, node.from, node.to )