Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jvatic/goja-babel
Run babel transforms using Go to transpile your modern JavaScript and JSX.
https://github.com/jvatic/goja-babel
babel golang javascript react
Last synced: 1 day ago
JSON representation
Run babel transforms using Go to transpile your modern JavaScript and JSX.
- Host: GitHub
- URL: https://github.com/jvatic/goja-babel
- Owner: jvatic
- License: bsd-3-clause
- Created: 2017-02-22T00:05:06.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T12:18:17.000Z (3 months ago)
- Last Synced: 2024-10-25T12:41:21.736Z (3 months ago)
- Topics: babel, golang, javascript, react
- Language: Go
- Homepage:
- Size: 24.2 MB
- Stars: 60
- Watchers: 6
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
goja-babel
==========[![CI](https://github.com/jvatic/goja-babel/actions/workflows/ci.yml/badge.svg)](https://github.com/jvatic/goja-babel/actions/workflows/ci.yml)
Uses github.com/dop251/goja to run babel.js within Go.
## Usage
```go
package mainimport (
"fmt"
"io"
"os"
"strings""github.com/jvatic/goja-babel"
)func main() {
babel.Init(4) // Setup 4 transformers (can be any number > 0)
res, err := babel.Transform(strings.NewReader(`let foo = 1;
`), map[string]interface{}{
Hello JSX!
The value of foo is {foo}.
"plugins": []string{
"transform-react-jsx",
"transform-block-scoping",
},
})
if err != nil {
panic(err)
}
io.Copy(os.Stdout, res)
fmt.Println("")
}
``````js
$ go run main.go
var foo = 1;/*#__PURE__*/
React.createElement("div", null, "Hello JSX! The value of foo is ", foo, ".");
```## Benchmarks
```
go test -bench Transform -benchmem
goos: darwin
goarch: amd64
pkg: github.com/jvatic/goja-babel
cpu: Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
BenchmarkTransformString-8 81 15642708 ns/op 3069085 B/op 37243 allocs/op
BenchmarkTransformStringWithSingletonPool-8 67 15820676 ns/op 3070920 B/op 37244 allocs/op
BenchmarkTransformStringWithLargePool-8 78 15497562 ns/op 3070015 B/op 37243 allocs/op
PASS
ok github.com/jvatic/goja-babel 4.993s
```