lib/validator.js
function checkTagName(node, output) {
  var result = output.result
  var deps = output.deps
  var log = output.log

  var tagName = node.tagName
  var childNodes = node.childNodes || []
  var location = node.__location || {}

  // alias
  if (TAG_NAME_ALIAS_MAP[tagName]) {
    if (tagName !== 'img') { // FIXME: `parse5` autofixes image to img silently
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'NOTE: tag name `' + tagName + '` is autofixed to `' + TAG_NAME_ALIAS_MAP[tagName] + '`'
      })
    }
    tagName = TAG_NAME_ALIAS_MAP[tagName]
  }

  if (tagName === 'component') {
    var indexOfIs = -1
    if (node.attrs) {
      node.attrs.forEach(function (attr, index) {
        if (attr.name === 'is') {
          indexOfIs = index
          result.type = tagName = exp(attr.value)
        }
      })
    }
    if (indexOfIs > -1) {
      node.attrs.splice(indexOfIs, 1) // delete `is`
    }
    else {
      result.type = tagName = 'container'
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'WARNING: tag `component` should have an `is` attribute, otherwise it will be regarded as a `container`'
      })
    }
  }
  else {
    result.type = tagName
  }

  // deps
  if (deps.indexOf(tagName) < 0 && typeof tagName === 'string') { // FIXME: improve `require` to bundle dynamic binding components
    deps.push(tagName)
  }

  // parent (no any rules yet)

  // child (noChild, textContent)
  if (NO_CHILD_TAG_NAME_LIST.indexOf(tagName) >= 0) {
    if (childNodes.length > 0) {
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'ERROR: tag `' + tagName + '` should not have children'
      })
    }
  }
  if (TEXT_CONTENT_TAG_NAME_LIST.indexOf(tagName) >= 0) {
    if (childNodes.length > 1 || (childNodes[0] && childNodes[0].nodeName !== '#text')) {
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'ERROR: tag name `' + tagName + '` should just have one text node only'
      })
    }
  }

  // default attr
  if (TAG_DEFAULT_ATTR_MAP[tagName]) {
    Object.keys(TAG_DEFAULT_ATTR_MAP[tagName]).forEach(function (attr) {
      if (attr !== 'append') {
        result.attr = result.attr || {}
        result.attr[attr] = TAG_DEFAULT_ATTR_MAP[tagName][attr]
      }
      else {
        result[attr] = TAG_DEFAULT_ATTR_MAP[tagName][attr]
      }
    })
  }
}
function checkTagName(node, output) {
  var result = output.result
  var deps = output.deps
  var log = output.log

  var tagName = node.tagName
  var childNodes = node.childNodes || []
  var location = node.__location || {}

  // alias
  if (TAG_NAME_ALIAS_MAP[tagName]) {
    if (tagName !== 'img') { // FIXME: `parse5` autofixes image to img silently
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'NOTE: tag name `' + tagName + '` is autofixed to `' + TAG_NAME_ALIAS_MAP[tagName] + '`'
      })
    }
    tagName = TAG_NAME_ALIAS_MAP[tagName]
  }

  if (tagName === 'component') {
    var indexOfIs = -1
    if (node.attrs) {
      node.attrs.forEach(function (attr, index) {
        if (attr.name === 'is') {
          indexOfIs = index
          result.type = tagName = exp(attr.value)
        }
      })
    }
    if (indexOfIs > -1) {
      node.attrs.splice(indexOfIs, 1) // delete `is`
    }
    else {
      result.type = tagName = 'container'
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'WARNING: tag `component` should have an `is` attribute, otherwise it will be regarded as a `container`'
      })
    }
  }
  else {
    result.type = tagName
  }

  // deps
  if (deps.indexOf(tagName) < 0 && typeof tagName === 'string') { // FIXME: improve `require` to bundle dynamic binding components
    deps.push(tagName)
  }

  // parent (no any rules yet)

  // child (noChild, textContent)
  if (NO_CHILD_TAG_NAME_LIST.indexOf(tagName) >= 0) {
    if (childNodes.length > 0) {
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'ERROR: tag `' + tagName + '` should not have children'
      })
    }
  }
  if (TEXT_CONTENT_TAG_NAME_LIST.indexOf(tagName) >= 0) {
    if (childNodes.length > 1 || (childNodes[0] && childNodes[0].nodeName !== '#text')) {
      log.push({
        line: location.line || 1,
        column: location.col || 1,
        reason: 'ERROR: tag name `' + tagName + '` should just have one text node only'
      })
    }
  }

  // default attr
  if (TAG_DEFAULT_ATTR_MAP[tagName]) {
    Object.keys(TAG_DEFAULT_ATTR_MAP[tagName]).forEach(function (attr) {
      if (attr !== 'append') {
        result.attr = result.attr || {}
        result.attr[attr] = TAG_DEFAULT_ATTR_MAP[tagName][attr]
      }
      else {
        result[attr] = TAG_DEFAULT_ATTR_MAP[tagName][attr]
      }
    })
  }
}
function checkTagName ( node , output ) { var result = output . result var deps = output . deps var log = output . log var tagName = node . tagName var childNodes = node . childNodes || [ ] var location = node . __location || { } // alias if ( TAG_NAME_ALIAS_MAP [ tagName ] ) { if ( tagName !== 'img' ) { // FIXME: `parse5` autofixes image to img silently log . push ( { line : location . line || 1 , column : location . col || 1 , reason : 'NOTE: tag name `' + tagName + '` is autofixed to `' + TAG_NAME_ALIAS_MAP [ tagName ] + '`' } ) } tagName = TAG_NAME_ALIAS_MAP [ tagName ] } if ( tagName === 'component' ) { var indexOfIs = - 1 if ( node . attrs ) { node . attrs . forEach ( function ( attr , index ) { if ( attr . name === 'is' ) { indexOfIs = index result . type = tagName = exp ( attr . value ) } } ) } if ( indexOfIs > - 1 ) { node . attrs . splice ( indexOfIs , 1 ) // delete `is` } else { result . type = tagName = 'container' log . push ( { line : location . line || 1 , column : location . col || 1 , reason : 'WARNING: tag `component` should have an `is` attribute, otherwise it will be regarded as a `container`' } ) } } else { result . type = tagName } // deps if ( deps . indexOf ( tagName ) < 0 && typeof tagName === 'string' ) { // FIXME: improve `require` to bundle dynamic binding components deps . push ( tagName ) } // parent (no any rules yet) // child (noChild, textContent) if ( NO_CHILD_TAG_NAME_LIST . indexOf ( tagName ) >= 0 ) { if ( childNodes . length > 0 ) { log . push ( { line : location . line || 1 , column : location . col || 1 , reason : 'ERROR: tag `' + tagName + '` should not have children' } ) } } if ( TEXT_CONTENT_TAG_NAME_LIST . indexOf ( tagName ) >= 0 ) { if ( childNodes . length > 1 || ( childNodes [ 0 ] && childNodes [ 0 ] . nodeName !== '#text' ) ) { log . push ( { line : location . line || 1 , column : location . col || 1 , reason : 'ERROR: tag name `' + tagName + '` should just have one text node only' } ) } } // default attr if ( TAG_DEFAULT_ATTR_MAP [ tagName ] ) { Object . keys ( TAG_DEFAULT_ATTR_MAP [ tagName ] ) . forEach ( function ( attr ) { if ( attr !== 'append' ) { result . attr = result . attr || { } result . attr [ attr ] = TAG_DEFAULT_ATTR_MAP [ tagName ] [ attr ] } else { result [ attr ] = TAG_DEFAULT_ATTR_MAP [ tagName ] [ attr ] } } ) } }
tag name checking
- autofix alias
- append deps
- check parent requirements
- check children requirements
and the result, deps, log will be updated

@param  {Node} node
@param  {object} output{result, deps[], log[]}
tag name checking - autofix alias - append deps - check parent requirements - check children requirements and the result deps log will be updated