0.0.3 â€Ē Published 3 years ago

babel-plugin-transform-loong v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

babel-plugin-transform-loong

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.

ðŸ“Ķ Installation

npm install --save-dev babel-plugin-syntax-jsx babel-plugin-transform-loong

Add the following line to your .babelrc file:

{
  "plugins": ["@babel/plugin-syntax-jsx", "babel-plugin-transform-loong"]
}

ðŸ”Ļ Usage

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

<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>
  <If condition={data > 1}>This condition 1</if>
  <Elseif condition={data === 2}>This condition 2</Elseif>
  <Else>This condition 3</Else>
</Condition>

Foreach

<foreach iterable={data} variable="item,index">
  <div>
    {item.name}-{index}
  </div>
</foreach>

To

<Foreach>
  {(item, index) => (
    <div>
      {item.name}-{index}
    </div>
  )}
</Foreach>

Slot

<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>}
/>

🐛 Issues

If you find a bug, please file an issue on our issue tracker on GitHub.

🏁 Changelog

Changes are tracked in the CHANGELOG.md.

📄 License

React Keep Alive is available under the MIT License.