Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return objectExpression.properties.map(node => {
const { key, value, argument } = node;
if (t.isSpreadProperty(node) || t.isSpreadElement(node)) {
return t.JSXSpreadAttribute(argument);
} else if (t.isProperty(node) && node.computed && !t.isStringLiteral(key)) {
// to handle h(Abc, { [kek]: 0, ["norm"]: 1 }) to
return t.JSXSpreadAttribute(t.objectExpression([node]));
} else {
return bJsxAttr(key, value);
}
});
};
return node.elements.map(element => {
if (isHyperscriptCall(element)) {
return transformHyperscriptToJsx(element, false);
}
if (t.isStringLiteral(element)) {
return t.JSXText(element.value);
}
if (t.isExpression(element)) {
return t.JSXExpressionContainer(element);
}
});
};
const singleArgumentCase = firstArgument => {
const isElement = t.isStringLiteral(firstArgument);
const isReactComponent = t.isIdentifier(firstArgument);
const isMemberExpression = t.isMemberExpression(firstArgument);
let attributes = [];
if (isElement) {
const { id, className, tag } = getTagAndClassNamesAndId(
firstArgument.value
);
className &&
attributes.push(
bJsxAttr(t.JSXIdentifier("className"), processClassName(className))
);
id && attributes.push(bJsxAttr(t.JSXIdentifier("id"), t.StringLiteral(id)));
return bJsxElem({
selfClosing: true,
name: tag,
const injectChildren = (jsxElem, node) => {
let result;
if (t.isArrayExpression(node)) {
result = transformChildrenArray(node);
}
if (t.isStringLiteral(node)) {
result = [t.JSXText(node.value)];
}
if (t.isExpression(node) && !result) {
result = [t.JSXExpressionContainer(node)];
}
if (t.isJSXExpressionContainer(jsxElem)) {
closeComponent(jsxElem.expression.right, result);
return jsxElem;
} else {
return closeComponent(jsxElem, result);
}
};
const bJsxAttr = (prop, expressionOrValue) => {
const attributeName = t.isStringLiteral(prop)
? prop.extra.rawValue
: prop.name;
const stringOrExpression = t.isStringLiteral(expressionOrValue)
? expressionOrValue
: t.JSXExpressionContainer(expressionOrValue);
return t.JSXAttribute(bJsxIdent(attributeName), stringOrExpression);
};
const bJsxAttr = (prop, expressionOrValue) => {
const attributeName = t.isStringLiteral(prop)
? prop.extra.rawValue
: prop.name;
const stringOrExpression = t.isStringLiteral(expressionOrValue)
? expressionOrValue
: t.JSXExpressionContainer(expressionOrValue);
return t.JSXAttribute(bJsxIdent(attributeName), stringOrExpression);
};
const singleArgumentCase = firstArgument => {
const isElement = t.isStringLiteral(firstArgument);
const isReactComponent = t.isIdentifier(firstArgument);
const isMemberExpression = t.isMemberExpression(firstArgument);
let attributes = [];
if (isElement) {
const { id, className, tag } = getTagAndClassNamesAndId(
firstArgument.value
);
className &&
attributes.push(
bJsxAttr(t.JSXIdentifier("className"), t.StringLiteral(className))
);
id && attributes.push(bJsxAttr(t.JSXIdentifier("id"), t.StringLiteral(id)));
return bJsxElem({
selfClosing: true,
name: tag,
attributes
const bJsxAttr = (prop, expressionOrValue) => {
const attributeName = t.isStringLiteral(prop)
? prop.extra.rawValue
: prop.name;
const stringOrExpression = t.isStringLiteral(expressionOrValue)
? expressionOrValue
: t.JSXExpressionContainer(expressionOrValue);
return t.JSXAttribute(bJsxIdent(attributeName), stringOrExpression);
};