Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-react-display-name

Package Overview
Dependencies
54
Maintainers
6
Versions
68
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.15.0 to 7.15.1

136

lib/index.js

@@ -14,92 +14,27 @@ "use strict";

function addDisplayNameInCreateClass(id, call) {
const props = call.arguments[0].properties;
let safe = true;
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
for (let i = 0; i < props.length; i++) {
const prop = props[i];
function addDisplayName(id, call) {
const props = call.arguments[0].properties;
let safe = true;
const key = _core.types.toComputedKey(prop);
for (let i = 0; i < props.length; i++) {
const prop = props[i];
if (_core.types.isLiteral(key, {
value: "displayName"
})) {
safe = false;
break;
const key = _core.types.toComputedKey(prop);
if (_core.types.isLiteral(key, {
value: "displayName"
})) {
safe = false;
break;
}
}
}
if (safe) {
props.unshift(_core.types.objectProperty(_core.types.identifier("displayName"), _core.types.stringLiteral(id)));
}
}
function getDisplayNameReferenceIdentifier(path) {
let id;
path.find(function (path) {
if (path.isAssignmentExpression()) {
id = path.node.left;
} else if (path.isObjectProperty()) {
id = path.node.key;
} else if (path.isVariableDeclarator()) {
id = path.node.id;
} else if (path.isStatement()) {
return true;
if (safe) {
props.unshift(_core.types.objectProperty(_core.types.identifier("displayName"), _core.types.stringLiteral(id)));
}
if (id) return true;
});
if (!id) return;
if (_core.types.isMemberExpression(id)) {
id = id.property;
}
if (!_core.types.isIdentifier(id)) return;
return id;
}
function isCreateContext(node) {
let callee;
return _core.types.isCallExpression(node) && _core.types.isMemberExpression(callee = node.callee) && _core.types.isIdentifier(callee.object, {
name: "React"
}) && (!callee.computed && _core.types.isIdentifier(callee.property, {
name: "createContext"
}) || _core.types.isStringLiteral(callee.property, {
value: "createContext"
}));
}
function buildDisplayNameAssignment(ref, displayName) {
return _core.types.assignmentExpression("=", _core.types.memberExpression(_core.types.cloneNode(ref), _core.types.identifier("displayName")), _core.types.stringLiteral(displayName));
}
function addDisplayNameAfterCreateContext(id, path) {
const {
parentPath
} = path;
if (parentPath.isVariableDeclarator()) {
const ref = parentPath.node.id;
parentPath.parentPath.insertAfter(buildDisplayNameAssignment(ref, id));
} else if (parentPath.isAssignmentExpression()) {
const ref = parentPath.node.left;
parentPath.insertAfter(buildDisplayNameAssignment(ref, id));
} else {
const {
scope
} = path;
const ref = scope.generateUidIdentifier("ref");
scope.push({
id: ref
});
path.replaceWith(_core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(ref), path.node), buildDisplayNameAssignment(ref, id), _core.types.cloneNode(ref)]));
}
}
const createContextVisited = new WeakSet();
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
const isCreateClassCallExpression = _core.types.buildMatchMemberExpression("React.createClass");

@@ -138,3 +73,3 @@

addDisplayNameInCreateClass(displayName, node.declaration);
addDisplayName(displayName, node.declaration);
}

@@ -147,21 +82,26 @@ },

} = path;
if (isCreateClass(node)) {
const id = getDisplayNameReferenceIdentifier(path);
if (id) {
addDisplayNameInCreateClass(id.name, node);
if (!isCreateClass(node)) return;
let id;
path.find(function (path) {
if (path.isAssignmentExpression()) {
id = path.node.left;
} else if (path.isObjectProperty()) {
id = path.node.key;
} else if (path.isVariableDeclarator()) {
id = path.node.id;
} else if (path.isStatement()) {
return true;
}
} else if (isCreateContext(node)) {
if (createContextVisited.has(node)) {
return;
}
createContextVisited.add(node);
const id = getDisplayNameReferenceIdentifier(path);
if (id) return true;
});
if (!id) return;
if (id) {
addDisplayNameAfterCreateContext(id.name, path);
}
if (_core.types.isMemberExpression(id)) {
id = id.property;
}
if (_core.types.isIdentifier(id)) {
addDisplayName(id.name, node);
}
}

@@ -168,0 +108,0 @@

{
"name": "@babel/plugin-transform-react-display-name",
"version": "7.15.0",
"version": "7.15.1",
"description": "Add displayName to React.createClass calls",

@@ -5,0 +5,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc