How to use the babel-plugin-styled-components/lib/utils/detectors.isPureHelper function in babel-plugin-styled-components

To help you get started, we’ve selected a few babel-plugin-styled-components 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 QuickBase / babel-plugin-styled-components-css-namespace / src / visitors / cssNamespace.js View on Github external
const { cssNamespace } = getCssNamespace(state);

  const { node } = path;
  const {
    quasi: { quasis, expressions }
  } = node;

  // Ignore nodes generated by this visitor, to prevent infinite loops
  if (replacementNodes.has(node)) return;

  // Ignore templates tagged with anything other than `styled(x)`
  // Inspired by
  if (!isStyled(t)(tag, state)) return;
  if (isKeyframesHelper(t)(tag, state)) return;
  if (isPureHelper(t)(tag, state)) return;
  if (isHelper(t)(tag, state)) return;
  if (isCSSHelper(t)(tag, state)) return;
  if (isInjectGlobalHelper(t)(tag, state)) return;
  if ( && === 'keyframes') return; // Maintain backward compatibility with styled.keyframes

  // Convert the tagged template to a string, with ${} expressions replaced with placeholders
  const originalStyleString = quasis
    .map((quasi, i) => {
      const rawValue = quasi.value.raw;
      const nextQuasi = quasis[i + 1];
      const rawValueWithoutWhiteSpace = rawValue.replace(/[\n\r\s]/g, '');

      // When there is no associated expression, we can return the plain string
      if (!expressions[i]) {
        return rawValue;