|
1 | 1 | import { inheritableAttrs, elemsGroups } from './_collections.js'; |
2 | 2 |
|
3 | 3 | /** |
| 4 | + * @typedef {import('../lib/types.js').XastElement} XastElement |
4 | 5 | * @typedef {import('../lib/types.js').XastNode} XastNode |
5 | 6 | */ |
6 | 7 |
|
@@ -80,26 +81,30 @@ export const fn = () => { |
80 | 81 | node.attributes.transform == null && |
81 | 82 | firstChild.attributes.transform == null)) |
82 | 83 | ) { |
| 84 | + const newChildElemAttrs = { ...firstChild.attributes }; |
| 85 | + |
83 | 86 | for (const [name, value] of Object.entries(node.attributes)) { |
84 | 87 | // avoid copying to not conflict with animated attribute |
85 | 88 | if (hasAnimatedAttr(firstChild, name)) { |
86 | 89 | return; |
87 | 90 | } |
88 | | - if (firstChild.attributes[name] == null) { |
89 | | - firstChild.attributes[name] = value; |
| 91 | + |
| 92 | + if (newChildElemAttrs[name] == null) { |
| 93 | + newChildElemAttrs[name] = value; |
90 | 94 | } else if (name === 'transform') { |
91 | | - firstChild.attributes[name] = |
92 | | - value + ' ' + firstChild.attributes[name]; |
93 | | - } else if (firstChild.attributes[name] === 'inherit') { |
94 | | - firstChild.attributes[name] = value; |
| 95 | + newChildElemAttrs[name] = value + ' ' + newChildElemAttrs[name]; |
| 96 | + } else if (newChildElemAttrs[name] === 'inherit') { |
| 97 | + newChildElemAttrs[name] = value; |
95 | 98 | } else if ( |
96 | | - inheritableAttrs.has(name) === false && |
97 | | - firstChild.attributes[name] !== value |
| 99 | + !inheritableAttrs.has(name) && |
| 100 | + newChildElemAttrs[name] !== value |
98 | 101 | ) { |
99 | 102 | return; |
100 | 103 | } |
101 | | - delete node.attributes[name]; |
102 | 104 | } |
| 105 | + |
| 106 | + node.attributes = {}; |
| 107 | + firstChild.attributes = newChildElemAttrs; |
103 | 108 | } |
104 | 109 | } |
105 | 110 |
|
|
0 commit comments