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. var _keys = require("babel-runtime/core-js/object/keys");
  10.  
  11. var _keys2 = _interopRequireDefault(_keys);
  12.  
  13. exports.needsWhitespace = needsWhitespace;
  14. exports.needsWhitespaceBefore = needsWhitespaceBefore;
  15. exports.needsWhitespaceAfter = needsWhitespaceAfter;
  16. exports.needsParens = needsParens;
  17.  
  18. var _whitespace = require("./whitespace");
  19.  
  20. var _whitespace2 = _interopRequireDefault(_whitespace);
  21.  
  22. var _parentheses = require("./parentheses");
  23.  
  24. var parens = _interopRequireWildcard(_parentheses);
  25.  
  26. var _babelTypes = require("babel-types");
  27.  
  28. var t = _interopRequireWildcard(_babelTypes);
  29.  
  30. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  31.  
  32. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  33.  
  34. function expandAliases(obj) {
  35.   var newObj = {};
  36.  
  37.   function add(type, func) {
  38.     var fn = newObj[type];
  39.     newObj[type] = fn ? function (node, parent, stack) {
  40.       var result = fn(node, parent, stack);
  41.  
  42.       return result == null ? func(node, parent, stack) : result;
  43.     } : func;
  44.   }
  45.  
  46.   for (var _iterator = (0, _keys2.default)(obj), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  47.     var _ref;
  48.  
  49.     if (_isArray) {
  50.       if (_i >= _iterator.length) break;
  51.       _ref = _iterator[_i++];
  52.     } else {
  53.       _i = _iterator.next();
  54.       if (_i.done) break;
  55.       _ref = _i.value;
  56.     }
  57.  
  58.     var type = _ref;
  59.  
  60.  
  61.     var aliases = t.FLIPPED_ALIAS_KEYS[type];
  62.     if (aliases) {
  63.       for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
  64.         var _ref2;
  65.  
  66.         if (_isArray2) {
  67.           if (_i2 >= _iterator2.length) break;
  68.           _ref2 = _iterator2[_i2++];
  69.         } else {
  70.           _i2 = _iterator2.next();
  71.           if (_i2.done) break;
  72.           _ref2 = _i2.value;
  73.         }
  74.  
  75.         var alias = _ref2;
  76.  
  77.         add(alias, obj[type]);
  78.       }
  79.     } else {
  80.       add(type, obj[type]);
  81.     }
  82.   }
  83.  
  84.   return newObj;
  85. }
  86.  
  87. var expandedParens = expandAliases(parens);
  88. var expandedWhitespaceNodes = expandAliases(_whitespace2.default.nodes);
  89. var expandedWhitespaceList = expandAliases(_whitespace2.default.list);
  90.  
  91. function find(obj, node, parent, printStack) {
  92.   var fn = obj[node.type];
  93.   return fn ? fn(node, parent, printStack) : null;
  94. }
  95.  
  96. function isOrHasCallExpression(node) {
  97.   if (t.isCallExpression(node)) {
  98.     return true;
  99.   }
  100.  
  101.   if (t.isMemberExpression(node)) {
  102.     return isOrHasCallExpression(node.object) || !node.computed && isOrHasCallExpression(node.property);
  103.   } else {
  104.     return false;
  105.   }
  106. }
  107.  
  108. function needsWhitespace(node, parent, type) {
  109.   if (!node) return 0;
  110.  
  111.   if (t.isExpressionStatement(node)) {
  112.     node = node.expression;
  113.   }
  114.  
  115.   var linesInfo = find(expandedWhitespaceNodes, node, parent);
  116.  
  117.   if (!linesInfo) {
  118.     var items = find(expandedWhitespaceList, node, parent);
  119.     if (items) {
  120.       for (var i = 0; i < items.length; i++) {
  121.         linesInfo = needsWhitespace(items[i], node, type);
  122.         if (linesInfo) break;
  123.       }
  124.     }
  125.   }
  126.  
  127.   return linesInfo && linesInfo[type] || 0;
  128. }
  129.  
  130. function needsWhitespaceBefore(node, parent) {
  131.   return needsWhitespace(node, parent, "before");
  132. }
  133.  
  134. function needsWhitespaceAfter(node, parent) {
  135.   return needsWhitespace(node, parent, "after");
  136. }
  137.  
  138. function needsParens(node, parent, printStack) {
  139.   if (!parent) return false;
  140.  
  141.   if (t.isNewExpression(parent) && parent.callee === node) {
  142.     if (isOrHasCallExpression(node)) return true;
  143.   }
  144.  
  145.   return find(expandedParens, node, parent, printStack);
  146. }
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