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. exports.__esModule = true;
  4.  
  5. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  6.  
  7. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  8.  
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10.  
  11. var Whitespace = function () {
  12.   function Whitespace(tokens) {
  13.     (0, _classCallCheck3.default)(this, Whitespace);
  14.  
  15.     this.tokens = tokens;
  16.     this.used = {};
  17.   }
  18.  
  19.   Whitespace.prototype.getNewlinesBefore = function getNewlinesBefore(node) {
  20.     var startToken = void 0;
  21.     var endToken = void 0;
  22.     var tokens = this.tokens;
  23.  
  24.     var index = this._findToken(function (token) {
  25.       return token.start - node.start;
  26.     }, 0, tokens.length);
  27.     if (index >= 0) {
  28.       while (index && node.start === tokens[index - 1].start) {
  29.         --index;
  30.       }startToken = tokens[index - 1];
  31.       endToken = tokens[index];
  32.     }
  33.  
  34.     return this._getNewlinesBetween(startToken, endToken);
  35.   };
  36.  
  37.   Whitespace.prototype.getNewlinesAfter = function getNewlinesAfter(node) {
  38.     var startToken = void 0;
  39.     var endToken = void 0;
  40.     var tokens = this.tokens;
  41.  
  42.     var index = this._findToken(function (token) {
  43.       return token.end - node.end;
  44.     }, 0, tokens.length);
  45.     if (index >= 0) {
  46.       while (index && node.end === tokens[index - 1].end) {
  47.         --index;
  48.       }startToken = tokens[index];
  49.       endToken = tokens[index + 1];
  50.       if (endToken.type.label === ",") endToken = tokens[index + 2];
  51.     }
  52.  
  53.     if (endToken && endToken.type.label === "eof") {
  54.       return 1;
  55.     } else {
  56.       return this._getNewlinesBetween(startToken, endToken);
  57.     }
  58.   };
  59.  
  60.   Whitespace.prototype._getNewlinesBetween = function _getNewlinesBetween(startToken, endToken) {
  61.     if (!endToken || !endToken.loc) return 0;
  62.  
  63.     var start = startToken ? startToken.loc.end.line : 1;
  64.     var end = endToken.loc.start.line;
  65.     var lines = 0;
  66.  
  67.     for (var line = start; line < end; line++) {
  68.       if (typeof this.used[line] === "undefined") {
  69.         this.used[line] = true;
  70.         lines++;
  71.       }
  72.     }
  73.  
  74.     return lines;
  75.   };
  76.  
  77.   Whitespace.prototype._findToken = function _findToken(test, start, end) {
  78.     if (start >= end) return -1;
  79.     var middle = start + end >>> 1;
  80.     var match = test(this.tokens[middle]);
  81.     if (match < 0) {
  82.       return this._findToken(test, middle + 1, end);
  83.     } else if (match > 0) {
  84.       return this._findToken(test, start, middle);
  85.     } else if (match === 0) {
  86.       return middle;
  87.     }
  88.     return -1;
  89.   };
  90.  
  91.   return Whitespace;
  92. }();
  93.  
  94. exports.default = Whitespace;
  95. module.exports = exports["default"];
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