MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readDirectiveTokens

Function readDirectiveTokens

src/resolution/dart-libraries.ts:207–238  ·  view source on GitHub ↗

* The tokens of a directive, from just past its keyword to its `;`, and the * index past that `;` — or null when a body (`{`, `=>`) comes first, as in a * function named `part`, or the file ends.

(src: string, i: number)

Source from the content-addressed store, hash-verified

205 * function named `part`, or the file ends.
206 */
207function readDirectiveTokens(src: string, i: number): { tokens: DirectiveToken[]; end: number } | null {
208 const tokens: DirectiveToken[] = [];
209 for (;;) {
210 i = skipTrivia(src, i);
211 if (i >= src.length || tokens.length > 2000) return null;
212 const c = src[i]!;
213 if (c === ';') return { tokens, end: i + 1 };
214 if (c === '{' || c === '}' || (c === '=' && src[i + 1] === '>')) return null;
215 const literal = readString(src, i);
216 if (literal) {
217 tokens.push({ kind: 'string', value: literal.value });
218 i = literal.end;
219 continue;
220 }
221 if (c === '(') {
222 // A configuration condition: `(dart.library.io)`, `(dart.library.js_interop == 'true')`.
223 i = skipGroup(src, i, '(', ')');
224 if (i < 0) return null;
225 tokens.push({ kind: 'condition' });
226 continue;
227 }
228 IDENTIFIER.lastIndex = i;
229 const word = IDENTIFIER.exec(src);
230 if (word) {
231 tokens.push({ kind: 'word', value: word[0] });
232 i += word[0].length;
233 continue;
234 }
235 tokens.push({ kind: 'punctuation', value: c });
236 i++;
237 }
238}
239
240/** A dotted library name (`app.named`), as the words and dots it is written with. */
241function dottedName(tokens: readonly DirectiveToken[]): string | null {

Callers 1

readDartDirectivesFunction · 0.85

Calls 5

readStringFunction · 0.85
pushMethod · 0.80
skipTriviaFunction · 0.70
skipGroupFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected