Skip to content

Commit

Permalink
Don't report recursive nodes in debugAst
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Aug 23, 2024
1 parent 67b1f64 commit c661fb4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { AstNode } from './ast'
import { inferredTypeToString } from './typecheck'
import { ExtractKeys } from './util/type'

export const debugAst = (node: AstNode, focusKinds: ExtractKeys<AstNode>[] = ['kind', 'type'], depth = 0): any => {
if (depth > 10) return '@rec'
export const debugAst = (
node: AstNode,
focusKinds: ExtractKeys<AstNode>[] = ['kind', 'type'],
reportRecursive = false,
depth = 0
): any => {
if (depth > 10) return reportRecursive ? '@rec' : undefined

const o = Object.fromEntries(
Object.entries(node)
Expand All @@ -24,11 +29,13 @@ export const debugAst = (node: AstNode, focusKinds: ExtractKeys<AstNode>[] = ['k
}
}
if (Array.isArray(v)) {
const items = v.map(i => debugAst(i, focusKinds, depth + 1)).filter(i => i !== undefined)
const items = v
.map(i => debugAst(i, focusKinds, reportRecursive, depth + 1))
.filter(i => i !== undefined)
return [p, items]
}
if (typeof v === 'object' && 'parseNode' in v) {
return [p, debugAst(v, focusKinds, depth + 1)]
return [p, debugAst(v, focusKinds, reportRecursive, depth + 1)]
}
if (focusKinds.includes(<any>p)) {
return [p, v]
Expand Down

0 comments on commit c661fb4

Please sign in to comment.