* Whether a declaration is inside an `{$IFDEF}`, `{$IFNDEF}`, `{$IF}` or * `{$IFOPT}` block, or its `{$ELSE}`.
(node: Node, context: ResolutionContext)
| 249 | * `{$IFOPT}` block, or its `{$ELSE}`. |
| 250 | */ |
| 251 | function declaredUnderCondition(node: Node, context: ResolutionContext): boolean { |
| 252 | const memo = memos(context).conditionDepths; |
| 253 | let depths = memo.get(node.filePath); |
| 254 | const lines = fileLines(node.filePath, context); |
| 255 | if (!depths) { |
| 256 | depths = []; |
| 257 | let depth = 0; |
| 258 | for (const text of lines) { |
| 259 | depths.push(depth); |
| 260 | if (text.includes('{$')) depth = conditionDepthAfter(text, depth); |
| 261 | } |
| 262 | memo.set(node.filePath, depths); |
| 263 | } |
| 264 | const line = lines[node.startLine - 1] ?? ''; |
| 265 | return conditionDepthAfter(line.slice(0, node.startColumn), depths[node.startLine - 1] ?? 0) > 0; |
| 266 | } |
| 267 | |
| 268 | /** The depth of conditional blocks after a line's directives (`{$IFDEF X}` opens one, `{$ENDIF}` closes it). */ |
| 269 | function conditionDepthAfter(text: string, depth: number): number { |
no test coverage detected