(tokensAfterPattern: string[])
| 338 | } |
| 339 | |
| 340 | function hasFileReadTargetToken(tokensAfterPattern: string[]): boolean { |
| 341 | let expectInputFile = false; |
| 342 | let skipNextOutputTarget = false; |
| 343 | |
| 344 | for (const token of tokensAfterPattern) { |
| 345 | if (expectInputFile) { |
| 346 | expectInputFile = false; |
| 347 | if (token !== "-" && token.length > 0) { |
| 348 | return true; |
| 349 | } |
| 350 | continue; |
| 351 | } |
| 352 | |
| 353 | if (skipNextOutputTarget) { |
| 354 | skipNextOutputTarget = false; |
| 355 | continue; |
| 356 | } |
| 357 | |
| 358 | // Input redirection: ... < file OR ... <file |
| 359 | if (token === "<" || token === "0<") { |
| 360 | expectInputFile = true; |
| 361 | continue; |
| 362 | } |
| 363 | const inputMatch = /^(?:0)?<(.+)$/.exec(token); |
| 364 | if (inputMatch && !token.startsWith("<<") && !token.startsWith("<<<")) { |
| 365 | const inputFile = inputMatch[1]; |
| 366 | if (inputFile !== "-" && inputFile.length > 0) { |
| 367 | return true; |
| 368 | } |
| 369 | continue; |
| 370 | } |
| 371 | |
| 372 | // Output redirection: ignore output targets. |
| 373 | if ( |
| 374 | token === ">" || |
| 375 | token === ">>" || |
| 376 | token === "1>" || |
| 377 | token === "1>>" || |
| 378 | token === "2>" || |
| 379 | token === "2>>" || |
| 380 | token === "&>" || |
| 381 | token === "&>>" |
| 382 | ) { |
| 383 | skipNextOutputTarget = true; |
| 384 | continue; |
| 385 | } |
| 386 | |
| 387 | // Output redirection with attached target (e.g. ">out", "2>/dev/null", "2>&1") |
| 388 | if (/^(?:\d+|&)?>>?/.test(token)) { |
| 389 | continue; |
| 390 | } |
| 391 | |
| 392 | // Flags and stdin |
| 393 | if (token === "-" || token === "--" || token.startsWith("-")) { |
| 394 | continue; |
| 395 | } |
| 396 | |
| 397 | // Remaining non-flag tokens look like file/path operands. |
no test coverage detected