source: imaps-frontend/node_modules/eslint/lib/source-code/token-store/forward-token-cursor.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @fileoverview Define the cursor which iterates tokens only.
3 * @author Toru Nagashima
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Requirements
9//------------------------------------------------------------------------------
10
11const Cursor = require("./cursor");
12const utils = require("./utils");
13
14//------------------------------------------------------------------------------
15// Exports
16//------------------------------------------------------------------------------
17
18/**
19 * The cursor which iterates tokens only.
20 */
21module.exports = class ForwardTokenCursor extends Cursor {
22
23 /**
24 * Initializes this cursor.
25 * @param {Token[]} tokens The array of tokens.
26 * @param {Comment[]} comments The array of comments.
27 * @param {Object} indexMap The map from locations to indices in `tokens`.
28 * @param {number} startLoc The start location of the iteration range.
29 * @param {number} endLoc The end location of the iteration range.
30 */
31 constructor(tokens, comments, indexMap, startLoc, endLoc) {
32 super();
33 this.tokens = tokens;
34 this.index = utils.getFirstIndex(tokens, indexMap, startLoc);
35 this.indexEnd = utils.getLastIndex(tokens, indexMap, endLoc);
36 }
37
38 /** @inheritdoc */
39 moveNext() {
40 if (this.index <= this.indexEnd) {
41 this.current = this.tokens[this.index];
42 this.index += 1;
43 return true;
44 }
45 return false;
46 }
47
48 /*
49 *
50 * Shorthand for performance.
51 *
52 */
53
54 /** @inheritdoc */
55 getOneToken() {
56 return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
57 }
58
59 /** @inheritdoc */
60 getAllTokens() {
61 return this.tokens.slice(this.index, this.indexEnd + 1);
62 }
63};
Note: See TracBrowser for help on using the repository browser.