Răsfoiți Sursa

improve component name warning

Evan You 10 ani în urmă
părinte
comite
591e79f7e9
2 a modificat fișierele cu 8 adăugiri și 5 ștergeri
  1. 5 2
      src/instance/api/global.js
  2. 3 3
      test/unit/specs/api/global_spec.js

+ 5 - 2
src/instance/api/global.js

@@ -73,8 +73,11 @@ export default function (Vue) {
     }
     var name = extendOptions.name || Super.options.name
     if (process.env.NODE_ENV !== 'production') {
-      if (!/^[a-zA-Z][\w-]+$/.test(name)) {
-        warn('Invalid component name: ' + name)
+      if (!/^[a-zA-Z][\w-]*$/.test(name)) {
+        warn(
+          'Invalid component name: "' + name + '". Component names ' +
+          'can only contain alphanumeric characaters and the hyphen.'
+        )
         name = null
       }
     }

+ 3 - 3
test/unit/specs/api/global_spec.js

@@ -45,11 +45,11 @@ describe('Global API', function () {
 
   it('extend warn invalid names', function () {
     Vue.extend({ name: '123' })
-    expect(hasWarned('Invalid component name: 123')).toBe(true)
+    expect(hasWarned('Invalid component name: "123"')).toBe(true)
     Vue.extend({ name: '_fesf' })
-    expect(hasWarned('Invalid component name: _fesf')).toBe(true)
+    expect(hasWarned('Invalid component name: "_fesf"')).toBe(true)
     Vue.extend({ name: 'Some App' })
-    expect(hasWarned('Invalid component name: Some App')).toBe(true)
+    expect(hasWarned('Invalid component name: "Some App"')).toBe(true)
   })
 
   it('use', function () {