( key: DeprecationTypes, instance: ComponentInternalInstance | null, ...args: any[] )
| 436 | } |
| 437 | |
| 438 | export function warnDeprecation( |
| 439 | key: DeprecationTypes, |
| 440 | instance: ComponentInternalInstance | null, |
| 441 | ...args: any[] |
| 442 | ): void { |
| 443 | if (!__DEV__) { |
| 444 | return |
| 445 | } |
| 446 | if (__TEST__ && !warningEnabled) { |
| 447 | return |
| 448 | } |
| 449 | |
| 450 | instance = instance || getCurrentInstance() |
| 451 | |
| 452 | // check user config |
| 453 | const config = getCompatConfigForKey(key, instance) |
| 454 | if (config === 'suppress-warning') { |
| 455 | return |
| 456 | } |
| 457 | |
| 458 | const dupKey = key + args.join('') |
| 459 | let compId: string | number | null = |
| 460 | instance && formatComponentName(instance, instance.type) |
| 461 | if (compId === 'Anonymous' && instance) { |
| 462 | compId = instance.uid |
| 463 | } |
| 464 | |
| 465 | // skip if the same warning is emitted for the same component type |
| 466 | const componentDupKey = dupKey + compId |
| 467 | if (!__TEST__ && componentDupKey in instanceWarned) { |
| 468 | return |
| 469 | } |
| 470 | instanceWarned[componentDupKey] = true |
| 471 | |
| 472 | // same warning, but different component. skip the long message and just |
| 473 | // log the key and count. |
| 474 | if (!__TEST__ && dupKey in warnCount) { |
| 475 | warn(`(deprecation ${key}) (${++warnCount[dupKey] + 1})`) |
| 476 | return |
| 477 | } |
| 478 | |
| 479 | warnCount[dupKey] = 0 |
| 480 | |
| 481 | const { message, link } = deprecationData[key] |
| 482 | warn( |
| 483 | `(deprecation ${key}) ${ |
| 484 | typeof message === 'function' ? message(...args) : message |
| 485 | }${link ? `\n Details: ${link}` : ``}`, |
| 486 | ) |
| 487 | if (!isCompatEnabled(key, instance, true)) { |
| 488 | console.error( |
| 489 | `^ The above deprecation's compat behavior is disabled and will likely ` + |
| 490 | `lead to runtime errors.`, |
| 491 | ) |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | export type CompatConfig = Partial< |
no test coverage detected