Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hasExpressions ||
t.isBinaryExpression(intermediateFirstArg);
const isFirstArgIsCalledFunction =
intermediateFirstArg.arguments &&
intermediateFirstArg.arguments.length >= 0;
// Intermediate value to convert to StringLiteral if TemplateLiteral has no expressions
const firstArgument =
isTemplateLiteral && !hasExpressions
? convertToStringLiteral(intermediateFirstArg)
: intermediateFirstArg;
const isConditionalExpression =
firstArgument.type === "ConditionalExpression"
// If firstArg is computed should be ignored, but inside the JSX should be wrapped into JSXExprContainer
if (isComputedClassNameOrComponent || isFirstArgIsCalledFunction || isConditionalExpression) {
return isTopLevelCall ? node : t.JSXExpressionContainer(node);
}
switch (node.arguments.length) {
case 1:
return singleArgumentCase(firstArgument);
case 2:
return twoArgumentsCase(firstArgument, secondArg, true);
case 3:
return threeArgumentsCase(firstArgument, secondArg, thirdArg);
default:
break;
}
};
intermediateFirstArg.arguments.length >= 0;
// Intermediate value to convert to StringLiteral if TemplateLiteral has no expressions
const firstArgument =
isTemplateLiteral && !hasExpressions
? convertToStringLiteral(intermediateFirstArg)
: intermediateFirstArg;
const isFirstArgIsConditionalExpression =
firstArgument.type === "ConditionalExpression"
// If firstArg is computed should be ignored, but inside the JSX should be wrapped into JSXExprContainer
if (
isComputedClassNameOrComponent ||
isFirstArgIsCalledFunction ||
isFirstArgIsConditionalExpression
) {
return isTopLevelCall ? node : t.JSXExpressionContainer(node);
}
switch (node.arguments.length) {
case 1:
return singleArgumentCase(firstArgument);
case 2:
return twoArgumentsCase(firstArgument, secondArg, true);
case 3:
return threeArgumentsCase(firstArgument, secondArg, thirdArg);
default:
break;
}
};
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 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 props = bJsxAttributes(secondArg);
const currentProps = jsxElem.openingElement.attributes;
jsxElem.openingElement.attributes = [...currentProps, ...props];
const isShouldBePrepended = props.find(
prop => prop.name && prop.name.name === "shouldRender"
);
if (isShouldBePrepended) {
const shouldRenderExpression = props.find(
prop => prop.name.name === "shouldRender"
).value.expression;
const logicalExpression = t.LogicalExpression(
"&&",
shouldRenderExpression,
jsxElem
);
return t.JSXExpressionContainer(logicalExpression);
}
return jsxElem;
}
if (thirdArgIsAbsent) {
return injectChildren(jsxElem, secondArg);
} else {
jsxElem.openingElement.attributes.push(t.JSXSpreadAttribute(secondArg));
return jsxElem;
}
};
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 injectChildren = (jsxElem, node) => {
if (t.isArrayExpression(node)) {
return closeComponent(jsxElem, transformChildrenArray(node));
}
if (t.isStringLiteral(node)) {
return closeComponent(jsxElem, [t.JSXText(node.value)]);
}
if (t.isExpression(node)) {
return closeComponent(jsxElem, [t.JSXExpressionContainer(node)]);
}
};