New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swc_plugin_transform_cx_jsx

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

swc_plugin_transform_cx_jsx

Plugin for swc.rs that transforms cxjs.io

24.3.2
unpublished
latest
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

swc-plugin-transform-cx-jsx

Having improved performance, this plugin replaces babel-plugin-transform-cx-jsx.

This is an SWC plugin that transforms JSX code wrapped inside <cx> tags into plain JavaScript.

Example:

const page = (
   <cx>
      <div>
         <h1>Cx</h1>
         <p>Some text</p>
      </div>
   </cx>
);

becomes

const page = {
   type: HtmlElement,
   tag: "div",
   children: [
      {
         type: HtmlElement,
         tag: "h1",
         children: ["Cx"],
      },
      {
         type: HtmlElement,
         tag: "p",
         children: ["Some text"],
      },
   ],
};

Functional Components

Functional components in CxJS have to be wrapped inside a createFunctionalComponent call. When transformFunctionalComponents is set to true the plugin will automatically add the call for expressions which immediately return a <cx> block. i.e. (props) => <cx></cx>;

const MySuperTextField = ({label, value}) => <cx>
   <TextField value={value} label={label} mod="super" validation-mode="inline" />
</cx>;

becomes

const MySuperTextField = createFunctionalComponent(({label, value}) => <cx>
   <TextField value={value} label={label} mod="super" validation-mode="inline" />
</cx>);

Trim Whitespace

Small gains in bundle size can be gained if trimWhitespace is set to true. This will remove the whitespace between elements, unless the parent element has the ws or preserveWhitespace flag set. Some elements, such as code, should not be touched and this can be addressed using the trimWhitespaceExceptions configuration parameter.

Example 1

<cx>
   <div>
      <div />
   </div>
</cx>
const page = {
   type: HtmlElement,
   tag: "div",
   children: [
      "    " //<- This line will be removed
      {
         type: HtmlElement,
         tag: "div",
      },
      "    " //<- This line will be removed
   ],
};

Example 2

<cx>
   <div ws>
      <div />
   </div>
</cx>
const page = {
   type: HtmlElement,
   tag: "div",
   ws: true,
   children: [
      "    " //<- This line will be preserved because of the ws parameter
      {
         type: HtmlElement,
         tag: "div",
      },
      "    " //<- This line will be preserved because of the ws parameter
   ],
};

FAQs

Package last updated on 05 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts