MCPcopy Create free account
hub / github.com/arktypeio/arktype / addIssueFeatures

Function addIssueFeatures

ark/type/standalone/sites.ts:154–222  ·  view source on GitHub ↗
(
	features: IssueFeatures,
	units: readonly RootUnit[],
	written: readonly BaseNode[]
)

Source from the content-addressed store, hash-verified

152
153// a callback may raise an issue at any path, with any text
154export const addIssueFeatures = (
155 features: IssueFeatures,
156 units: readonly RootUnit[],
157 written: readonly BaseNode[]
158): void => {
159 // what a unit declares where one of its roots is compiled, whose code passes
160 // a narrow its ctx: one only checkers call that tests its data or rejects
161 // with a message is passed one of theirs, and fails at a site
162 const compiled = new Set(
163 units.flatMap(unit =>
164 unit.roots.every(root => isCheckerIn(unit, root)) ? [] : unit.declared
165 )
166 )
167 for (const node of written) {
168 if (node.is("sequence")) features.reportsIndices = true
169 else if (node.is("structure")) {
170 // an index signature's keys come from data, as do the undeclared
171 // keys a structure rejects
172 if (node.index) features.reportsIndices = true
173 if (
174 node.index ||
175 node.undeclared === "reject" ||
176 node.props.some(
177 prop => typeof prop.key === "symbol" || !isDotAccessible(prop.key)
178 )
179 )
180 features.bracketsKeys = true
181 } else if (
182 node.is("morph") ||
183 (node.is("predicate") &&
184 !raisesNothing(node.predicate) &&
185 (compiled.has(node) || !testsOrRejects.has(node.predicate)))
186 ) {
187 features.reportsIndices = true
188 features.bracketsKeys = true
189 features.writesText = true
190 features.readsErrors = true
191 if (node.is("morph")) features.listsUnions = true
192 if (node.meta.label !== undefined) features.labelsValues = true
193 } else if (node.is("union") && node.tfs) {
194 features.transformsBranches = true
195 if (node.hasMorph || node.hasAlias) features.failsInBranches = true
196 }
197 if (
198 (node.is("predicate") && !isKeyword(node.predicate)) ||
199 (node.is("morph") &&
200 node.morphs.some(m => typeof m === "function" && !isKeyword(m)))
201 )
202 features.readsContext = true
203 }
204 for (const unit of units) {
205 for (const [, source] of unit.members) {
206 if (addsUnionIssue.test(source)) features.listsUnions = true
207 if (saysMessage.test(source)) features.writesText = true
208 if (callsTextIn.test(source)) features.callsSiteText = true
209 if (appliesValue.test(source)) features.appliesValues = true
210 if (discriminatesBoolean.test(source))
211 features.discriminatesBooleans = true

Callers 1

readWrittenFunction · 0.90

Calls 7

isCheckerInFunction · 0.90
isDotAccessibleFunction · 0.90
raisesNothingFunction · 0.85
isKeywordFunction · 0.85
isMethod · 0.80
testMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected