	extends ResolvedConfig,
		ScopeOnlyConfigOptions {}

$ark.ambient ??= {} as never

let rawUnknownUnion: UnionNode | undefined

const rootScopeFnName = "function $"

const precompile = (references: readonly BaseNode[]): void =>
	bindPrecompilation(references, precompileReferences(references))

const bindPrecompilation = (
	references: readonly BaseNode[],
	precompiler: CompiledFunction<() => PrecompiledReferences>
): void => {
	const precompilation = precompiler.write(rootScopeFnName, 4)
	const compiledTraversals = precompiler.compile()()

	for (const node of references) {
		if (node.precompilation) {
			// if node has already been bound to another scope or anonymous type, don't rebind it
			continue
		}
		node.traverseAllows =
			compiledTraversals[`${node.id}Allows`].bind(compiledTraversals)
		if (node.isRoot() && !node.allowsRequiresContext) {
			// if the reference doesn't require context, we can assign over
			// it directly to avoid having to initialize it
			node.allows = node.traverseAllows as never
		}
