Documentation
¶
Index ¶
- func ExtractUsedHelpers(pkg *packages.Package, root ast.Node) ([]ast.Decl, []*types.PkgName, error)
- func ExtractUsedImports(pkg *packages.Package, root ast.Node) ([]*ast.ImportSpec, error)
- func FormatNode(node ast.Node, fset *token.FileSet) (string, error)
- func StripPackageAndImports(src string) (string, error)
- type Entry
- type Loader
- type PageConfigResult
- type PosError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractUsedHelpers ¶
ExtractUsedHelpers performs a BFS over identifier references starting at root. Same-package function/const/type declarations referenced (transitively) are returned in discovery order. External package names are collected separately and deduplicated by imported *types.Package.
Package-level vars are rejected with a positioned error to keep WASM bodies pure (no hidden mutable shared state pulled into the generated main).
func ExtractUsedImports ¶
ExtractUsedImports returns the import specs in pkg that are referenced from the AST subtree rooted at root. Imports are deduplicated by path; aliases from the original spec are preserved.
func FormatNode ¶
FormatNode renders an AST node back to Go source. For *ast.BlockStmt the outer braces are stripped so the caller can splice the inner statements directly into another body.
func StripPackageAndImports ¶
StripPackageAndImports parses src as a Go file and returns the formatted source with the package clause and all import declarations removed. Doc comments on remaining declarations are preserved.
Types ¶
type Loader ¶
Loader is a one-shot loader over a directory's Go packages, indexed by absolute file path.
type PageConfigResult ¶
type PageConfigResult struct {
Body *ast.BlockStmt
Compression string
Compiler string
// Multiplexed reflects the RouteConfig.Multiplexed bool field. When true the
// generated main() registers the ClientSideState body via GothicRegisterScope
// so one instance serves every placement of the component (opt-in).
Multiplexed bool
}
PageConfigResult holds extracted data from a RouteConfig composite literal (router.RouteConfig in a real project; routes.RouteConfig in the astx testdata).
func ExtractClientSideStateBody ¶
func ExtractClientSideStateBody(entry Entry) (PageConfigResult, bool, error)
ExtractClientSideStateBody scans entry.File for a composite literal whose type (per TypesInfo) is a RouteConfig — router.RouteConfig in a real project (github.com/gothicframework/core/router) or routes.RouteConfig in the astx testdata fixtures — and which contains a ClientSideState key. It supports either an inline FuncLit value or a named function ident (resolved through TypesInfo.Uses → its FuncDecl).
It also extracts the WasmCompression field value (as a plain identifier name like "BROTLI" or "GZIP", or a string literal if written as such) when present.
Returns (result, true, nil) when found, (zero, false, nil) when no such literal exists, and a *PosError when the literal is malformed.