(match: Match)
| 190 | ) |
| 191 | |
| 192 | const 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))) |
no test coverage detected