mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-30 09:01:54 +00:00
refactor(util): narrow layer visitor options (#45734)
This commit is contained in:
parent
35231b408e
commit
02550b36c7
1 changed files with 2 additions and 4 deletions
|
|
@ -164,7 +164,6 @@ function isNode(input: Layer.Any | AnyNode): input is AnyNode {
|
|||
type Visit<Result> = (node: AnyNode, context: VisitContext<Result>) => Result
|
||||
|
||||
type VisitContext<Result> = {
|
||||
readonly cache: Map<AnyNode, Result>
|
||||
readonly visit: (node: AnyNode) => Result
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +173,6 @@ function walk<Result>(
|
|||
options: {
|
||||
readonly cache?: Map<AnyNode, Result>
|
||||
readonly resolve?: (node: AnyNode) => AnyNode
|
||||
readonly detectCycles?: boolean
|
||||
} = {},
|
||||
) {
|
||||
const cache = options.cache ?? new Map<AnyNode, Result>()
|
||||
|
|
@ -186,7 +184,7 @@ function walk<Result>(
|
|||
const cached = cache.get(target)
|
||||
if (cached !== undefined || cache.has(target)) return cached!
|
||||
|
||||
if (options.detectCycles !== false && visiting.has(target)) {
|
||||
if (visiting.has(target)) {
|
||||
const start = stack.indexOf(target)
|
||||
throw new Error(
|
||||
`Cycle detected in layer tree: ${[...stack.slice(start), target].map((item) => item.name).join(" -> ")}`,
|
||||
|
|
@ -196,7 +194,7 @@ function walk<Result>(
|
|||
visiting.add(target)
|
||||
stack.push(target)
|
||||
try {
|
||||
const result = visit(target, { cache, visit: recur })
|
||||
const result = visit(target, { visit: recur })
|
||||
if (!cache.has(target)) cache.set(target, result)
|
||||
return result
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue