.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / source-code / token-store / padded-token-cursor.js
1 /**
2  * @fileoverview Define the cursor which iterates tokens only, with inflated range.
3  * @author Toru Nagashima
4  */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Requirements
9 //------------------------------------------------------------------------------
10
11 const ForwardTokenCursor = require("./forward-token-cursor");
12
13 //------------------------------------------------------------------------------
14 // Exports
15 //------------------------------------------------------------------------------
16
17 /**
18  * The cursor which iterates tokens only, with inflated range.
19  * This is for the backward compatibility of padding options.
20  */
21 module.exports = class PaddedTokenCursor extends ForwardTokenCursor {
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      * @param {number} beforeCount The number of tokens this cursor iterates before start.
31      * @param {number} afterCount The number of tokens this cursor iterates after end.
32      */
33     constructor(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
34         super(tokens, comments, indexMap, startLoc, endLoc);
35         this.index = Math.max(0, this.index - beforeCount);
36         this.indexEnd = Math.min(tokens.length - 1, this.indexEnd + afterCount);
37     }
38 };