Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.isHelper = exports.isKeyframesHelper = exports.isInjectGlobalHelper = exports.isCSSHelper = exports.isStyled = void 0;

const t = global._interopRequireWildcard(require('@babel/types'));

function importLocalName(name, state) {
  let localName = name === 'default' ? 'styled' : name;
  state.file.path.traverse({
    ImportDeclaration: {
      // eslint-disable-next-line
      exit: function exit(path) {
        const node = path.node;

        if (node.source.value === 'styled-components') {
          const list = path.get('specifiers');

          for (let index = 0; index < list.length; index++) {
            const specifier = list[index];

            if (specifier.isImportDefaultSpecifier()) {
              localName = specifier.node.local.name;
            }

            if (specifier.isImportSpecifier() && specifier.node.imported.name === name) {
              localName = specifier.node.local.name;
            }

            if (specifier.isImportNamespaceSpecifier()) {
              localName = specifier.node.local.name;
            }
          }
        }
      }
    }
  });
  return localName;
} // eslint-disable-next-line


function isStyled(tag, state) {
  const isStyledExpressionCall = t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && tag.callee.property.name !== 'default';
  /** ignore default for #93 below */

  if (isStyledExpressionCall) {
    // styled.something()
    return isStyled(tag.callee.object, state);
  } else {
    return t.isMemberExpression(tag) && tag.object.name === importLocalName('default', state) || t.isCallExpression(tag) && tag.callee.name === importLocalName('default', state) ||
    /**
     * #93 Support require()
     * styled-components might be imported using a require()
     * call and assigned to a variable of any name.
     * - styled.default.div``
     * - styled.default.something()
     */
    state.styledRequired && t.isMemberExpression(tag) && t.isMemberExpression(tag.object) && tag.object.property.name === 'default' && tag.object.object.name === state.styledRequired || state.styledRequired && t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && tag.callee.property.name === 'default' && tag.callee.object.name === state.styledRequired;
  }
}

function isCSSHelper(tag, state) {
  return t.isIdentifier(tag) && tag.name === importLocalName('css', state);
}

function isInjectGlobalHelper(tag, state) {
  return t.isIdentifier(tag) && tag.name === importLocalName('injectGlobal', state);
}

function isKeyframesHelper(tag, state) {
  return t.isIdentifier(tag) && tag.name === importLocalName('keyframes', state);
}

function isHelper(tag, state) {
  return isCSSHelper(tag, state) || isKeyframesHelper(tag, state);
}

exports.isStyled = isStyled;
exports.isCSSHelper = isCSSHelper;
exports.isInjectGlobalHelper = isInjectGlobalHelper;
exports.isKeyframesHelper = isKeyframesHelper;
exports.isHelper = isHelper;