(key, values, forceUnique)
| 334 | } |
| 335 | // Find a function definition by any means necessary (unless it is ambiguous) |
| 336 | #getFunction(key, values, forceUnique) { |
| 337 | // Selector |
| 338 | if (isHexString(key)) { |
| 339 | const selector = key.toLowerCase(); |
| 340 | for (const fragment of this.#functions.values()) { |
| 341 | if (selector === fragment.selector) { |
| 342 | return fragment; |
| 343 | } |
| 344 | } |
| 345 | return null; |
| 346 | } |
| 347 | // It is a bare name, look up the function (will return null if ambiguous) |
| 348 | if (key.indexOf("(") === -1) { |
| 349 | const matching = []; |
| 350 | for (const [name, fragment] of this.#functions) { |
| 351 | if (name.split("(" /* fix:) */)[0] === key) { |
| 352 | matching.push(fragment); |
| 353 | } |
| 354 | } |
| 355 | if (values) { |
| 356 | const lastValue = (values.length > 0) ? values[values.length - 1] : null; |
| 357 | let valueLength = values.length; |
| 358 | let allowOptions = true; |
| 359 | if (Typed.isTyped(lastValue) && lastValue.type === "overrides") { |
| 360 | allowOptions = false; |
| 361 | valueLength--; |
| 362 | } |
| 363 | // Remove all matches that don't have a compatible length. The args |
| 364 | // may contain an overrides, so the match may have n or n - 1 parameters |
| 365 | for (let i = matching.length - 1; i >= 0; i--) { |
| 366 | const inputs = matching[i].inputs.length; |
| 367 | if (inputs !== valueLength && (!allowOptions || inputs !== valueLength - 1)) { |
| 368 | matching.splice(i, 1); |
| 369 | } |
| 370 | } |
| 371 | // Remove all matches that don't match the Typed signature |
| 372 | for (let i = matching.length - 1; i >= 0; i--) { |
| 373 | const inputs = matching[i].inputs; |
| 374 | for (let j = 0; j < values.length; j++) { |
| 375 | // Not a typed value |
| 376 | if (!Typed.isTyped(values[j])) { |
| 377 | continue; |
| 378 | } |
| 379 | // We are past the inputs |
| 380 | if (j >= inputs.length) { |
| 381 | if (values[j].type === "overrides") { |
| 382 | continue; |
| 383 | } |
| 384 | matching.splice(i, 1); |
| 385 | break; |
| 386 | } |
| 387 | // Make sure the value type matches the input type |
| 388 | if (values[j].type !== inputs[j].baseType) { |
| 389 | matching.splice(i, 1); |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | } |
no test coverage detected