@babel/helper-builder-react-jsx
Advanced tools
Comparing version 8.0.0-alpha.2 to 8.0.0-alpha.3
@@ -1,4 +0,2 @@ | ||
import * as _t from '@babel/types'; | ||
import annotateAsPure from '@babel/helper-annotate-as-pure'; | ||
import * as _t from "@babel/types"; | ||
const { | ||
@@ -28,3 +26,4 @@ booleanLiteral, | ||
} = _t; | ||
function index (opts) { | ||
import annotateAsPure from "@babel/helper-annotate-as-pure"; | ||
export default function (opts) { | ||
const visitor = {}; | ||
@@ -140,2 +139,49 @@ visitor.JSXNamespacedName = function (path) { | ||
} | ||
function pushProps(_props, objs) { | ||
if (!_props.length) return _props; | ||
objs.push(objectExpression(_props)); | ||
return []; | ||
} | ||
function buildOpeningElementAttributes(attribs, pass) { | ||
let _props = []; | ||
const objs = []; | ||
const { | ||
useSpread = false | ||
} = 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) { | ||
const props = attribs.map(convertAttribute); | ||
return objectExpression(props); | ||
} | ||
while (attribs.length) { | ||
const prop = attribs.shift(); | ||
if (isJSXSpreadAttribute(prop)) { | ||
_props = pushProps(_props, objs); | ||
objs.push(prop.argument); | ||
} else { | ||
_props.push(convertAttribute(prop)); | ||
} | ||
} | ||
pushProps(_props, objs); | ||
let convertedAttribs; | ||
if (objs.length === 1) { | ||
convertedAttribs = objs[0]; | ||
} else { | ||
if (!isObjectExpression(objs[0])) { | ||
objs.unshift(objectExpression([])); | ||
} | ||
const helper = useBuiltIns ? memberExpression(identifier("Object"), identifier("assign")) : pass.addHelper("extends"); | ||
convertedAttribs = callExpression(helper, objs); | ||
} | ||
return convertedAttribs; | ||
} | ||
function buildFragmentCall(path, pass) { | ||
@@ -167,3 +213,2 @@ if (opts.filter && !opts.filter(path.node, pass)) return; | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/helper-builder-react-jsx", | ||
"version": "8.0.0-alpha.2", | ||
"version": "8.0.0-alpha.3", | ||
"description": "Helper function to build react jsx", | ||
@@ -17,8 +17,8 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.2", | ||
"@babel/types": "^8.0.0-alpha.2" | ||
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.3", | ||
"@babel/types": "^8.0.0-alpha.3" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^8.0.0-alpha.2", | ||
"@babel/traverse": "^8.0.0-alpha.2" | ||
"@babel/core": "^8.0.0-alpha.3", | ||
"@babel/traverse": "^8.0.0-alpha.3" | ||
}, | ||
@@ -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
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
27559
210