* The logic for this is quite terse. It's because we need to * support spread elements. We loop over all attributes, * breaking on spreads, we then push a new object containing * all prior attributes to an array for later processing.
(attribs, path)
| 160 | */ |
| 161 | |
| 162 | function buildOpeningElementAttributes (attribs, path) { |
| 163 | var _props = [] |
| 164 | var objs = [] |
| 165 | |
| 166 | function pushProps () { |
| 167 | if (!_props.length) return |
| 168 | objs.push(t.objectExpression(_props)) |
| 169 | _props = [] |
| 170 | } |
| 171 | |
| 172 | while (attribs.length) { |
| 173 | var prop = attribs.shift() |
| 174 | if (t.isJSXSpreadAttribute(prop)) { |
| 175 | pushProps() |
| 176 | prop.argument._isSpread = true |
| 177 | objs.push(prop.argument) |
| 178 | } else { |
| 179 | _props.push(convertAttribute(prop)) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | pushProps() |
| 184 | |
| 185 | objs = objs.map(function (o) { |
| 186 | return o._isSpread ? o : groupProps(o.properties, t) |
| 187 | }) |
| 188 | |
| 189 | if (objs.length === 1) { |
| 190 | // only one object |
| 191 | attribs = objs[0] |
| 192 | } else if (objs.length) { |
| 193 | // add prop merging helper |
| 194 | var helper = addDefault(path, 'babel-helper-vue-jsx-merge-props', { nameHint: '_mergeJSXProps' }) |
| 195 | // spread it |
| 196 | attribs = t.callExpression( |
| 197 | helper, |
| 198 | [t.arrayExpression(objs)] |
| 199 | ) |
| 200 | } |
| 201 | return attribs |
| 202 | } |
| 203 | |
| 204 | function convertAttribute (node) { |
| 205 | var value = convertAttributeValue(node.value || t.booleanLiteral(true)) |
no test coverage detected
searching dependent graphs…