MCPcopy
hub / github.com/vuejs/babel-plugin-transform-vue-jsx / buildOpeningElementAttributes

Function buildOpeningElementAttributes

index.js:162–202  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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))

Callers 1

buildElementCallFunction · 0.85

Calls 2

pushPropsFunction · 0.85
convertAttributeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…