@babel/helper-builder-react-jsx
Advanced tools
Comparing version 7.19.0 to 7.21.4-esm
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = _default; | ||
var _t = require("@babel/types"); | ||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure"); | ||
const { | ||
@@ -37,6 +34,4 @@ booleanLiteral, | ||
} = _t; | ||
function _default(opts) { | ||
const visitor = {}; | ||
visitor.JSXNamespacedName = function (path) { | ||
@@ -48,11 +43,8 @@ if (opts.throwIfNamespace) { | ||
}; | ||
visitor.JSXSpreadChild = function (path) { | ||
throw path.buildCodeFrameError("Spread children are not supported in React."); | ||
}; | ||
visitor.JSXElement = { | ||
exit(path, state) { | ||
const callExpr = buildElementCall(path, state); | ||
if (callExpr) { | ||
@@ -62,3 +54,2 @@ path.replaceWith(inherits(callExpr, path.node)); | ||
} | ||
}; | ||
@@ -70,5 +61,3 @@ visitor.JSXFragment = { | ||
} | ||
const callExpr = buildFragmentCall(path, state); | ||
if (callExpr) { | ||
@@ -78,6 +67,4 @@ path.replaceWith(inherits(callExpr, path.node)); | ||
} | ||
}; | ||
return visitor; | ||
function convertJSXIdentifier(node, parent) { | ||
@@ -98,6 +85,4 @@ if (isJSXIdentifier(node)) { | ||
} | ||
return node; | ||
} | ||
function convertAttributeValue(node) { | ||
@@ -110,3 +95,2 @@ if (isJSXExpressionContainer(node)) { | ||
} | ||
function convertAttribute(node) { | ||
@@ -116,12 +100,8 @@ if (isJSXSpreadAttribute(node)) { | ||
} | ||
const value = convertAttributeValue(node.value || booleanLiteral(true)); | ||
if (isStringLiteral(value) && !isJSXExpressionContainer(node.value)) { | ||
var _value$extra; | ||
value.value = value.value.replace(/\n\s+/g, " "); | ||
(_value$extra = value.extra) == null ? true : delete _value$extra.raw; | ||
} | ||
if (isJSXNamespacedName(node.name)) { | ||
@@ -134,6 +114,4 @@ node.name = stringLiteral(node.name.namespace.name + ":" + node.name.name.name); | ||
} | ||
return inherits(objectProperty(node.name, value), node); | ||
} | ||
function buildElementCall(path, pass) { | ||
@@ -146,3 +124,2 @@ if (opts.filter && !opts.filter(path.node, pass)) return; | ||
let tagName; | ||
if (isIdentifier(tagExpr)) { | ||
@@ -153,3 +130,2 @@ tagName = tagExpr.name; | ||
} | ||
const state = { | ||
@@ -161,10 +137,7 @@ tagExpr: tagExpr, | ||
}; | ||
if (opts.pre) { | ||
opts.pre(state, pass); | ||
} | ||
const attribs = openingPath.node.attributes; | ||
let convertedAttributes; | ||
if (attribs.length) { | ||
@@ -177,9 +150,6 @@ { | ||
} | ||
args.push(convertedAttributes, ...path.node.children); | ||
if (opts.post) { | ||
opts.post(state, pass); | ||
} | ||
const call = state.call || callExpression(state.callee, args); | ||
@@ -189,3 +159,2 @@ if (state.pure) (0, _helperAnnotateAsPure.default)(call); | ||
} | ||
function pushProps(_props, objs) { | ||
@@ -196,3 +165,2 @@ if (!_props.length) return _props; | ||
} | ||
function buildOpeningElementAttributes(attribs, pass) { | ||
@@ -204,17 +172,12 @@ let _props = []; | ||
} = pass.opts; | ||
if (typeof useSpread !== "boolean") { | ||
throw new Error("transform-react-jsx currently only accepts a boolean option for " + "useSpread (defaults to false)"); | ||
} | ||
const useBuiltIns = pass.opts.useBuiltIns || false; | ||
if (typeof useBuiltIns !== "boolean") { | ||
throw new Error("transform-react-jsx currently only accepts a boolean option for " + "useBuiltIns (defaults to false)"); | ||
} | ||
if (useSpread && useBuiltIns) { | ||
throw new Error("transform-react-jsx currently only accepts useBuiltIns or useSpread " + "but not both"); | ||
} | ||
if (useSpread) { | ||
@@ -224,6 +187,4 @@ const props = attribs.map(convertAttribute); | ||
} | ||
while (attribs.length) { | ||
const prop = attribs.shift(); | ||
if (isJSXSpreadAttribute(prop)) { | ||
@@ -236,6 +197,4 @@ _props = pushProps(_props, objs); | ||
} | ||
pushProps(_props, objs); | ||
let convertedAttribs; | ||
if (objs.length === 1) { | ||
@@ -247,10 +206,7 @@ convertedAttribs = objs[0]; | ||
} | ||
const helper = useBuiltIns ? memberExpression(identifier("Object"), identifier("assign")) : pass.addHelper("extends"); | ||
convertedAttribs = callExpression(helper, objs); | ||
} | ||
return convertedAttribs; | ||
} | ||
function buildFragmentCall(path, pass) { | ||
@@ -268,13 +224,9 @@ if (opts.filter && !opts.filter(path.node, pass)) return; | ||
}; | ||
if (opts.pre) { | ||
opts.pre(state, pass); | ||
} | ||
args.push(nullLiteral(), ...path.node.children); | ||
if (opts.post) { | ||
opts.post(state, pass); | ||
} | ||
pass.set("usedFragment", true); | ||
@@ -281,0 +233,0 @@ const call = state.call || callExpression(state.callee, args); |
{ | ||
"name": "@babel/helper-builder-react-jsx", | ||
"version": "7.19.0", | ||
"version": "7.21.4-esm", | ||
"description": "Helper function to build react jsx", | ||
@@ -17,8 +17,8 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "^7.18.6", | ||
"@babel/types": "^7.19.0" | ||
"@babel/helper-annotate-as-pure": "^7.21.4-esm", | ||
"@babel/types": "^7.21.4-esm" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.19.0", | ||
"@babel/traverse": "^7.19.0" | ||
"@babel/core": "^7.21.4-esm", | ||
"@babel/traverse": "^7.21.4-esm" | ||
}, | ||
@@ -25,0 +25,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27693
6
1