Use Loong syntax to write react components.
babel-plugin-transform-loong
is a plugin for babel which transpiles LSX syntax within template literals to JSX.
npm install --save-dev babel-plugin-syntax-jsx @loong-js/babel-plugin-transform-loong
Add the following line to your .babelrc file:
{
"plugins": [
"@babel/plugin-syntax-jsx",
"@loong-js/babel-plugin-transform-loong"
]
}
LSX syntax is a simplified version of JSX syntax. There are some JS features in LSX that cannot be used, such as rendering functions, loops, ternary, etc.
<condition>
<if condition={data > 1}>This condition 1</if>
<elseif condition={data === 2}>This condition 2</elseif>
<else>This condition 3</else>
</condition>
To
<Condition>
<Condition.If condition={data > 1}>This condition 1</Condition.If>
<Condition.Elseif condition={data === 2}>This condition 2</Condition.Elseif>
<Condition.Else>This condition 3</Condition.Else>
</Condition>
<foreach iterable={data} variable="item,index">
<div>
{item.name}-{index}
</div>
</foreach>
To
<Foreach>
{(item, index) => (
<div>
{item.name}-{index}
</div>
)}
</Foreach>
<Component>
<slot name="prefix">
<div>εηΌ</div>
</slot>
// After adding the rendering property, enable the rendering function
<slot rendering name="renderPrefix" variable="value">
<div>{value}εηΌ</div>
</slot>
</Component>
To
<Component
prefix={<div>εηΌ</div>}
renderPrefix={(value) => <div>{value}εηΌ</div>}
/>
If you find a bug, please file an issue on our issue tracker on GitHub.
Changes are tracked in the CHANGELOG.md.
babel-plugin-transform-loong
is available under the MIT License.