* 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, )
| 87 | * @private |
| 88 | */ |
| 89 | function createCursorWithSkip( |
| 90 | factory, |
| 91 | tokens, |
| 92 | comments, |
| 93 | indexMap, |
| 94 | startLoc, |
| 95 | endLoc, |
| 96 | opts, |
| 97 | ) { |
| 98 | let includeComments = false; |
| 99 | let skip = 0; |
| 100 | let filter = null; |
| 101 | |
| 102 | if (typeof opts === "number") { |
| 103 | skip = opts | 0; |
| 104 | } else if (typeof opts === "function") { |
| 105 | filter = opts; |
| 106 | } else if (opts) { |
| 107 | includeComments = !!opts.includeComments; |
| 108 | skip = opts.skip | 0; |
| 109 | filter = opts.filter || null; |
| 110 | } |
| 111 | assert(skip >= 0, "options.skip should be zero or a positive integer."); |
| 112 | assert( |
| 113 | !filter || typeof filter === "function", |
| 114 | "options.filter should be a function.", |
| 115 | ); |
| 116 | |
| 117 | return factory.createCursor( |
| 118 | tokens, |
| 119 | comments, |
| 120 | indexMap, |
| 121 | startLoc, |
| 122 | endLoc, |
| 123 | includeComments, |
| 124 | filter, |
| 125 | skip, |
| 126 | -1, |
| 127 | ); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Creates the cursor iterates tokens with options. |
no test coverage detected
searching dependent graphs…