generator

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package generator creates TypeScript client code for Go WASM functions.

Two modes are supported:

  • Sync mode: class that calls globalThis functions directly
  • Worker mode: class that communicates via Web Worker

Go functions returning (T, error) automatically throw in TypeScript using the __error field convention defined by ErrorFieldName.

Index

Constants

View Source
const ErrorFieldName = "__error"

ErrorFieldName is the JSON field used to pass Go errors through the WASM boundary. When a Go function returns (T, error), the generated binding returns map[string]interface{}{ErrorFieldName: err.Error()} on error. The TypeScript client checks for this field and throws it as a JavaScript Error.

Variables

This section is empty.

Functions

func DeriveClassName added in v1.1.0

func DeriveClassName(dirName string) string

DeriveClassName generates a TypeScript class name from a directory name. It prepends "Go" and converts to TitleCase, unless the directory name is "go" or starts with "go-" or "go_" (to avoid "GoGoWasm" from "go-wasm").

func Generate

func Generate(parsed *parser.ParsedFile, outputFile, className string) string

Generate creates TypeScript class-based client for sync mode. This generates a class that wraps globalThis function calls.

func GenerateClient

func GenerateClient(parsed *parser.ParsedFile, outputFile, className string) string

GenerateClient creates client.ts with a class-based API for worker mode.

func GenerateGoBindings

func GenerateGoBindings(parsed *parser.ParsedFile, workerMode bool) string

GenerateGoBindings generates Go wrapper code for WASM export. workerMode determines whether callbacks use postMessage-based invocation (true) or direct JS function invocation (false).

func GenerateWorker

func GenerateWorker(wasmPath string) string

GenerateWorker creates worker.js content that runs Go WASM in a Web Worker. The wasmPath parameter specifies the path to the WASM file (e.g., "module.wasm").

func GenerateWorkerClassMethod

func GenerateWorkerClassMethod(fn parser.GoFunction) string

GenerateWorkerClassMethod creates a single async instance method for worker mode.

func LowerFirst added in v1.1.0

func LowerFirst(s string) string

LowerFirst converts first letter to lowercase. Used for converting Go function names to JavaScript conventions.

func ToKebabCase added in v1.1.0

func ToKebabCase(s string) string

ToKebabCase converts "GoMain" to "go-main". Used for generating TypeScript filenames from class names.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL