Skip to content

OC-Git/jsx-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsx-compiler

This work is in very large parts based upon the work of the DataFormsJS project and their jsx-loader!

Here their compiler is merely re-package to be available standalone.

Installation

Very simple:

npm install jsx-compiler

Compile to Component

You can compile a JSX script to a React component:

import Compiler from 'jsx-compiler'

const script = `
    return (
        <>
        {list.map(item => (
            <div key={item}>
                {item} {p.b}
            </div>))}
        </>
)`;
const ctx = {
list: ["a", "b", "c"],
};

const compiler = new Compiler();
const Component = compiler.compileToComponent(ctx, script, "p");

return <Component b="hihi" />;

This <Component/> will behave as expected.

Compile to String

You can compile a JSX script to JavaScript:

import Compiler from 'jsx-compiler'

const script = `
    return <div>huhu</div>
`

const compiler = new Compiler();
return compiler.compileToString(script);

Here, return React.createElement("div", null, "huhu") will be returned.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors