MCPcopy
hub / github.com/eslint/eslint / createCursorWithCount

Function createCursorWithCount

lib/languages/js/source-code/token-store/index.js:145–187  ·  view source on GitHub ↗

* 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,
)

Source from the content-addressed store, hash-verified

143 * @private
144 */
145function 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.

Callers 9

createCursorWithPaddingFunction · 0.85
getFirstTokensMethod · 0.85
getLastTokensMethod · 0.85
getTokensBeforeMethod · 0.85
getTokensAfterMethod · 0.85
getFirstTokensBetweenMethod · 0.85
getLastTokensBetweenMethod · 0.85
getCommentsBeforeMethod · 0.85
getCommentsAfterMethod · 0.85

Calls 2

createCursorMethod · 0.80
assertFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…