* Creates the cursor iterates tokens with options. * @param {CursorFactory} factory The cursor factory to initialize cursor. * @param {Token[]} tokens The array of tokens. * @param {Comment[]} comments The array of comments. * @param {Object} indexMap The map from locations to indices in `tokens
( factory, tokens, comments, indexMap, startLoc, endLoc, opts, )
| 143 | * @private |
| 144 | */ |
| 145 | function createCursorWithCount( |
| 146 | factory, |
| 147 | tokens, |
| 148 | comments, |
| 149 | indexMap, |
| 150 | startLoc, |
| 151 | endLoc, |
| 152 | opts, |
| 153 | ) { |
| 154 | let includeComments = false; |
| 155 | let count = 0; |
| 156 | let countExists = false; |
| 157 | let filter = null; |
| 158 | |
| 159 | if (typeof opts === "number") { |
| 160 | count = opts | 0; |
| 161 | countExists = true; |
| 162 | } else if (typeof opts === "function") { |
| 163 | filter = opts; |
| 164 | } else if (opts) { |
| 165 | includeComments = !!opts.includeComments; |
| 166 | count = opts.count | 0; |
| 167 | countExists = typeof opts.count === "number"; |
| 168 | filter = opts.filter || null; |
| 169 | } |
| 170 | assert(count >= 0, "options.count should be zero or a positive integer."); |
| 171 | assert( |
| 172 | !filter || typeof filter === "function", |
| 173 | "options.filter should be a function.", |
| 174 | ); |
| 175 | |
| 176 | return factory.createCursor( |
| 177 | tokens, |
| 178 | comments, |
| 179 | indexMap, |
| 180 | startLoc, |
| 181 | endLoc, |
| 182 | includeComments, |
| 183 | filter, |
| 184 | 0, |
| 185 | countExists ? count : -1, |
| 186 | ); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Creates the cursor iterates tokens with options. |
no test coverage detected
searching dependent graphs…