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

Function classifyStructure

packages/tools/api-diff/src/Diff.ts:192–332  ·  view source on GitHub ↗
(match: Match)

Source from the content-addressed store, hash-verified

190 )
191
192const classifyStructure = (match: Match): ReadonlyArray<ApiChange> => {
193 const base = match.base
194 const head = match.head
195 const changes: Array<ApiChange> = []
196 if (base.bucket !== head.bucket) {
197 changes.push(makeChange("bucket-changed", match, { before: base.bucket, after: head.bucket }))
198 }
199 if (base.declarationKind !== head.declarationKind) {
200 changes.push(makeChange("declaration-kind-changed", match, {
201 before: base.declarationKind,
202 after: head.declarationKind
203 }))
204 }
205
206 const baseDeclarations = base.declarations
207 const headDeclarations = head.declarations
208 const baseSignatures = baseDeclarations.filter((declaration) =>
209 declaration.kind === "function" || declaration.kind === "method"
210 )
211 const headSignatures = headDeclarations.filter((declaration) =>
212 declaration.kind === "function" || declaration.kind === "method"
213 )
214 if (headSignatures.length > baseSignatures.length) {
215 changes.push(makeChange("overload-added", match, {
216 before: baseSignatures.length,
217 after: headSignatures.length
218 }))
219 } else if (headSignatures.length < baseSignatures.length) {
220 changes.push(makeChange("overload-removed", match, {
221 before: baseSignatures.length,
222 after: headSignatures.length
223 }))
224 } else if (
225 baseSignatures.length > 1 &&
226 stableJson(baseSignatures.map(declarationHash).sort()) === stableJson(headSignatures.map(declarationHash).sort()) &&
227 stableJson(baseSignatures.map(declarationHash)) !== stableJson(headSignatures.map(declarationHash))
228 ) {
229 changes.push(makeChange("overload-reordered", match))
230 }
231
232 const comparedSignatures = Math.min(baseSignatures.length, headSignatures.length)
233 for (let index = 0; index < comparedSignatures; index++) {
234 const before = baseSignatures[index]!
235 const after = headSignatures[index]!
236 const beforeParameters = before.parameters ?? []
237 const afterParameters = after.parameters ?? []
238 if (afterParameters.length > beforeParameters.length) {
239 changes.push(makeChange("parameter-added", match, {
240 overload: index,
241 before: beforeParameters,
242 after: afterParameters
243 }, String(index)))
244 } else if (afterParameters.length < beforeParameters.length) {
245 changes.push(makeChange("parameter-removed", match, {
246 overload: index,
247 before: beforeParameters,
248 after: afterParameters
249 }, String(index)))

Callers 1

diffSnapshotsFunction · 0.85

Calls 9

stableJsonFunction · 0.90
makeChangeFunction · 0.85
memberMapFunction · 0.85
pushMethod · 0.80
filterMethod · 0.80
getMethod · 0.65
StringInterface · 0.50
mapMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected