MCPcopy
hub / github.com/vuejs/core / compatCoerceAttr

Function compatCoerceAttr

packages/runtime-dom/src/modules/attrs.ts:54–95  ·  view source on GitHub ↗
(
  el: Element,
  key: string,
  value: unknown,
  instance: ComponentInternalInstance | null = null,
)

Source from the content-addressed store, hash-verified

52 : NOOP
53
54export function compatCoerceAttr(
55 el: Element,
56 key: string,
57 value: unknown,
58 instance: ComponentInternalInstance | null = null,
59): boolean {
60 if (isEnumeratedAttr(key)) {
61 const v2CoercedValue =
62 value === undefined
63 ? null
64 : value === null || value === false || value === 'false'
65 ? 'false'
66 : 'true'
67 if (
68 v2CoercedValue &&
69 compatUtils.softAssertCompatEnabled(
70 DeprecationTypes.ATTR_ENUMERATED_COERCION,
71 instance,
72 key,
73 value,
74 v2CoercedValue,
75 )
76 ) {
77 el.setAttribute(key, v2CoercedValue)
78 return true
79 }
80 } else if (
81 value === false &&
82 !(el.tagName === 'INPUT' && key === 'value') &&
83 !isSpecialBooleanAttr(key) &&
84 compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
85 ) {
86 compatUtils.warnDeprecation(
87 DeprecationTypes.ATTR_FALSE_VALUE,
88 instance,
89 key,
90 )
91 el.removeAttribute(key)
92 return true
93 }
94 return false
95}

Callers 1

patchAttrFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected