(
source: string,
candidates: ReadonlyArray<Candidate>,
comment: { readonly start: number },
file: string,
line: number
)
| 100 | ]).has(parent.type) |
| 101 | |
| 102 | const assertionTarget = ( |
| 103 | source: string, |
| 104 | candidates: ReadonlyArray<Candidate>, |
| 105 | comment: { readonly start: number }, |
| 106 | file: string, |
| 107 | line: number |
| 108 | ): Candidate => { |
| 109 | const target = candidates |
| 110 | .filter(({ node }) => node.end <= comment.start && /^[ \t]*$/.test(source.slice(node.end, comment.start))) |
| 111 | .sort((left, right) => right.node.end - left.node.end || right.depth - left.depth)[0] |
| 112 | |
| 113 | if (target === undefined) { |
| 114 | return fail(source, comment.start, file, line, "doctest assertion must trail a complete statement on the same line") |
| 115 | } |
| 116 | if (isUnbracedControlFlow(target.parent)) { |
| 117 | return fail(source, comment.start, file, line, "doctest assertions in control flow require an explicit block") |
| 118 | } |
| 119 | return target |
| 120 | } |
| 121 | |
| 122 | const parseExpected = (expected: string, source: string, offset: number, file: string, line: number): void => { |
| 123 | const parsed = parseSync(`${file}?doctest-expected`, `const __expected = (${expected})`, { lang: "ts" }) |
no test coverage detected