2 * @fileoverview Define the cursor which iterates tokens only.
3 * @author Toru Nagashima
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const Cursor = require("./cursor");
12 const utils = require("./utils");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
19 * The cursor which iterates tokens only.
21 module.exports = class ForwardTokenCursor extends Cursor {
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.
31 constructor(tokens, comments, indexMap, startLoc, endLoc) {
34 this.index = utils.getFirstIndex(tokens, indexMap, startLoc);
35 this.indexEnd = utils.getLastIndex(tokens, indexMap, endLoc);
40 if (this.index <= this.indexEnd) {
41 this.current = this.tokens[this.index];
50 * Shorthand for performance.
56 return (this.index <= this.indexEnd) ? this.tokens[this.index] : null;
61 return this.tokens.slice(this.index, this.indexEnd + 1);