shithub: mycel

ref: 1d50aea6c14615b107116dac70e71454099ece5d
dir: /cmd/6to5/main.go/

View raw version
// Conversion of ES6+ into ES5.1 (wip)
//
// TODO: turn into a script that uses devjs
package main

import (
	"fmt"
	"github.com/jvatic/goja-babel"
	"io"
	"log"
	"os"
)

func Main() (err error) {
	babel.Init(1) // Setup 1 transformer (can be any number > 0)
	r, err := babel.Transform(os.Stdin, map[string]interface{}{
		"plugins": []string{
			"transform-block-scoping",
			"transform-destructuring",
			"transform-spread",
			"transform-parameters",
		},
	})
	if err != nil {
		return fmt.Errorf("transform: %v", err)
	}
	_, err = io.Copy(os.Stdout, r)

	return
}

func main() {
	if err := Main(); err != nil {
		log.Fatalf("%v",err)
	}
}