https://github.com/paralin/goscript
Type-aware and modular Go to JavaScript compiler.
https://github.com/paralin/goscript
Last synced: 12 months ago
JSON representation
Type-aware and modular Go to JavaScript compiler.
- Host: GitHub
- URL: https://github.com/paralin/goscript
- Owner: paralin
- License: mit
- Created: 2017-03-29T00:10:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-18T22:16:59.000Z (almost 2 years ago)
- Last Synced: 2025-03-10T22:48:36.533Z (12 months ago)
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoScript
[![GoDoc Widget]][GoDoc] [![Go Report Card Widget]][Go Report Card]
[GoDoc]: https://godoc.org/github.com/paralin/goscript
[GoDoc Widget]: https://godoc.org/github.com/paralin/goscript?status.svg
[Go Report Card Widget]: https://goreportcard.com/badge/github.com/paralin/goscript
[Go Report Card]: https://goreportcard.com/report/github.com/paralin/goscript
## 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:
```go
package main
import (
"os"
)
func main() {
os.Stdout.WriteString("Hello world!\n")
}
```
Generated with `goscript compile .`:
```typescript
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:
```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.