Documentation
¶
Overview ¶
Package compiler transpiles TypeScript async function bodies into ES2020 JavaScript with VLQ source-mapped diagnostics and static payload key validation.
Index ¶
Constants ¶
const ProgramName = "user_program.ts"
ProgramName is the source name given to the compiled user program inside goja; stack frames carrying it are user code.
Variables ¶
This section is empty.
Functions ¶
func CleanStack ¶
func CleanStack(msg string, cr *CompileResult) string
CleanStack keeps the error text and at most 3 user-code frames rendered as `at code:N: <source>`, dropping internal frames (`<eval>`, `__ptc_main`, native) and goja pc offsets that only cost tokens.
func FormatRuntimeError ¶
func FormatRuntimeError(errText string, cr *CompileResult) string
FormatRuntimeError translates goja stack locations using the esbuild VLQ sourcemap back to 1-based user TypeScript lines.
Types ¶
type CompileError ¶
CompileError describes a static syntax or payload preflight error with 1-based user source lines.
func (*CompileError) Error ¶
func (e *CompileError) Error() string
type CompileResult ¶
type CompileResult struct {
JSCode string
SourceMap []byte
SourceLine []string
// contains filtered or unexported fields
}
CompileResult holds the transpiled JavaScript and source mapping metadata.
func Compile ¶
func Compile(code string, payloads map[string]string) (*CompileResult, error)
Compile validates payload key references and transpiles TypeScript async body code to ES2020 JavaScript.
func (*CompileResult) UserLine ¶
func (cr *CompileResult) UserLine(genLine, genCol int) int
UserLine maps a 1-based line/column of the compiled JS (as reported by goja for ProgramName) to the user's source line; column 0 means unknown.