mirror of https://github.com/amol-/dukpy.git
Support for JSX transpiling
This commit is contained in:
parent
5b06de69b8
commit
331a81b723
|
@ -1,5 +1,5 @@
|
|||
from .evaljs import evaljs, JSInterpreter
|
||||
from ._dukpy import JSRuntimeError
|
||||
from .coffee import coffee_compile
|
||||
from .babel import babel_compile
|
||||
from .babel import babel_compile, jsx_compile
|
||||
from .tsc import typescript_compile
|
|
@ -18,3 +18,10 @@ def babel_compile(source, **kwargs):
|
|||
es6code=source,
|
||||
babel_options=kwargs
|
||||
)
|
||||
|
||||
|
||||
def jsx_compile(source, mode='react'):
|
||||
modes = {
|
||||
'react': ["transform-react-jsx"]
|
||||
}
|
||||
return babel_compile(source, plugins=modes.get(mode, []))['code']
|
||||
|
|
|
@ -71,3 +71,12 @@ var greeter = new Greeter("Hello, world!");
|
|||
});"""
|
||||
|
||||
assert expected in ans, report_diff(expected, ans)
|
||||
|
||||
def test_jsx(self):
|
||||
ans = dukpy.jsx_compile('var react_hello = <h1>Hello, world!</h1>;')
|
||||
|
||||
expected = """"use strict";
|
||||
|
||||
var react_hello = React.createElement(\n "h1",\n null,\n "Hello, world!"\n);"""
|
||||
|
||||
assert expected == ans, report_diff(expected, ans)
|
Loading…
Reference in New Issue