* 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)
| 205 | * function named `part`, or the file ends. |
| 206 | */ |
| 207 | function 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. */ |
| 241 | function dottedName(tokens: readonly DirectiveToken[]): string | null { |
no test coverage detected