BVB Source Codes

reactide Show whitespace.js Source code

Return Download reactide: download whitespace.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. var _map = require("lodash/map");
  4.  
  5. var _map2 = _interopRequireDefault(_map);
  6.  
  7. var _babelTypes = require("babel-types");
  8.  
  9. var t = _interopRequireWildcard(_babelTypes);
  10.  
  11. 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; } }
  12.  
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14.  
  15. function crawl(node) {
  16.   var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17.  
  18.   if (t.isMemberExpression(node)) {
  19.     crawl(node.object, state);
  20.     if (node.computed) crawl(node.property, state);
  21.   } else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
  22.     crawl(node.left, state);
  23.     crawl(node.right, state);
  24.   } else if (t.isCallExpression(node)) {
  25.     state.hasCall = true;
  26.     crawl(node.callee, state);
  27.   } else if (t.isFunction(node)) {
  28.     state.hasFunction = true;
  29.   } else if (t.isIdentifier(node)) {
  30.     state.hasHelper = state.hasHelper || isHelper(node.callee);
  31.   }
  32.  
  33.   return state;
  34. }
  35.  
  36. function isHelper(node) {
  37.   if (t.isMemberExpression(node)) {
  38.     return isHelper(node.object) || isHelper(node.property);
  39.   } else if (t.isIdentifier(node)) {
  40.     return node.name === "require" || node.name[0] === "_";
  41.   } else if (t.isCallExpression(node)) {
  42.     return isHelper(node.callee);
  43.   } else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
  44.     return t.isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right);
  45.   } else {
  46.     return false;
  47.   }
  48. }
  49.  
  50. function isType(node) {
  51.   return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) || t.isIdentifier(node) || t.isMemberExpression(node);
  52. }
  53.  
  54. exports.nodes = {
  55.   AssignmentExpression: function AssignmentExpression(node) {
  56.     var state = crawl(node.right);
  57.     if (state.hasCall && state.hasHelper || state.hasFunction) {
  58.       return {
  59.         before: state.hasFunction,
  60.         after: true
  61.       };
  62.     }
  63.   },
  64.   SwitchCase: function SwitchCase(node, parent) {
  65.     return {
  66.       before: node.consequent.length || parent.cases[0] === node
  67.     };
  68.   },
  69.   LogicalExpression: function LogicalExpression(node) {
  70.     if (t.isFunction(node.left) || t.isFunction(node.right)) {
  71.       return {
  72.         after: true
  73.       };
  74.     }
  75.   },
  76.   Literal: function Literal(node) {
  77.     if (node.value === "use strict") {
  78.       return {
  79.         after: true
  80.       };
  81.     }
  82.   },
  83.   CallExpression: function CallExpression(node) {
  84.     if (t.isFunction(node.callee) || isHelper(node)) {
  85.       return {
  86.         before: true,
  87.         after: true
  88.       };
  89.     }
  90.   },
  91.   VariableDeclaration: function VariableDeclaration(node) {
  92.     for (var i = 0; i < node.declarations.length; i++) {
  93.       var declar = node.declarations[i];
  94.  
  95.       var enabled = isHelper(declar.id) && !isType(declar.init);
  96.       if (!enabled) {
  97.         var state = crawl(declar.init);
  98.         enabled = isHelper(declar.init) && state.hasCall || state.hasFunction;
  99.       }
  100.  
  101.       if (enabled) {
  102.         return {
  103.           before: true,
  104.           after: true
  105.         };
  106.       }
  107.     }
  108.   },
  109.   IfStatement: function IfStatement(node) {
  110.     if (t.isBlockStatement(node.consequent)) {
  111.       return {
  112.         before: true,
  113.         after: true
  114.       };
  115.     }
  116.   }
  117. };
  118.  
  119. exports.nodes.ObjectProperty = exports.nodes.ObjectTypeProperty = exports.nodes.ObjectMethod = exports.nodes.SpreadProperty = function (node, parent) {
  120.   if (parent.properties[0] === node) {
  121.     return {
  122.       before: true
  123.     };
  124.   }
  125. };
  126.  
  127. exports.list = {
  128.   VariableDeclaration: function VariableDeclaration(node) {
  129.     return (0, _map2.default)(node.declarations, "init");
  130.   },
  131.   ArrayExpression: function ArrayExpression(node) {
  132.     return node.elements;
  133.   },
  134.   ObjectExpression: function ObjectExpression(node) {
  135.     return node.properties;
  136.   }
  137. };
  138.  
  139. [["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function (_ref) {
  140.   var type = _ref[0],
  141.       amounts = _ref[1];
  142.  
  143.   if (typeof amounts === "boolean") {
  144.     amounts = { after: amounts, before: amounts };
  145.   }
  146.   [type].concat(t.FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) {
  147.     exports.nodes[type] = function () {
  148.       return amounts;
  149.     };
  150.   });
  151. });
downloadwhitespace.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