MCPcopy
hub / github.com/Effect-TS/effect / typeAST

Function typeAST

packages/effect/src/SchemaAST.ts:2682–2736  ·  view source on GitHub ↗
(ast: AST)

Source from the content-addressed store, hash-verified

2680 * @since 3.10.0
2681 */
2682export const typeAST = (ast: AST): AST => {
2683 switch (ast._tag) {
2684 case "Declaration": {
2685 const typeParameters = changeMap(ast.typeParameters, typeAST)
2686 return typeParameters === ast.typeParameters ?
2687 ast :
2688 new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations)
2689 }
2690 case "TupleType": {
2691 const elements = changeMap(ast.elements, (e) => {
2692 const type = typeAST(e.type)
2693 return type === e.type ? e : new OptionalType(type, e.isOptional)
2694 })
2695 const restASTs = getRestASTs(ast.rest)
2696 const rest = changeMap(restASTs, typeAST)
2697 return elements === ast.elements && rest === restASTs ?
2698 ast :
2699 new TupleType(elements, rest.map((type) => new Type(type)), ast.isReadonly, ast.annotations)
2700 }
2701 case "TypeLiteral": {
2702 const propertySignatures = changeMap(ast.propertySignatures, (p) => {
2703 const type = typeAST(p.type)
2704 return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly)
2705 })
2706 const indexSignatures = changeMap(ast.indexSignatures, (is) => {
2707 const type = typeAST(is.type)
2708 return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly)
2709 })
2710 return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ?
2711 ast :
2712 new TypeLiteral(propertySignatures, indexSignatures, ast.annotations)
2713 }
2714 case "Union": {
2715 const types = changeMap(ast.types, typeAST)
2716 return types === ast.types ? ast : Union.make(types, ast.annotations)
2717 }
2718 case "Suspend":
2719 return new Suspend(() => typeAST(ast.f()), ast.annotations)
2720 case "Refinement": {
2721 const from = typeAST(ast.from)
2722 return from === ast.from ?
2723 ast :
2724 new Refinement(from, ast.filter, ast.annotations)
2725 }
2726 case "Transformation": {
2727 const preserve = preserveTransformationAnnotations(ast)
2728 return typeAST(
2729 preserve !== undefined ?
2730 annotations(ast.to, preserve) :
2731 ast.to
2732 )
2733 }
2734 }
2735 return ast
2736}
2737
2738function changeMap<A>(
2739 as: Arr.NonEmptyReadonlyArray<A>,

Callers 1

renameFunction · 0.85

Calls 6

changeMapFunction · 0.85
getRestASTsFunction · 0.85
annotationsFunction · 0.70
mapMethod · 0.65
makeMethod · 0.65
fMethod · 0.65

Tested by

no test coverage detected