github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/src/util/component.js (about) 1 import { warn } from './debug' 2 import { resolveAsset } from './options' 3 import { getBindAttr } from './dom' 4 5 export const commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6|code|pre|table|th|td|tr|form|label|input|select|option|nav|article|section|header|footer)$/i 6 export const reservedTagRE = /^(slot|partial|component)$/i 7 8 let isUnknownElement 9 if (process.env.NODE_ENV !== 'production') { 10 isUnknownElement = function (el, tag) { 11 if (tag.indexOf('-') > -1) { 12 // http://stackoverflow.com/a/28210364/1070244 13 return ( 14 el.constructor === window.HTMLUnknownElement || 15 el.constructor === window.HTMLElement 16 ) 17 } else { 18 return ( 19 /HTMLUnknownElement/.test(el.toString()) && 20 // Chrome returns unknown for several HTML5 elements. 21 // https://code.google.com/p/chromium/issues/detail?id=540526 22 !/^(data|time|rtc|rb)$/.test(tag) 23 ) 24 } 25 } 26 } 27 28 /** 29 * Check if an element is a component, if yes return its 30 * component id. 31 * 32 * @param {Element} el 33 * @param {Object} options 34 * @return {Object|undefined} 35 */ 36 37 export function checkComponentAttr (el, options) { 38 var tag = el.tagName.toLowerCase() 39 var hasAttrs = el.hasAttributes() 40 if (!commonTagRE.test(tag) && !reservedTagRE.test(tag)) { 41 if (resolveAsset(options, 'components', tag)) { 42 return { id: tag } 43 } else { 44 var is = hasAttrs && getIsBinding(el, options) 45 if (is) { 46 return is 47 } else if (process.env.NODE_ENV !== 'production') { 48 var expectedTag = 49 options._componentNameMap && 50 options._componentNameMap[tag] 51 if (expectedTag) { 52 warn( 53 'Unknown custom element: <' + tag + '> - ' + 54 'did you mean <' + expectedTag + '>? ' + 55 'HTML is case-insensitive, remember to use kebab-case in templates.' 56 ) 57 } else if (isUnknownElement(el, tag)) { 58 warn( 59 'Unknown custom element: <' + tag + '> - did you ' + 60 'register the component correctly? For recursive components, ' + 61 'make sure to provide the "name" option.' 62 ) 63 } 64 } 65 } 66 } else if (hasAttrs) { 67 return getIsBinding(el, options) 68 } 69 } 70 71 /** 72 * Get "is" binding from an element. 73 * 74 * @param {Element} el 75 * @param {Object} options 76 * @return {Object|undefined} 77 */ 78 79 function getIsBinding (el, options) { 80 // dynamic syntax 81 var exp = el.getAttribute('is') 82 if (exp != null) { 83 if (resolveAsset(options, 'components', exp)) { 84 el.removeAttribute('is') 85 return { id: exp } 86 } 87 } else { 88 exp = getBindAttr(el, 'is') 89 if (exp != null) { 90 return { id: exp, dynamic: true } 91 } 92 } 93 }