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