jsx

package module
v0.0.0-...-78100e2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 8 Imported by: 0

README

React JSX without Node.js

Go-jsx is a convenient tool that converts React JSX code into Javascript without requiring Node.js.

With Go installed

$ go get github.com/tiborvass/go-jsx/cmd/jsx
$ cd $GOPATH/src/github.com/tiborvass/go-jsx/examples/basic-jsx-precompile
$ $GOPATH/bin/jsx example.jsx > example.js
$ diff -u example.jsx example.js

Notes

I'm not proud of the code in any way, I'm just happy it seems to work for my usecase. Feel free to fix bugs and improve the code.

License

The examples folder taken from Facebook's React repository have their own license at examples/LICENSE-examples.

The rest of the code is under the MIT License.

Documentation

Overview

Jsx transpiles React JSX code to Javascript.

This package also provides primitives to write your own visitors

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(filename string) (string, error)

File takes the name of a JSX file as input and returns the Javascript version of the content.

func String

func String(src string) (string, error)

String takes JSX source code as input and returns Javascript.

Types

type Attr

type Attr struct {
	Payload string
	Typ     AttrType
}

type AttrType

type AttrType int
const (
	HtmlAttr AttrType = iota
	JsAttr
)

type ElementNode

type ElementNode struct {
	Name        string
	Children    []Node
	Attrs       map[string]Attr
	SpreadAttrs []JsNode
}

func (ElementNode) Node

func (ElementNode) Node()

type JsNode

type JsNode string

func (JsNode) Node

func (JsNode) Node()

type Node

type Node interface {
	Node()
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func (*Parser) Parse

func (p *Parser) Parse() (finalErr error)

type React

type React struct {
	// contains filtered or unexported fields
}

React implements Visitor. Should be called with Walk(NewReact(...), node).

func NewReact

func NewReact(fset *file.FileSet, errList parser.ErrorList, file *file.File) *React

NewReact returns a ready-to-use React object.

func (*React) Enter

func (v *React) Enter(node ast.Node) ast.Visitor

TODO: refactor this and expose only something like the current `v.str()` to spare others from reimplementing the whole visitor when all they need is to provide a string given an *ElementNode.

func (*React) Exit

func (v *React) Exit(node ast.Node)

func (*React) String

func (v *React) String() string

String returns the Javascript version of what the React visitor processed so far.

type TextNode

type TextNode string

func (TextNode) Node

func (TextNode) Node()

Directories

Path Synopsis
cmd
jsx

Jump to

Keyboard shortcuts

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