Просмотр исходного кода

support camelCase assets (close #1029)

Stephen Young 11 лет назад
Родитель
Сommit
c84406ff15
2 измененных файлов с 28 добавлено и 2 удалено
  1. 3 2
      src/util/options.js
  2. 25 0
      test/unit/specs/util/options_spec.js

+ 3 - 2
src/util/options.js

@@ -340,13 +340,14 @@ exports.mergeOptions = function merge (parent, child, vm) {
  */
 
 exports.resolveAsset = function resolve (options, type, id) {
-  var asset = options[type][id]
+  var camelizedId = _.camelize(id)
+  var asset = options[type][id] || options[type][camelizedId]
   while (
     !asset && options._parent &&
     (!config.strict || options._repeat)
   ) {
     options = options._parent.$options
-    asset = options[type][id]
+    asset = options[type][id] || options[type][camelizedId]
   }
   return asset
 }

+ 25 - 0
test/unit/specs/util/options_spec.js

@@ -1,6 +1,7 @@
 var _ = require('../../../../src/util')
 var Vue = require('../../../../src/vue')
 var merge = _.mergeOptions
+var resolveAsset = _.resolveAsset
 
 describe('Util - Option merging', function () {
 
@@ -303,3 +304,27 @@ describe('Util - Option merging', function () {
   })
 
 })
+
+describe('Util - Option resolveAsset', function () {
+
+  var vm
+  beforeEach(function () {
+    vm = new Vue({
+      data: {},
+      components: {
+        'hyphenated-component': {
+          template: 'hi'
+        },
+        camelCasedComponent: {
+          template: 'yo'
+        }
+      }
+    })
+  })
+
+  it('resolves', function () {
+    expect(resolveAsset(vm.$options, 'components', 'hyphenated-component')).toBeTruthy()
+    expect(resolveAsset(vm.$options, 'components', 'camel-cased-component')).toBeTruthy()
+  })
+
+})