(properties: Property[])
| 837 | // - onXXX handlers / style: merge into array |
| 838 | // - class: merge into single expression with concatenation |
| 839 | function 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 | |
| 864 | function mergeAsArray(existing: Property, incoming: Property) { |
| 865 | if (existing.value.type === NodeTypes.JS_ARRAY_EXPRESSION) { |
no test coverage detected