MCPcopy Create free account
hub / github.com/Effect-TS/effect / assertionTarget

Function assertionTarget

packages/tools/doctest/src/Transform.ts:102–120  ·  view source on GitHub ↗
(
  source: string,
  candidates: ReadonlyArray<Candidate>,
  comment: { readonly start: number },
  file: string,
  line: number
)

Source from the content-addressed store, hash-verified

100 ]).has(parent.type)
101
102const 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
122const parseExpected = (expected: string, source: string, offset: number, file: string, line: number): void => {
123 const parsed = parseSync(`${file}?doctest-expected`, `const __expected = (${expected})`, { lang: "ts" })

Callers 1

transformFunction · 0.85

Calls 3

isUnbracedControlFlowFunction · 0.85
filterMethod · 0.80
failFunction · 0.70

Tested by

no test coverage detected