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

@babel/helper-builder-react-jsx

Package Overview
Dependencies
Maintainers
6
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-builder-react-jsx - npm Package Compare versions

Comparing version 7.0.0-beta.42 to 7.0.0-beta.43

133

lib/index.js
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _esutils = _interopRequireDefault(require("esutils"));
function _esutils() {
const data = _interopRequireDefault(require("esutils"));
var t = _interopRequireWildcard(require("@babel/types"));
_esutils = function () {
return data;
};
return data;
}
function t() {
const data = _interopRequireWildcard(require("@babel/types"));
t = function () {
return data;
};
return data;
}
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

@@ -15,7 +33,8 @@

function _default(opts) {
var visitor = {};
const visitor = {};
visitor.JSXNamespacedName = function (path) {
if (opts.throwIfNamespace) {
throw path.buildCodeFrameError("Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can turn on the 'throwIfNamespace' flag to bypass this warning.");
throw path.buildCodeFrameError(`Namespace tags are not supported by default. React's JSX doesn't support namespace tags. \
You can turn on the 'throwIfNamespace' flag to bypass this warning.`);
}

@@ -25,12 +44,13 @@ };

visitor.JSXElement = {
exit: function exit(path, file) {
var callExpr = buildElementCall(path, file);
exit(path, file) {
const callExpr = buildElementCall(path, file);
if (callExpr) {
path.replaceWith(t.inherits(callExpr, path.node));
path.replaceWith(t().inherits(callExpr, path.node));
}
}
};
visitor.JSXFragment = {
exit: function exit(path, file) {
exit(path, file) {
if (opts.compat) {

@@ -40,8 +60,9 @@ throw path.buildCodeFrameError("Fragment tags are only supported in React 16 and up.");

var callExpr = buildFragmentCall(path, file);
const callExpr = buildFragmentCall(path, file);
if (callExpr) {
path.replaceWith(t.inherits(callExpr, path.node));
path.replaceWith(t().inherits(callExpr, path.node));
}
}
};

@@ -51,14 +72,14 @@ return visitor;

function convertJSXIdentifier(node, parent) {
if (t.isJSXIdentifier(node)) {
if (node.name === "this" && t.isReferenced(node, parent)) {
return t.thisExpression();
} else if (_esutils.default.keyword.isIdentifierNameES6(node.name)) {
if (t().isJSXIdentifier(node)) {
if (node.name === "this" && t().isReferenced(node, parent)) {
return t().thisExpression();
} else if (_esutils().default.keyword.isIdentifierNameES6(node.name)) {
node.type = "Identifier";
} else {
return t.stringLiteral(node.name);
return t().stringLiteral(node.name);
}
} else if (t.isJSXMemberExpression(node)) {
return t.memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node));
} else if (t.isJSXNamespacedName(node)) {
return t.stringLiteral(node.namespace.name + ":" + node.name.name);
} else if (t().isJSXMemberExpression(node)) {
return t().memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node));
} else if (t().isJSXNamespacedName(node)) {
return t().stringLiteral(`${node.namespace.name}:${node.name.name}`);
}

@@ -70,3 +91,3 @@

function convertAttributeValue(node) {
if (t.isJSXExpressionContainer(node)) {
if (t().isJSXExpressionContainer(node)) {
return node.expression;

@@ -79,5 +100,5 @@ } else {

function convertAttribute(node) {
var value = convertAttributeValue(node.value || t.booleanLiteral(true));
const value = convertAttributeValue(node.value || t().booleanLiteral(true));
if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(node.value)) {
if (t().isStringLiteral(value) && !t().isJSXExpressionContainer(node.value)) {
value.value = value.value.replace(/\n\s+/g, " ");

@@ -90,9 +111,9 @@

if (t.isValidIdentifier(node.name.name)) {
if (t().isValidIdentifier(node.name.name)) {
node.name.type = "Identifier";
} else {
node.name = t.stringLiteral(t.isJSXNamespacedName(node.name) ? node.name.namespace.name + ":" + node.name.name.name : node.name.name);
node.name = t().stringLiteral(t().isJSXNamespacedName(node.name) ? node.name.namespace.name + ":" + node.name.name.name : node.name.name);
}
return t.inherits(t.objectProperty(node.name, value), node);
return t().inherits(t().objectProperty(node.name, value), node);
}

@@ -102,15 +123,15 @@

if (opts.filter && !opts.filter(path.node, file)) return;
var openingPath = path.get("openingElement");
openingPath.parent.children = t.react.buildChildren(openingPath.parent);
var tagExpr = convertJSXIdentifier(openingPath.node.name, openingPath.node);
var args = [];
var tagName;
const openingPath = path.get("openingElement");
openingPath.parent.children = t().react.buildChildren(openingPath.parent);
const tagExpr = convertJSXIdentifier(openingPath.node.name, openingPath.node);
const args = [];
let tagName;
if (t.isIdentifier(tagExpr)) {
if (t().isIdentifier(tagExpr)) {
tagName = tagExpr.name;
} else if (t.isLiteral(tagExpr)) {
} else if (t().isLiteral(tagExpr)) {
tagName = tagExpr.value;
}
var state = {
const state = {
tagExpr: tagExpr,

@@ -125,3 +146,3 @@ tagName: tagName,

var attribs = openingPath.node.attributes;
let attribs = openingPath.node.attributes;

@@ -131,6 +152,6 @@ if (attribs.length) {

} else {
attribs = t.nullLiteral();
attribs = t().nullLiteral();
}
args.push.apply(args, [attribs].concat(path.node.children));
args.push(attribs, ...path.node.children);

@@ -141,3 +162,3 @@ if (opts.post) {

return state.call || t.callExpression(state.callee, args);
return state.call || t().callExpression(state.callee, args);
}

@@ -147,3 +168,3 @@

if (!_props.length) return _props;
objs.push(t.objectExpression(_props));
objs.push(t().objectExpression(_props));
return [];

@@ -153,5 +174,5 @@ }

function buildOpeningElementAttributes(attribs, file) {
var _props = [];
var objs = [];
var useBuiltIns = file.opts.useBuiltIns || false;
let _props = [];
const objs = [];
const useBuiltIns = file.opts.useBuiltIns || false;

@@ -163,5 +184,5 @@ if (typeof useBuiltIns !== "boolean") {

while (attribs.length) {
var prop = attribs.shift();
const prop = attribs.shift();
if (t.isJSXSpreadAttribute(prop)) {
if (t().isJSXSpreadAttribute(prop)) {
_props = pushProps(_props, objs);

@@ -179,8 +200,8 @@ objs.push(prop.argument);

} else {
if (!t.isObjectExpression(objs[0])) {
objs.unshift(t.objectExpression([]));
if (!t().isObjectExpression(objs[0])) {
objs.unshift(t().objectExpression([]));
}
var helper = useBuiltIns ? t.memberExpression(t.identifier("Object"), t.identifier("assign")) : file.addHelper("extends");
attribs = t.callExpression(helper, objs);
const helper = useBuiltIns ? t().memberExpression(t().identifier("Object"), t().identifier("assign")) : file.addHelper("extends");
attribs = t().callExpression(helper, objs);
}

@@ -193,8 +214,8 @@

if (opts.filter && !opts.filter(path.node, file)) return;
var openingPath = path.get("openingElement");
openingPath.parent.children = t.react.buildChildren(openingPath.parent);
var args = [];
var tagName = null;
var tagExpr = file.get("jsxFragIdentifier")();
var state = {
const openingPath = path.get("openingElement");
openingPath.parent.children = t().react.buildChildren(openingPath.parent);
const args = [];
const tagName = null;
const tagExpr = file.get("jsxFragIdentifier")();
const state = {
tagExpr: tagExpr,

@@ -209,3 +230,3 @@ tagName: tagName,

args.push.apply(args, [t.nullLiteral()].concat(path.node.children));
args.push(t().nullLiteral(), ...path.node.children);

@@ -217,4 +238,4 @@ if (opts.post) {

file.set("usedFragment", true);
return state.call || t.callExpression(state.callee, args);
return state.call || t().callExpression(state.callee, args);
}
}
{
"name": "@babel/helper-builder-react-jsx",
"version": "7.0.0-beta.42",
"version": "7.0.0-beta.43",
"description": "Helper function to build react jsx",

@@ -9,5 +9,5 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx",

"dependencies": {
"@babel/types": "7.0.0-beta.42",
"@babel/types": "7.0.0-beta.43",
"esutils": "^2.0.0"
}
}
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