0.0.8 â€Ē Published 4 years ago

@loong-js/babel-plugin-transform-loong v0.0.8

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

@loong-js/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 @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"
  ]
}

ðŸ”Ļ 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>
  <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

<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

babel-plugin-transform-loong is available under the MIT License.

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago