BVB Source Codes

reactide Show locutil.js Source code

Return Download reactide: download locutil.js Source code - Download reactide Source code - Type:.js
  1. import {lineBreakG} from "./whitespace"
  2.  
  3. // These are used when `options.locations` is on, for the
  4. // `startLoc` and `endLoc` properties.
  5.  
  6. export class Position {
  7.   constructor(line, col) {
  8.     this.line = line
  9.     this.column = col
  10.   }
  11.  
  12.   offset(n) {
  13.     return new Position(this.line, this.column + n)
  14.   }
  15. }
  16.  
  17. export class SourceLocation {
  18.   constructor(p, start, end) {
  19.     this.start = start
  20.     this.end = end
  21.     if (p.sourceFile !== null) this.source = p.sourceFile
  22.   }
  23. }
  24.  
  25. // The `getLineInfo` function is mostly useful when the
  26. // `locations` option is off (for performance reasons) and you
  27. // want to find the line/column position for a given character
  28. // offset. `input` should be the code string that the offset refers
  29. // into.
  30.  
  31. export function getLineInfo(input, offset) {
  32.   for (let line = 1, cur = 0;;) {
  33.     lineBreakG.lastIndex = cur
  34.     let match = lineBreakG.exec(input)
  35.     if (match && match.index < offset) {
  36.       ++line
  37.       cur = match.index + match[0].length
  38.     } else {
  39.       return new Position(line, offset - cur)
  40.     }
  41.   }
  42. }
  43.  
downloadlocutil.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