Process generates schema statements for one or more named types. It populates internal state and returns accumulated statements.
(typeMap map[string]*checker.Type, scope *ast.Node, isExported bool)
| 594 | // Process generates schema statements for one or more named types. |
| 595 | // It populates internal state and returns accumulated statements. |
| 596 | func (g *StructuralSchemaGen) Process(typeMap map[string]*checker.Type, scope *ast.Node, isExported bool) []*ast.Node { |
| 597 | maps.Copy(g.nameToType, typeMap) |
| 598 | |
| 599 | // Scan existing schemas in scope for reuse |
| 600 | g.ScanExistingSchemas(scope) |
| 601 | |
| 602 | // Process each type |
| 603 | type processResult struct { |
| 604 | requestedName string |
| 605 | t *checker.Type |
| 606 | result *ast.Node |
| 607 | } |
| 608 | |
| 609 | var results []processResult |
| 610 | for name, t := range typeMap { |
| 611 | ctx := processingContext{ |
| 612 | depth: 0, |
| 613 | maxDepth: 200, |
| 614 | version: g.Version, |
| 615 | } |
| 616 | expr, err := g.processType(t, ctx) |
| 617 | if err != nil { |
| 618 | // On error, emit an error comment |
| 619 | expr = g.Tracker.NewIdentifier(fmt.Sprintf("undefined /* %s */", err.Error())) |
| 620 | } |
| 621 | results = append(results, processResult{ |
| 622 | requestedName: name, |
| 623 | t: t, |
| 624 | result: expr, |
| 625 | }) |
| 626 | } |
| 627 | |
| 628 | // Add variable statements for types that were not hoisted |
| 629 | for _, r := range results { |
| 630 | if _, ok := g.typeToStatementIndex[r.t.Id()]; ok { |
| 631 | continue |
| 632 | } |
| 633 | varDecl := g.Tracker.NewVariableDeclaration( |
| 634 | g.Tracker.NewIdentifier(r.requestedName), |
| 635 | nil, nil, |
| 636 | r.result, |
| 637 | ) |
| 638 | varDeclList := g.Tracker.NewVariableDeclarationList( |
| 639 | g.Tracker.NewNodeList([]*ast.Node{varDecl}), |
| 640 | ast.NodeFlagsConst, |
| 641 | ) |
| 642 | modifiers := g.Tracker.NewModifierList([]*ast.Node{ |
| 643 | g.Tracker.NewModifier(ast.KindExportKeyword), |
| 644 | }) |
| 645 | stmt := g.Tracker.NewVariableStatement(modifiers, varDeclList) |
| 646 | g.schemaStatements = append(g.schemaStatements, stmt) |
| 647 | g.typeToStatementIndex[r.t.Id()] = len(g.schemaStatements) - 1 |
| 648 | } |
| 649 | |
| 650 | // Add export modifiers to requested type statements |
| 651 | if isExported { |
| 652 | exportIndices := make(map[int]bool) |
| 653 | for _, t := range g.nameToType { |
no test coverage detected