Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
babel-plugin-transform-jsx-flexible
Advanced tools
Babel plugin to allow multiple JSX handlers in the same file.
Turn JSX into arbitrary function calls
This is a drop-in replacement for
babel-plugin-transform-react-jsx
,
with the additional feature that multiple JSX handler functions can be used in
the same file. The plugin passes all tests for the transform-react-jsx
plugin (included in this repo).
Changing the JSX handler within a file is accomplished by enclosing a JSX block
within a special tag that is defined in the plugin's configuration (see the
tags
option below).
npm install --save-dev babel-plugin-transform-react-jsx
.babelrc
(Recommended).babelrc
Without options (no different from transform-react-jsx
):
{
"plugins": ["transform-jsx-flexible"]
}
With options:
{
"plugins": [
["transform-jsx-flexible", {
"tags": {
"CustomTag1": "createElement_CustomTag1",
"CustomTag2": "createElement_CustomTag2"
}
}]
]
}
Code In
var profile = <div>
<img src="avatar.png" className="profile" />
<h3>{[user.firstName, user.lastName].join(' ')}</h3>
</div>;
var somethingElse = <CustomTag1>
<div />
</CustomTag1>;
Code Out
var profile = React.createElement("div", null,
React.createElement("img", { src: "avatar.png", className: "profile" }),
React.createElement("h3", null, [user.firstName, user.lastName].join(" "))
);
var somethingElse = createElement_CustomTag1(CustomTag1, null,
createElement_CustomTag1("div", null)
);
pragma
Inherited from babel-plugin-transform-react-jsx
.
string
, defaults to React.createElement
.
Replace the function used when compiling JSX expressions.
Note that the @jsx React.DOM
pragma has been deprecated as of React v0.12
useBuiltIns
Inherited from babel-plugin-transform-react-jsx
.
boolean
, defaults to false
.
When spreading props, use Object.assign
directly instead of Babel's extend helper.
tags
An object that maps custom JSX tag names (the keys) to custom functions (the values) that should be used to render any JSX element enclosed inside the given custom tag name.
For example:
"plugins": [
"transform-jsx-flexible",
{
"tags": {
"CustomTag1": "createElement_CustomTag1",
"CustomTag2": "createElement_CustomTag2"
}
}
]
Using this configuration, any CustomTag1
element and any JSX elements
enclosed inside of it will be created using the function
createElement_CustomTag1()
in the transpiled JS code, instead of
React.createElement
(or the current default JSX function).
The same goes for CustomTag2
and createElement_CustomTag2
. Also, JSX
handlers can be changed within the same block by nesting these custom tags
together.
FAQs
Babel plugin to allow multiple JSX handlers in the same file.
The npm package babel-plugin-transform-jsx-flexible receives a total of 1 weekly downloads. As such, babel-plugin-transform-jsx-flexible popularity was classified as not popular.
We found that babel-plugin-transform-jsx-flexible demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.