| 2580 | * @since 3.10.0 |
| 2581 | */ |
| 2582 | export const mutable = (ast: AST): AST => { |
| 2583 | switch (ast._tag) { |
| 2584 | case "TupleType": |
| 2585 | return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations) |
| 2586 | case "TypeLiteral": { |
| 2587 | const propertySignatures = changeMap( |
| 2588 | ast.propertySignatures, |
| 2589 | (ps) => |
| 2590 | ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations) |
| 2591 | ) |
| 2592 | const indexSignatures = changeMap( |
| 2593 | ast.indexSignatures, |
| 2594 | (is) => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false) |
| 2595 | ) |
| 2596 | return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? |
| 2597 | ast : |
| 2598 | new TypeLiteral(propertySignatures, indexSignatures, ast.annotations) |
| 2599 | } |
| 2600 | case "Union": { |
| 2601 | const types = changeMap(ast.types, mutable) |
| 2602 | return types === ast.types ? ast : Union.make(types, ast.annotations) |
| 2603 | } |
| 2604 | case "Suspend": |
| 2605 | return new Suspend(() => mutable(ast.f()), ast.annotations) |
| 2606 | case "Refinement": { |
| 2607 | const from = mutable(ast.from) |
| 2608 | return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations) |
| 2609 | } |
| 2610 | case "Transformation": { |
| 2611 | const from = mutable(ast.from) |
| 2612 | const to = mutable(ast.to) |
| 2613 | return from === ast.from && to === ast.to ? |
| 2614 | ast : |
| 2615 | new Transformation(from, to, ast.transformation, ast.annotations) |
| 2616 | } |
| 2617 | } |
| 2618 | return ast |
| 2619 | } |
| 2620 | |
| 2621 | // ------------------------------------------------------------------------------------- |
| 2622 | // compiler harness |