How to use the babel-core.types.JSXExpressionContainer function in babel-core

To help you get started, we’ve selected a few babel-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RIP21 / babel-plugin-hyperscript-to-jsx / src / rev.js View on Github external
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;
  }
};
github RIP21 / babel-plugin-hyperscript-to-jsx / src / index.js View on Github external
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;
  }
};
github RIP21 / babel-plugin-hyperscript-to-jsx / src / rev.js View on Github external
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);
};
github RIP21 / babel-plugin-hyperscript-to-jsx / src / rev.js View on Github external
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);
  }
};
github RIP21 / babel-plugin-hyperscript-to-jsx / src / rev.js View on Github external
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;
  }
};
github RIP21 / babel-plugin-hyperscript-to-jsx / src / index.js View on Github external
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);
};
github RIP21 / babel-plugin-hyperscript-to-jsx / src / index.js View on Github external
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)]);
  }
};