get rid of all those Comments

This commit is contained in:
Corey Johnson 2025-11-05 16:18:34 -08:00
parent 653ff5df10
commit 146d2a22ee
2 changed files with 11 additions and 6 deletions

View File

@ -657,7 +657,7 @@ export class Compiler {
} }
case terms.Array: { 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. // 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 // = 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: { case terms.Dict: {
const children = getAllChildren(node).filter((n) => n.type.id !== terms.Comment) const children = getAllChildren(node)
const instructions: ProgramItem[] = [] const instructions: ProgramItem[] = []
children.forEach((node) => { children.forEach((node) => {

View File

@ -22,7 +22,8 @@ export const getAllChildren = (node: SyntaxNode): SyntaxNode[] => {
children.push(child) children.push(child)
child = child.nextSibling child = child.nextSibling
} }
return children
return children.filter((n) => n.type.id !== terms.Comment)
} }
export const getBinaryParts = (node: SyntaxNode) => { export const getBinaryParts = (node: SyntaxNode) => {
@ -50,13 +51,15 @@ export const getAssignmentParts = (node: SyntaxNode) => {
// array destructuring // array destructuring
if (left && left.type.id === terms.Array) { 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 } return { arrayPattern: identifiers, right }
} }
if (!left || left.type.id !== terms.AssignableIdentifier) { if (!left || left.type.id !== terms.AssignableIdentifier) {
throw new CompilerError( 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.from,
node.to node.to
) )
@ -71,7 +74,9 @@ export const getCompoundAssignmentParts = (node: SyntaxNode) => {
if (!left || left.type.id !== terms.AssignableIdentifier) { if (!left || left.type.id !== terms.AssignableIdentifier) {
throw new CompilerError( 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.from,
node.to node.to
) )