goscript

module
v0.0.0-...-58ba716 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT

README

GoScript

GoDoc Widget Go Report Card Widget

Introduction

GoScript is a Go to TypeScript compiler. It allows Go programs to run in the browser after being checked and optimized by the TypeScript compiler.

It's currently an experimental project, and not ready for production.

Generated Code

Below is a simple example of how code is generated:

package main

import (
	"os"
)

func main() {
	os.Stdout.WriteString("Hello world!\n")
}

Generated with goscript compile .:

import * as os from "@go/os";
function main() {
	os.Stdout.WriteString("Hello world!\n");
}

Code is compiled with GOARCH=js. Code designed to work with syscall/js and wasm /should/ work correctly with GoScript out of the box.

All Go import paths are prefixed with @go/ and can be imported in TypeScript:

import { MyFunction, MyStruct } from '@go/github.com/myorg/mypackage';

MyFunction();
let myThing = new MyStruct();
myThing.DoSometing();

Go structs are converted into classes.

Roadmap

  • Sample programs compile & run
  • Generate init() function to recursively initialize packages
  • Tooling to integrate with typescript compiler
  • "go test" implementation with Go -> Ts transformation
  • performance testing
  • examples of calling Go code from TypeScript

At the moment, some of the Go ast is not implemented. This work will be completed first before tackling the above features.

Directories

Path Synopsis
cmd
example

Jump to

Keyboard shortcuts

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