import type { arkKeyOf, array } from "@ark/util"; import type { distill, inferIntersection, inferPipe, LimitLiteral, withDefault } from "../../attributes.ts"; import type { type } from "../../keywords/keywords.ts"; import type { inferDefinition } from "../definition.ts"; import type { Comparator } from "../reduce/shared.ts"; import type { InfixToken, PostfixToken } from "../shift/tokens.ts"; import type { GenericInstantiationAst, inferGenericInstantiation } from "./generic.ts"; export type inferAstRoot = ast extends array ? inferExpression : never; export type inferAstIn = distill.In>; export type inferAstOut = distill.Out>; export type DefAst = [ def, "def", alias ]; export type InferredAst = [ t, "inferred", def ]; export type inferExpression = ast extends array ? ast extends InferredAst ? resolution : ast extends DefAst ? inferDefinition : ast extends GenericInstantiationAst ? inferGenericInstantiation : ast[1] extends "[]" ? inferExpression[] : ast[1] extends "|" ? inferExpression | inferExpression : ast[1] extends "&" ? inferIntersection, inferExpression> : ast[1] extends "|>" ? inferPipe, inferExpression> : ast[1] extends "=" ? type.infer extends infer defaultValue ? withDefault, defaultValue> : never : ast[1] extends "#" ? type.brand, ast[2]> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? inferExpression : inferExpression : ast[1] extends "%" ? inferExpression : ast[1] extends "?" ? inferExpression : ast[0] extends "keyof" ? arkKeyOf> : never : never; export type PrefixOperator = "keyof" | "instanceof" | "===" | "node"; export type PrefixExpression = [operator, operand]; export type PostfixExpression = readonly [operand, operator]; export type InfixExpression = [l, operator, r];