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:
/* eslint-disable */
'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.default = babelPluginStyledComponents;

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {
    default: obj
  };
}

function _interopRequireWildcard(obj) {
  if (obj && obj.__esModule) {
    return obj;
  } else {
    const newObj = {};

    if (obj != null) {
      for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          const desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};

          if (desc.get || desc.set) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }
    }

    newObj.default = obj;
    return newObj;
  }
}

if (typeof global === 'object') {
  global._interopRequireDefault = _interopRequireDefault;
  global._interopRequireWildcard = _interopRequireWildcard;
}

const _uglifyPure = _interopRequireDefault(require("./visitors/uglifyPure"));

const _minify = _interopRequireDefault(require("./visitors/minify"));

const displayNameAndId = require("./visitors/displayNameAndId");

const _templateLiterals = _interopRequireDefault(require("./visitors/templateLiterals"));

const assignStyledRequired = require("./visitors/assignStyledRequired");

const _require = require("./visitors/noParserImport"),
      noParserImportDeclaration = _require.noParserImportDeclaration,
      noParserRequireCallExpression = _require.noParserRequireCallExpression;
/**
 * @see https://www.sitepoint.com/understanding-asts-building-babel-plugin/
 * @api https://babeljs.io/docs/core-packages/babel-types/
 */


function babelPluginStyledComponents(_ref) {
  const t = _ref.types; // @todo fix these

  return {
    visitor: {
      // === do not need these two ===
      //
      // this part we really don't like, because we have a global
      // basically all this does is when you have `no-parser` option,
      // it changes the import path
      //
      // but we changed that at the source,
      // since we always want to use styleh
      // ImportDeclaration: function ImportDeclaration(path, state) {
      //   noParserImportDeclaration(path, state)
      // },
      // when we call some function, uglify & change export?
      // CallExpression: function CallExpression(path, state) {
      //   ;(0, _uglifyPure.default)(path, state)
      //   noParserRequireCallExpression(path, state)
      // },
      // templates, we can minify for a smaller js file
      TaggedTemplateExpression: function TaggedTemplateExpression(path, state) {
        // console.log('TaggedTemplateExpression')
        // could filter for elements :3
        // console.log(state.filename)
        if (state.filename.includes('view-container')) {
          // console.log('ignored!!!')
          return;
        } // path is ast traversal path
        // state.file.code
        // console.log({ path, state })
        // disabling until cleaned
        // ;(0, _minify.default)(path, state)
        // vvvvvv
        // => focus is on this one
        // vvvvv


        displayNameAndId(path, state); // ;(0, _templateLiterals.default)(path, state)
      } // all this does is check for
      // `import styled from 'styled-components'
      // or `require('styled-components')`
      // and then change it to a more direct path
      // so that we could bundle only what is used
      // and remove server from client
      // VariableDeclarator: function VariableDeclarator(path, state) {
      //   assignStyledRequired(path, state)
      // },

    }
  };
}