@babel/helper-builder-react-jsx
Advanced tools
Comparing version 7.3.0 to 7.7.0
116
lib/index.js
@@ -8,24 +8,10 @@ "use strict"; | ||
function _esutils() { | ||
const data = _interopRequireDefault(require("esutils")); | ||
var _esutils = _interopRequireDefault(require("esutils")); | ||
_esutils = function () { | ||
return data; | ||
}; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
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; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -52,3 +38,3 @@ | ||
if (callExpr) { | ||
path.replaceWith(t().inherits(callExpr, path.node)); | ||
path.replaceWith(t.inherits(callExpr, path.node)); | ||
} | ||
@@ -67,3 +53,3 @@ } | ||
if (callExpr) { | ||
path.replaceWith(t().inherits(callExpr, path.node)); | ||
path.replaceWith(t.inherits(callExpr, path.node)); | ||
} | ||
@@ -76,14 +62,14 @@ } | ||
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}`); | ||
} | ||
@@ -95,3 +81,3 @@ | ||
function convertAttributeValue(node) { | ||
if (t().isJSXExpressionContainer(node)) { | ||
if (t.isJSXExpressionContainer(node)) { | ||
return node.expression; | ||
@@ -104,21 +90,24 @@ } else { | ||
function convertAttribute(node) { | ||
const 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.isJSXSpreadAttribute(node)) { | ||
return t.spreadElement(node.argument); | ||
} | ||
if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(node.value)) { | ||
var _value$extra; | ||
value.value = value.value.replace(/\n\s+/g, " "); | ||
if (value.extra && value.extra.raw) { | ||
delete value.extra.raw; | ||
} | ||
(_value$extra = value.extra) === null || _value$extra === void 0 ? void 0 : delete _value$extra.raw; | ||
} | ||
if (t().isJSXNamespacedName(node.name)) { | ||
node.name = t().stringLiteral(node.name.namespace.name + ":" + node.name.name.name); | ||
} else if (_esutils().default.keyword.isIdentifierNameES6(node.name.name)) { | ||
if (t.isJSXNamespacedName(node.name)) { | ||
node.name = t.stringLiteral(node.name.namespace.name + ":" + node.name.name.name); | ||
} else if (_esutils.default.keyword.isIdentifierNameES6(node.name.name)) { | ||
node.name.type = "Identifier"; | ||
} else { | ||
node.name = t().stringLiteral(node.name.name); | ||
node.name = t.stringLiteral(node.name.name); | ||
} | ||
return t().inherits(t().objectProperty(node.name, value), node); | ||
return t.inherits(t.objectProperty(node.name, value), node); | ||
} | ||
@@ -129,3 +118,3 @@ | ||
const openingPath = path.get("openingElement"); | ||
openingPath.parent.children = t().react.buildChildren(openingPath.parent); | ||
openingPath.parent.children = t.react.buildChildren(openingPath.parent); | ||
const tagExpr = convertJSXIdentifier(openingPath.node.name, openingPath.node); | ||
@@ -135,5 +124,5 @@ const args = []; | ||
if (t().isIdentifier(tagExpr)) { | ||
if (t.isIdentifier(tagExpr)) { | ||
tagName = tagExpr.name; | ||
} else if (t().isLiteral(tagExpr)) { | ||
} else if (t.isLiteral(tagExpr)) { | ||
tagName = tagExpr.value; | ||
@@ -157,3 +146,3 @@ } | ||
} else { | ||
attribs = t().nullLiteral(); | ||
attribs = t.nullLiteral(); | ||
} | ||
@@ -167,3 +156,3 @@ | ||
return state.call || t().callExpression(state.callee, args); | ||
return state.call || t.callExpression(state.callee, args); | ||
} | ||
@@ -173,3 +162,3 @@ | ||
if (!_props.length) return _props; | ||
objs.push(t().objectExpression(_props)); | ||
objs.push(t.objectExpression(_props)); | ||
return []; | ||
@@ -181,2 +170,10 @@ } | ||
const objs = []; | ||
const { | ||
useSpread = false | ||
} = file.opts; | ||
if (typeof useSpread !== "boolean") { | ||
throw new Error("transform-react-jsx currently only accepts a boolean option for " + "useSpread (defaults to false)"); | ||
} | ||
const useBuiltIns = file.opts.useBuiltIns || false; | ||
@@ -188,6 +185,15 @@ | ||
if (useSpread && useBuiltIns) { | ||
throw new Error("transform-react-jsx currently only accepts useBuiltIns or useSpread " + "but not both"); | ||
} | ||
if (useSpread) { | ||
const props = attribs.map(convertAttribute); | ||
return t.objectExpression(props); | ||
} | ||
while (attribs.length) { | ||
const prop = attribs.shift(); | ||
if (t().isJSXSpreadAttribute(prop)) { | ||
if (t.isJSXSpreadAttribute(prop)) { | ||
_props = pushProps(_props, objs); | ||
@@ -205,8 +211,8 @@ objs.push(prop.argument); | ||
} else { | ||
if (!t().isObjectExpression(objs[0])) { | ||
objs.unshift(t().objectExpression([])); | ||
if (!t.isObjectExpression(objs[0])) { | ||
objs.unshift(t.objectExpression([])); | ||
} | ||
const 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); | ||
} | ||
@@ -220,3 +226,3 @@ | ||
const openingPath = path.get("openingElement"); | ||
openingPath.parent.children = t().react.buildChildren(openingPath.parent); | ||
openingPath.parent.children = t.react.buildChildren(openingPath.parent); | ||
const args = []; | ||
@@ -235,3 +241,3 @@ const tagName = null; | ||
args.push(t().nullLiteral(), ...path.node.children); | ||
args.push(t.nullLiteral(), ...path.node.children); | ||
@@ -243,4 +249,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.3.0", | ||
"version": "7.7.0", | ||
"description": "Helper function to build react jsx", | ||
@@ -12,5 +12,6 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx", | ||
"dependencies": { | ||
"@babel/types": "^7.3.0", | ||
"@babel/types": "^7.7.0", | ||
"esutils": "^2.0.0" | ||
} | ||
}, | ||
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea" | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9209
185
0
Updated@babel/types@^7.7.0