Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-react-create-element

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

babel-plugin-transform-react-create-element - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

package.json
{
"name": "babel-plugin-transform-react-create-element",
"version": "0.2.0",
"version": "0.2.1",
"description": "Shorten JSX React.createElement calls using a local variable.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -39,2 +39,4 @@ # babel-plugin-transform-react-create-element

Install via `npm install -D babel-plugin-transform-react-create-element` or `yarn add -D babel-plugin-transform-react-create-element`.
In your `.babelrc`:

@@ -41,0 +43,0 @@

@@ -5,8 +5,3 @@ "use strict";

const template_1 = tslib_1.__importDefault(require("@babel/template"));
const PRAGMA_ELEM_NAME = "createElement";
const LOCAL_VARIABLE_TEMPLATE = template_1.default(`
const %%pragma%% = /*#__PURE__*/ React.createElement;
`, {
preserveComments: true,
});
const LOCAL_VARIABLE_TEMPLATE = template_1.default("const %%localIdentifier%% = /*#__PURE__*/ React.createElement;", { preserveComments: true });
const getReactImport = (path) => {

@@ -18,3 +13,4 @@ const binding = path.scope.getBinding(path.node.name);

const bindingPath = binding.path;
if (bindingPath.isImportDefaultSpecifier()) {
if (bindingPath.isImportDefaultSpecifier() ||
bindingPath.isImportNamespaceSpecifier()) {
const parentPath = bindingPath.parentPath;

@@ -39,3 +35,3 @@ if (parentPath.isImportDeclaration() &&

};
const getCreateElementAndImport = (path) => {
const getCreateElementCallAndReactImport = (path) => {
const callee = path.get("callee");

@@ -50,2 +46,5 @@ if (!callee.isMemberExpression()) {

const object = callee.get("object");
if (!object.isIdentifier()) {
return null;
}
const reactImport = getReactImport(object);

@@ -58,5 +57,5 @@ if (!reactImport) {

const insertLocalVariable = (importSite) => {
const uniqueIdent = importSite.scope.generateUidIdentifier(PRAGMA_ELEM_NAME);
const uniqueIdent = importSite.scope.generateUidIdentifier("createElement");
const variableDeclaration = LOCAL_VARIABLE_TEMPLATE({
pragma: uniqueIdent,
localIdentifier: uniqueIdent,
});

@@ -71,3 +70,3 @@ const [node] = importSite.parentPath.insertAfter(variableDeclaration);

CallExpression(path, state) {
const data = getCreateElementAndImport(path);
const data = getCreateElementCallAndReactImport(path);
if (!data) {

@@ -74,0 +73,0 @@ return;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc