Skip to content

Commit 296dc78

Browse files
committed
fix array asset component name check
1 parent 9ec5cd3 commit 296dc78

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/util/options.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,12 @@ function guardArrayAssets (assets) {
281281
var asset
282282
while (i--) {
283283
asset = assets[i]
284-
var id = asset.name || (asset.options && asset.options.name)
284+
var id = typeof asset === 'function'
285+
? ((asset.options && asset.options.name) || asset.id)
286+
: (asset.name || asset.id)
285287
if (!id) {
286288
process.env.NODE_ENV !== 'production' && _.warn(
287-
'Array-syntax assets must provide a "name" field.'
289+
'Array-syntax assets must provide a "name" or "id" field.'
288290
)
289291
} else {
290292
res[id] = asset

test/unit/specs/util/options_spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,20 @@ describe('Util - Option merging', function () {
327327
components: [{}]
328328
}
329329
merge(a, b)
330-
expect(hasWarned(_, 'must provide a "name" field')).toBe(true)
330+
expect(hasWarned(_, 'must provide a "name" or "id" field')).toBe(true)
331+
})
332+
333+
it('warn Array async component without id', function () {
334+
var a = {
335+
components: {
336+
a: Vue.extend({})
337+
}
338+
}
339+
var b = {
340+
components: [function () {}]
341+
}
342+
merge(a, b)
343+
expect(hasWarned(_, 'must provide a "name" or "id" field')).toBe(true)
331344
})
332345

333346
})

0 commit comments

Comments
 (0)