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

Function dedupeProperties

packages/compiler-core/src/transforms/transformElement.ts:839–862  ·  view source on GitHub ↗
(properties: Property[])

Source from the content-addressed store, hash-verified

837// - onXXX handlers / style: merge into array
838// - class: merge into single expression with concatenation
839function dedupeProperties(properties: Property[]): Property[] {
840 const knownProps: Map<string, Property> = new Map()
841 const deduped: Property[] = []
842 for (let i = 0; i < properties.length; i++) {
843 const prop = properties[i]
844 // dynamic keys are always allowed
845 if (prop.key.type === NodeTypes.COMPOUND_EXPRESSION || !prop.key.isStatic) {
846 deduped.push(prop)
847 continue
848 }
849 const name = prop.key.content
850 const existing = knownProps.get(name)
851 if (existing) {
852 if (name === 'style' || name === 'class' || isOn(name)) {
853 mergeAsArray(existing, prop)
854 }
855 // unexpected duplicate, should have emitted error during parse
856 } else {
857 knownProps.set(name, prop)
858 deduped.push(prop)
859 }
860 }
861 return deduped
862}
863
864function mergeAsArray(existing: Property, incoming: Property) {
865 if (existing.value.type === NodeTypes.JS_ARRAY_EXPRESSION) {

Callers 2

pushMergeArgFunction · 0.85
buildPropsFunction · 0.85

Calls 5

isOnFunction · 0.90
mergeAsArrayFunction · 0.70
pushMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected