( declared: readonly BaseNode[], unitFn: CompiledUnit, compiledTraversals: PrecompiledTraversals[], byId: Record<string, BaseNode>, owningScope?: BaseScope, unbound?: UnboundTraversals )
| 269 | } |
| 270 | |
| 271 | const bindUnit = ( |
| 272 | declared: readonly BaseNode[], |
| 273 | unitFn: CompiledUnit, |
| 274 | compiledTraversals: PrecompiledTraversals[], |
| 275 | byId: Record<string, BaseNode>, |
| 276 | owningScope?: BaseScope, |
| 277 | unbound?: UnboundTraversals |
| 278 | ): void => { |
| 279 | for (let i = 0; i < declared.length; i++) { |
| 280 | const node = declared[i] |
| 281 | if (unbound?.has(node)) { |
| 282 | unbound.set(node, compiledTraversals[i]) |
| 283 | continue |
| 284 | } |
| 285 | // if node has already been bound to another scope or anonymous type, don't rebind it |
| 286 | if (node.unitFn && (!owningScope || node.$ !== owningScope)) continue |
| 287 | if (!Object.isExtensible(node)) { |
| 288 | node.c.preJit = undefined |
| 289 | continue |
| 290 | } |
| 291 | const [tAllows, tApply, tTransform] = compiledTraversals[i] |
| 292 | if (node.c.preJit) { |
| 293 | node.allows = node.c.preJit |
| 294 | node.c.preJit = undefined |
| 295 | } |
| 296 | node.tAllows = tAllows |
| 297 | if (node.isRoot() && !node.allowsCtx) { |
| 298 | // if the reference doesn't require context, we can assign over |
| 299 | // it directly to avoid having to initialize it |
| 300 | node.allows = tAllows as never |
| 301 | } |
| 302 | node.tApply = tApply |
| 303 | if (tTransform) node.tTransform = tTransform |
| 304 | node.unitFn = unitFn |
| 305 | delete node.c.rootApply |
| 306 | node.c.isReusableLeaf = isLeafIn(node, byId) |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | type PrecompiledTraversals = [ |
| 311 | allows: TraverseAllows, |
no test coverage detected