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.21.4-esm.2 to 7.21.4-esm.3

172

lib/create-plugin.js

@@ -1,6 +0,12 @@

import jsx from "@babel/plugin-syntax-jsx";
import { declare } from "@babel/helper-plugin-utils";
import { template, types as t } from "@babel/core";
import { addNamed, addNamespace, isModule } from "@babel/helper-module-imports";
import annotateAsPure from "@babel/helper-annotate-as-pure";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createPlugin;
var _pluginSyntaxJsx = require("@babel/plugin-syntax-jsx");
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _core = require("@babel/core");
var _helperModuleImports = require("@babel/helper-module-imports");
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
const DEFAULT = {

@@ -19,16 +25,16 @@ importSource: "react",

function hasProto(node) {
return node.properties.some(value => t.isObjectProperty(value, {
return node.properties.some(value => _core.types.isObjectProperty(value, {
computed: false,
shorthand: false
}) && (t.isIdentifier(value.key, {
}) && (_core.types.isIdentifier(value.key, {
name: "__proto__"
}) || t.isStringLiteral(value.key, {
}) || _core.types.isStringLiteral(value.key, {
value: "__proto__"
})));
}
export default function createPlugin({
function createPlugin({
name,
development
}) {
return declare((_, options) => {
return (0, _helperPluginUtils.declare)((_, options) => {
const {

@@ -64,5 +70,5 @@ pure: PURE_ANNOTATION,

if (isThisAllowed(path.scope)) {
attributes.push(t.jsxAttribute(t.jsxIdentifier("__self"), t.jsxExpressionContainer(t.thisExpression())));
attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier("__self"), _core.types.jsxExpressionContainer(_core.types.thisExpression())));
}
attributes.push(t.jsxAttribute(t.jsxIdentifier("__source"), t.jsxExpressionContainer(makeSource(path, state))));
attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier("__source"), _core.types.jsxExpressionContainer(makeSource(path, state))));
path.pushContainer("attributes", attributes);

@@ -73,3 +79,3 @@ }

name,
inherits: jsx,
inherits: _pluginSyntaxJsx.default,
visitor: {

@@ -127,4 +133,4 @@ JSXNamespacedName(path) {

const fragment = toMemberExpression(pragmaFrag);
set(state, "id/createElement", () => t.cloneNode(createElement));
set(state, "id/fragment", () => t.cloneNode(fragment));
set(state, "id/createElement", () => _core.types.cloneNode(createElement));
set(state, "id/fragment", () => _core.types.cloneNode(fragment));
set(state, "defaultPure", pragma === DEFAULT.pragma);

@@ -157,3 +163,3 @@ } else if (runtime === "automatic") {

}
path.replaceWith(t.inherits(callExpr, path.node));
path.replaceWith(_core.types.inherits(callExpr, path.node));
}

@@ -169,8 +175,8 @@ },

}
path.replaceWith(t.inherits(callExpr, path.node));
path.replaceWith(_core.types.inherits(callExpr, path.node));
}
},
JSXAttribute(path) {
if (t.isJSXElement(path.node.value)) {
path.node.value = t.jsxExpressionContainer(path.node.value);
if (_core.types.isJSXElement(path.node.value)) {
path.node.value = _core.types.jsxExpressionContainer(path.node.value);
}

@@ -204,4 +210,4 @@ }

function call(pass, name, args) {
const node = t.callExpression(get(pass, `id/${name}`)(), args);
if (PURE_ANNOTATION != null ? PURE_ANNOTATION : get(pass, "defaultPure")) annotateAsPure(node);
const node = _core.types.callExpression(get(pass, `id/${name}`)(), args);
if (PURE_ANNOTATION != null ? PURE_ANNOTATION : get(pass, "defaultPure")) (0, _helperAnnotateAsPure.default)(node);
return node;

@@ -215,5 +221,5 @@ }

const attr = attributes[i];
if (seenPropsSpread && t.isJSXAttribute(attr) && attr.name.name === "key") {
if (seenPropsSpread && _core.types.isJSXAttribute(attr) && attr.name.name === "key") {
return true;
} else if (t.isJSXSpreadAttribute(attr)) {
} else if (_core.types.isJSXSpreadAttribute(attr)) {
seenPropsSpread = true;

@@ -225,15 +231,15 @@ }

function convertJSXIdentifier(node, parent) {
if (t.isJSXIdentifier(node)) {
if (node.name === "this" && t.isReferenced(node, parent)) {
return t.thisExpression();
} else if (t.isValidIdentifier(node.name, false)) {
if (_core.types.isJSXIdentifier(node)) {
if (node.name === "this" && _core.types.isReferenced(node, parent)) {
return _core.types.thisExpression();
} else if (_core.types.isValidIdentifier(node.name, false)) {
node.type = "Identifier";
return node;
} else {
return t.stringLiteral(node.name);
return _core.types.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 (_core.types.isJSXMemberExpression(node)) {
return _core.types.memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node));
} else if (_core.types.isJSXNamespacedName(node)) {
return _core.types.stringLiteral(`${node.namespace.name}:${node.name.name}`);
}

@@ -243,3 +249,3 @@ return node;

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

@@ -251,16 +257,16 @@ } else {

function accumulateAttribute(array, attribute) {
if (t.isJSXSpreadAttribute(attribute.node)) {
if (_core.types.isJSXSpreadAttribute(attribute.node)) {
const arg = attribute.node.argument;
if (t.isObjectExpression(arg) && !hasProto(arg)) {
if (_core.types.isObjectExpression(arg) && !hasProto(arg)) {
array.push(...arg.properties);
} else {
array.push(t.spreadElement(arg));
array.push(_core.types.spreadElement(arg));
}
return array;
}
const value = convertAttributeValue(attribute.node.name.name !== "key" ? attribute.node.value || t.booleanLiteral(true) : attribute.node.value);
const value = convertAttributeValue(attribute.node.name.name !== "key" ? attribute.node.value || _core.types.booleanLiteral(true) : attribute.node.value);
if (attribute.node.name.name === "key" && value === null) {
throw attribute.buildCodeFrameError('Please provide an explicit key value. Using "key" as a shorthand for "key={true}" is not allowed.');
}
if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(attribute.node.value)) {
if (_core.types.isStringLiteral(value) && !_core.types.isJSXExpressionContainer(attribute.node.value)) {
var _value$extra;

@@ -270,10 +276,10 @@ value.value = value.value.replace(/\n\s+/g, " ");

}
if (t.isJSXNamespacedName(attribute.node.name)) {
attribute.node.name = t.stringLiteral(attribute.node.name.namespace.name + ":" + attribute.node.name.name.name);
} else if (t.isValidIdentifier(attribute.node.name.name, false)) {
if (_core.types.isJSXNamespacedName(attribute.node.name)) {
attribute.node.name = _core.types.stringLiteral(attribute.node.name.namespace.name + ":" + attribute.node.name.name.name);
} else if (_core.types.isValidIdentifier(attribute.node.name.name, false)) {
attribute.node.name.type = "Identifier";
} else {
attribute.node.name = t.stringLiteral(attribute.node.name.name);
attribute.node.name = _core.types.stringLiteral(attribute.node.name.name);
}
array.push(t.inherits(t.objectProperty(attribute.node.name, value), attribute.node));
array.push(_core.types.inherits(_core.types.objectProperty(attribute.node.name, value), attribute.node));
return array;

@@ -286,7 +292,7 @@ }

} else if (children.length > 1) {
childrenNode = t.arrayExpression(children);
childrenNode = _core.types.arrayExpression(children);
} else {
return undefined;
}
return t.objectProperty(t.identifier("children"), childrenNode);
return _core.types.objectProperty(_core.types.identifier("children"), childrenNode);
}

@@ -299,3 +305,3 @@ function buildJSXElementCall(path, file) {

for (const attr of openingPath.get("attributes")) {
if (attr.isJSXAttribute() && t.isJSXIdentifier(attr.node.name)) {
if (attr.isJSXAttribute() && _core.types.isJSXIdentifier(attr.node.name)) {
const {

@@ -324,3 +330,3 @@ name

}
const children = t.react.buildChildren(path.node);
const children = _core.types.react.buildChildren(path.node);
let attribs;

@@ -330,3 +336,3 @@ if (attribsArray.length || children.length) {

} else {
attribs = t.objectExpression([]);
attribs = _core.types.objectExpression([]);
}

@@ -336,3 +342,3 @@ args.push(attribs);

var _extracted$key;
args.push((_extracted$key = extracted.key) != null ? _extracted$key : path.scope.buildUndefinedNode(), t.booleanLiteral(children.length > 1));
args.push((_extracted$key = extracted.key) != null ? _extracted$key : path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1));
if (extracted.__source) {

@@ -354,10 +360,10 @@ args.push(extracted.__source);

}
return t.objectExpression(props);
return _core.types.objectExpression(props);
}
function buildJSXFragmentCall(path, file) {
const args = [get(file, "id/fragment")()];
const children = t.react.buildChildren(path.node);
args.push(t.objectExpression(children.length > 0 ? [buildChildrenProperty(children)] : []));
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(), t.booleanLiteral(children.length > 1));
args.push(path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1));
}

@@ -368,7 +374,7 @@ return call(file, children.length > 1 ? "jsxs" : "jsx", args);

if (filter && !filter(path.node, file)) return;
return call(file, "createElement", [get(file, "id/fragment")(), t.nullLiteral(), ...t.react.buildChildren(path.node)]);
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")), ...t.react.buildChildren(path.node)]);
return call(file, "createElement", [getTag(openingPath), buildCreateElementOpeningElementAttributes(file, path, openingPath.get("attributes")), ..._core.types.react.buildChildren(path.node)]);
}

@@ -378,9 +384,9 @@ function getTag(openingPath) {

let tagName;
if (t.isIdentifier(tagExpr)) {
if (_core.types.isIdentifier(tagExpr)) {
tagName = tagExpr.name;
} else if (t.isStringLiteral(tagExpr)) {
} else if (_core.types.isStringLiteral(tagExpr)) {
tagName = tagExpr.value;
}
if (t.react.isCompatTag(tagName)) {
return t.stringLiteral(tagName);
if (_core.types.react.isCompatTag(tagName)) {
return _core.types.stringLiteral(tagName);
} else {

@@ -399,5 +405,5 @@ return tagExpr;

props.forEach((prop, i) => {
if (t.isSpreadElement(prop)) {
if (_core.types.isSpreadElement(prop)) {
if (i > start) {
objs.push(t.objectExpression(props.slice(start, i)));
objs.push(_core.types.objectExpression(props.slice(start, i)));
}

@@ -409,20 +415,20 @@ objs.push(prop.argument);

if (props.length > start) {
objs.push(t.objectExpression(props.slice(start)));
objs.push(_core.types.objectExpression(props.slice(start)));
}
} else if (props.length) {
objs.push(t.objectExpression(props));
objs.push(_core.types.objectExpression(props));
}
if (!objs.length) {
return t.nullLiteral();
return _core.types.nullLiteral();
}
if (objs.length === 1) {
if (!(t.isSpreadElement(props[0]) && t.isObjectExpression(props[0].argument))) {
if (!(_core.types.isSpreadElement(props[0]) && _core.types.isObjectExpression(props[0].argument))) {
return objs[0];
}
}
if (!t.isObjectExpression(objs[0])) {
objs.unshift(t.objectExpression([]));
if (!_core.types.isObjectExpression(objs[0])) {
objs.unshift(_core.types.objectExpression([]));
}
const helper = useBuiltIns ? t.memberExpression(t.identifier("Object"), t.identifier("assign")) : file.addHelper("extends");
return t.callExpression(helper, objs);
const helper = useBuiltIns ? _core.types.memberExpression(_core.types.identifier("Object"), _core.types.identifier("assign")) : file.addHelper("extends");
return _core.types.callExpression(helper, objs);
}

@@ -433,3 +439,3 @@ }

for (const attr of attribs) {
const name = t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name;
const name = _core.types.isJSXAttribute(attr) && _core.types.isJSXIdentifier(attr.name) && attr.name.name;
if (runtime === "automatic" && (name === "__source" || name === "__self")) {

@@ -441,3 +447,3 @@ if (found[name]) throw sourceSelfError(path, name);

}
return props.length === 1 && t.isSpreadElement(props[0]) && !t.isObjectExpression(props[0].argument) ? props[0].argument : props.length > 0 ? t.objectExpression(props) : t.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();
}

@@ -461,6 +467,6 @@ });

const actualSource = getSource(source, importName);
if (isModule(path)) {
if ((0, _helperModuleImports.isModule)(path)) {
let reference = get(pass, `imports/${importName}`);
if (reference) return t.cloneNode(reference);
reference = addNamed(path, importName, actualSource, {
if (reference) return _core.types.cloneNode(reference);
reference = (0, _helperModuleImports.addNamed)(path, importName, actualSource, {
importedInterop: "uncompiled",

@@ -474,5 +480,5 @@ importPosition: "after"

if (reference) {
reference = t.cloneNode(reference);
reference = _core.types.cloneNode(reference);
} else {
reference = addNamespace(path, actualSource, {
reference = (0, _helperModuleImports.addNamespace)(path, actualSource, {
importedInterop: "uncompiled"

@@ -482,3 +488,3 @@ });

}
return t.memberExpression(reference, t.identifier(importName));
return _core.types.memberExpression(reference, _core.types.identifier(importName));
}

@@ -489,3 +495,3 @@ };

function toMemberExpression(id) {
return id.split(".").map(name => t.identifier(name)).reduce((object, property) => t.memberExpression(object, property));
return id.split(".").map(name => _core.types.identifier(name)).reduce((object, property) => _core.types.memberExpression(object, property));
}

@@ -504,12 +510,12 @@ function makeSource(path, state) {

id: fileNameIdentifier,
init: t.stringLiteral(filename)
init: _core.types.stringLiteral(filename)
});
state.fileNameIdentifier = fileNameIdentifier;
}
return makeTrace(t.cloneNode(state.fileNameIdentifier), location.start.line, location.start.column);
return makeTrace(_core.types.cloneNode(state.fileNameIdentifier), location.start.line, location.start.column);
}
function makeTrace(fileNameIdentifier, lineNumber, column0Based) {
const fileLineLiteral = lineNumber != null ? t.numericLiteral(lineNumber) : t.nullLiteral();
const fileColumnLiteral = column0Based != null ? t.numericLiteral(column0Based + 1) : t.nullLiteral();
return template.expression.ast`{
const fileLineLiteral = lineNumber != null ? _core.types.numericLiteral(lineNumber) : _core.types.nullLiteral();
const fileColumnLiteral = column0Based != null ? _core.types.numericLiteral(column0Based + 1) : _core.types.nullLiteral();
return _core.template.expression.ast`{
fileName: ${fileNameIdentifier},

@@ -516,0 +522,0 @@ lineNumber: ${fileLineLiteral},

@@ -1,7 +0,14 @@

import createPlugin from "./create-plugin.js";
export default createPlugin({
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _createPlugin = require("./create-plugin");
var _default = (0, _createPlugin.default)({
name: "transform-react-jsx/development",
development: true
});
exports.default = _default;
//# sourceMappingURL=development.js.map

@@ -1,7 +0,14 @@

import createPlugin from "./create-plugin.js";
export default createPlugin({
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _createPlugin = require("./create-plugin");
var _default = (0, _createPlugin.default)({
name: "transform-react-jsx",
development: false
});
exports.default = _default;
//# sourceMappingURL=index.js.map
{
"name": "@babel/plugin-transform-react-jsx",
"version": "7.21.4-esm.2",
"version": "7.21.4-esm.3",
"description": "Turn JSX into React function calls",

@@ -20,7 +20,7 @@ "repository": {

"dependencies": {
"@babel/helper-annotate-as-pure": "7.21.4-esm.2",
"@babel/helper-module-imports": "7.21.4-esm.2",
"@babel/helper-plugin-utils": "7.21.4-esm.2",
"@babel/plugin-syntax-jsx": "7.21.4-esm.2",
"@babel/types": "7.21.4-esm.2"
"@babel/helper-annotate-as-pure": "7.21.4-esm.3",
"@babel/helper-module-imports": "7.21.4-esm.3",
"@babel/helper-plugin-utils": "7.21.4-esm.3",
"@babel/plugin-syntax-jsx": "7.21.4-esm.3",
"@babel/types": "7.21.4-esm.3"
},

@@ -31,5 +31,5 @@ "peerDependencies": {

"devDependencies": {
"@babel/core": "7.21.4-esm.2",
"@babel/helper-plugin-test-runner": "7.21.4-esm.2",
"@babel/traverse": "7.21.4-esm.2"
"@babel/core": "7.21.4-esm.3",
"@babel/helper-plugin-test-runner": "7.21.4-esm.3",
"@babel/traverse": "7.21.4-esm.3"
},

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

Sorry, the diff of this file is not supported yet

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