BVB Source Codes

reactide Show index.js Source code

Return Download reactide: download index.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4.  
  5. exports.default = function (_ref) {
  6.   var t = _ref.types;
  7.  
  8.   function addDisplayName(id, call) {
  9.     var props = call.arguments[0].properties;
  10.     var safe = true;
  11.  
  12.     for (var i = 0; i < props.length; i++) {
  13.       var prop = props[i];
  14.       var key = t.toComputedKey(prop);
  15.       if (t.isLiteral(key, { value: "displayName" })) {
  16.         safe = false;
  17.         break;
  18.       }
  19.     }
  20.  
  21.     if (safe) {
  22.       props.unshift(t.objectProperty(t.identifier("displayName"), t.stringLiteral(id)));
  23.     }
  24.   }
  25.  
  26.   var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
  27.  
  28.   function isCreateClass(node) {
  29.     if (!node || !t.isCallExpression(node)) return false;
  30.  
  31.     if (!isCreateClassCallExpression(node.callee)) return false;
  32.  
  33.     var args = node.arguments;
  34.     if (args.length !== 1) return false;
  35.  
  36.     var first = args[0];
  37.     if (!t.isObjectExpression(first)) return false;
  38.  
  39.     return true;
  40.   }
  41.  
  42.   return {
  43.     visitor: {
  44.       ExportDefaultDeclaration: function ExportDefaultDeclaration(_ref2, state) {
  45.         var node = _ref2.node;
  46.  
  47.         if (isCreateClass(node.declaration)) {
  48.           var displayName = state.file.opts.basename;
  49.  
  50.           if (displayName === "index") {
  51.             displayName = _path2.default.basename(_path2.default.dirname(state.file.opts.filename));
  52.           }
  53.  
  54.           addDisplayName(displayName, node.declaration);
  55.         }
  56.       },
  57.       CallExpression: function CallExpression(path) {
  58.         var node = path.node;
  59.  
  60.         if (!isCreateClass(node)) return;
  61.  
  62.         var id = void 0;
  63.  
  64.         path.find(function (path) {
  65.           if (path.isAssignmentExpression()) {
  66.             id = path.node.left;
  67.           } else if (path.isObjectProperty()) {
  68.             id = path.node.key;
  69.           } else if (path.isVariableDeclarator()) {
  70.             id = path.node.id;
  71.           } else if (path.isStatement()) {
  72.             return true;
  73.           }
  74.  
  75.           if (id) return true;
  76.         });
  77.  
  78.         if (!id) return;
  79.  
  80.         if (t.isMemberExpression(id)) {
  81.           id = id.property;
  82.         }
  83.  
  84.         if (t.isIdentifier(id)) {
  85.           addDisplayName(id.name, node);
  86.         }
  87.       }
  88.     }
  89.   };
  90. };
  91.  
  92. var _path = require("path");
  93.  
  94. var _path2 = _interopRequireDefault(_path);
  95.  
  96. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  97.  
  98. module.exports = exports["default"];
downloadindex.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top