Coder Social home page Coder Social logo

sgano1 / goja-babel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jvatic/goja-babel

0.0 0.0 0.0 2.58 MB

Run babel transforms using Go to transpile your modern JavaScript and JSX.

License: BSD 3-Clause "New" or "Revised" License

Go 87.60% Shell 12.40%

goja-babel's Introduction

goja-babel

Uses github.com/dop251/goja to run babel.js within Go.

WARNING: This uses Babel v6.26 which is not the latest. Feel free to create a PR updating it to the latest.

WARNING: This is largely untested and the exposed API may change at any time.

Usage

package main

import (
	"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;
	<div>
		Hello JSX!
		The value of foo is {foo}.
	</div>`), map[string]interface{}{
		"plugins": []string{
			"transform-react-jsx",
			"transform-es2015-block-scoping",
		},
	})
	if err != nil {
		panic(err)
	}
	io.Copy(os.Stdout, res)
	fmt.Println("")
}
var foo = 1;
React.createElement(
	"div",
	null,
	"Hello JSX! The value of foo is ",
	foo,
	"."
);

Benchmarks

$ go test -bench Transform -benchmem
BenchmarkTransformString-8                    	     200	   6042202 ns/op	  925350 B/op	   15779 allocs/op
BenchmarkTransformStringWithSingletonPool-8   	     200	   5976874 ns/op	  927350 B/op	   15809 allocs/op
BenchmarkTransformStringWithLargePool-8       	     300	   5892891 ns/op	  926572 B/op	   15799 allocs/op
PASS
ok  	github.com/jvatic/goja-babel	20.346s

goja-babel's People

Contributors

jvatic avatar magicaltux avatar theharveyz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.