Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-react-jsx

Package Overview
Dependencies
Maintainers
4
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-react-jsx - npm Package Compare versions

Comparing version 7.20.7 to 7.20.13

75

lib/create-plugin.js

@@ -42,2 +42,3 @@ "use strict";

throwIfNamespace = true,
filter,
runtime: RUNTIME_DEFAULT = development ? "automatic" : "classic",

@@ -150,9 +151,13 @@ importSource: IMPORT_SOURCE_DEFAULT = DEFAULT.importSource,

}
},
JSXFragment(path, file) {
const frag = memberExpressionToJSX(get(file, "id/fragment")());
path.replaceWith(_core.types.inherits(_core.types.jsxElement(_core.types.inherits(_core.types.jsxOpeningElement(frag, []), path.node.openingFragment), _core.types.jsxClosingElement(_core.types.cloneNode(frag)), path.node.children), path.node));
JSXFragment: {
exit(path, file) {
let callExpr;
if (get(file, "runtime") === "classic") {
callExpr = buildCreateElementFragmentCall(path, file);
} else {
callExpr = buildJSXFragmentCall(path, file);
}
path.replaceWith(_core.types.inherits(callExpr, path.node));
}
},

@@ -177,7 +182,5 @@ JSXElement: {

};
function isDerivedClass(classPath) {
return classPath.node.superClass !== null;
}
function isThisAllowed(scope) {

@@ -208,3 +211,2 @@ do {

}
function shouldUseCreateElement(path) {

@@ -239,3 +241,2 @@ const openingPath = path.get("openingElement");

}
return node;

@@ -267,3 +268,2 @@ }

value.value = value.value.replace(/\n\s+/g, " ");
(_value$extra = value.extra) == null ? true : delete _value$extra.raw;

@@ -278,4 +278,3 @@ }

}
array.push(_core.types.inherits(_core.types.objectProperty(
attribute.node.name, value), attribute.node));
array.push(_core.types.inherits(_core.types.objectProperty(attribute.node.name, value), attribute.node));
return array;

@@ -294,3 +293,2 @@ }

}
function buildJSXElementCall(path, file) {

@@ -301,3 +299,2 @@ const openingPath = path.get("openingElement");

const extracted = Object.create(null);
for (const attr of openingPath.get("attributes")) {

@@ -331,4 +328,3 @@ if (attr.isJSXAttribute() && _core.types.isJSXIdentifier(attr.node.name)) {

if (attribsArray.length || children.length) {
attribs = buildJSXOpeningElementAttributes(attribsArray,
children);
attribs = buildJSXOpeningElementAttributes(attribsArray, children);
} else {

@@ -352,6 +348,4 @@ attribs = _core.types.objectExpression([]);

}
function buildJSXOpeningElementAttributes(attribs, children) {
const props = attribs.reduce(accumulateAttribute, []);
if ((children == null ? void 0 : children.length) > 0) {

@@ -362,7 +356,18 @@ props.push(buildChildrenProperty(children));

}
function buildJSXFragmentCall(path, file) {
const args = [get(file, "id/fragment")()];
const children = _core.types.react.buildChildren(path.node);
args.push(_core.types.objectExpression(children.length > 0 ? [buildChildrenProperty(children)] : []));
if (development) {
args.push(path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1));
}
return call(file, children.length > 1 ? "jsxs" : "jsx", args);
}
function buildCreateElementFragmentCall(path, file) {
if (filter && !filter(path.node, file)) return;
return call(file, "createElement", [get(file, "id/fragment")(), _core.types.nullLiteral(), ..._core.types.react.buildChildren(path.node)]);
}
function buildCreateElementCall(path, file) {
const openingPath = path.get("openingElement");
return call(file, "createElement", [getTag(openingPath), buildCreateElementOpeningElementAttributes(file, path, openingPath.get("attributes")),
..._core.types.react.buildChildren(path.node)]);
return call(file, "createElement", [getTag(openingPath), buildCreateElementOpeningElementAttributes(file, path, openingPath.get("attributes")), ..._core.types.react.buildChildren(path.node)]);
}

@@ -383,3 +388,2 @@ function getTag(openingPath) {

}
function buildCreateElementOpeningElementAttributes(file, path, attribs) {

@@ -412,8 +416,6 @@ const runtime = get(file, "runtime");

if (objs.length === 1) {
if (!(_core.types.isSpreadElement(props[0]) &&
_core.types.isObjectExpression(props[0].argument))) {
if (!(_core.types.isSpreadElement(props[0]) && _core.types.isObjectExpression(props[0].argument))) {
return objs[0];
}
}
if (!_core.types.isObjectExpression(objs[0])) {

@@ -423,3 +425,2 @@ objs.unshift(_core.types.objectExpression([]));

const helper = useBuiltIns ? _core.types.memberExpression(_core.types.identifier("Object"), _core.types.identifier("assign")) : file.addHelper("extends");
return _core.types.callExpression(helper, objs);

@@ -438,4 +439,3 @@ }

}
return props.length === 1 && _core.types.isSpreadElement(props[0]) &&
!_core.types.isObjectExpression(props[0].argument) ? props[0].argument : props.length > 0 ? _core.types.objectExpression(props) : _core.types.nullLiteral();
return props.length === 1 && _core.types.isSpreadElement(props[0]) && !_core.types.isObjectExpression(props[0].argument) ? props[0].argument : props.length > 0 ? _core.types.objectExpression(props) : _core.types.nullLiteral();
}

@@ -484,15 +484,4 @@ });

function toMemberExpression(id) {
return id.split(".").map(name => _core.types.identifier(name))
.reduce((object, property) => _core.types.memberExpression(object, property));
return id.split(".").map(name => _core.types.identifier(name)).reduce((object, property) => _core.types.memberExpression(object, property));
}
function memberExpressionToJSX(expr) {
switch (expr.type) {
case "Identifier":
return _core.types.jsxIdentifier(expr.name);
case "MemberExpression":
return _core.types.jsxMemberExpression(memberExpressionToJSX(expr.object), memberExpressionToJSX(expr.property));
default:
throw new Error("Internal error: unknown member expression type");
}
}
function makeSource(path, state) {

@@ -503,3 +492,2 @@ const location = path.node.loc;

}
if (!state.fileNameIdentifier) {

@@ -516,4 +504,3 @@ const {

}
return makeTrace(_core.types.cloneNode(
state.fileNameIdentifier), location.start.line, location.start.column);
return makeTrace(_core.types.cloneNode(state.fileNameIdentifier), location.start.line, location.start.column);
}

@@ -520,0 +507,0 @@ function makeTrace(fileNameIdentifier, lineNumber, column0Based) {

{
"name": "@babel/plugin-transform-react-jsx",
"version": "7.20.7",
"version": "7.20.13",
"description": "Turn JSX into React function calls",

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

"devDependencies": {
"@babel/core": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/helper-plugin-test-runner": "^7.18.6",
"@babel/traverse": "^7.20.7"
"@babel/traverse": "^7.20.13"
},

@@ -35,0 +35,0 @@ "engines": {

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