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. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  6.  
  7. var _getIterator3 = _interopRequireDefault(_getIterator2);
  8.  
  9. exports.default = function (_ref) {
  10.   var t = _ref.types;
  11.  
  12.   function getSpreadLiteral(spread, scope, state) {
  13.     if (state.opts.loose && !t.isIdentifier(spread.argument, { name: "arguments" })) {
  14.       return spread.argument;
  15.     } else {
  16.       return scope.toArray(spread.argument, true);
  17.     }
  18.   }
  19.  
  20.   function hasSpread(nodes) {
  21.     for (var i = 0; i < nodes.length; i++) {
  22.       if (t.isSpreadElement(nodes[i])) {
  23.         return true;
  24.       }
  25.     }
  26.     return false;
  27.   }
  28.  
  29.   function build(props, scope, state) {
  30.     var nodes = [];
  31.  
  32.     var _props = [];
  33.  
  34.     function push() {
  35.       if (!_props.length) return;
  36.       nodes.push(t.arrayExpression(_props));
  37.       _props = [];
  38.     }
  39.  
  40.     for (var _iterator = props, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  41.       var _ref2;
  42.  
  43.       if (_isArray) {
  44.         if (_i >= _iterator.length) break;
  45.         _ref2 = _iterator[_i++];
  46.       } else {
  47.         _i = _iterator.next();
  48.         if (_i.done) break;
  49.         _ref2 = _i.value;
  50.       }
  51.  
  52.       var prop = _ref2;
  53.  
  54.       if (t.isSpreadElement(prop)) {
  55.         push();
  56.         nodes.push(getSpreadLiteral(prop, scope, state));
  57.       } else {
  58.         _props.push(prop);
  59.       }
  60.     }
  61.  
  62.     push();
  63.  
  64.     return nodes;
  65.   }
  66.  
  67.   return {
  68.     visitor: {
  69.       ArrayExpression: function ArrayExpression(path, state) {
  70.         var node = path.node,
  71.             scope = path.scope;
  72.  
  73.         var elements = node.elements;
  74.         if (!hasSpread(elements)) return;
  75.  
  76.         var nodes = build(elements, scope, state);
  77.         var first = nodes.shift();
  78.  
  79.         if (!t.isArrayExpression(first)) {
  80.           nodes.unshift(first);
  81.           first = t.arrayExpression([]);
  82.         }
  83.  
  84.         path.replaceWith(t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes));
  85.       },
  86.       CallExpression: function CallExpression(path, state) {
  87.         var node = path.node,
  88.             scope = path.scope;
  89.  
  90.  
  91.         var args = node.arguments;
  92.         if (!hasSpread(args)) return;
  93.  
  94.         var calleePath = path.get("callee");
  95.         if (calleePath.isSuper()) return;
  96.  
  97.         var contextLiteral = t.identifier("undefined");
  98.  
  99.         node.arguments = [];
  100.  
  101.         var nodes = void 0;
  102.         if (args.length === 1 && args[0].argument.name === "arguments") {
  103.           nodes = [args[0].argument];
  104.         } else {
  105.           nodes = build(args, scope, state);
  106.         }
  107.  
  108.         var first = nodes.shift();
  109.         if (nodes.length) {
  110.           node.arguments.push(t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes));
  111.         } else {
  112.           node.arguments.push(first);
  113.         }
  114.  
  115.         var callee = node.callee;
  116.  
  117.         if (calleePath.isMemberExpression()) {
  118.           var temp = scope.maybeGenerateMemoised(callee.object);
  119.           if (temp) {
  120.             callee.object = t.assignmentExpression("=", temp, callee.object);
  121.             contextLiteral = temp;
  122.           } else {
  123.             contextLiteral = callee.object;
  124.           }
  125.           t.appendToMemberExpression(callee, t.identifier("apply"));
  126.         } else {
  127.           node.callee = t.memberExpression(node.callee, t.identifier("apply"));
  128.         }
  129.  
  130.         if (t.isSuper(contextLiteral)) {
  131.           contextLiteral = t.thisExpression();
  132.         }
  133.  
  134.         node.arguments.unshift(contextLiteral);
  135.       },
  136.       NewExpression: function NewExpression(path, state) {
  137.         var node = path.node,
  138.             scope = path.scope;
  139.  
  140.         var args = node.arguments;
  141.         if (!hasSpread(args)) return;
  142.  
  143.         var nodes = build(args, scope, state);
  144.  
  145.         var context = t.arrayExpression([t.nullLiteral()]);
  146.  
  147.         args = t.callExpression(t.memberExpression(context, t.identifier("concat")), nodes);
  148.  
  149.         path.replaceWith(t.newExpression(t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Function"), t.identifier("prototype")), t.identifier("bind")), t.identifier("apply")), [node.callee, args]), []));
  150.       }
  151.     }
  152.   };
  153. };
  154.  
  155. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  156.  
  157. 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