import Vue, { mergeData } from '../vue'
import { NAME_ICON } from '../constants/components'
import { RX_ICON_PREFIX } from '../constants/regex'
import { pascalCase, trim } from '../utils/string'
import { BIconBlank } from './icons'
import { commonIconProps } from './helpers/icon-base'

const findIconComponent = (parent, iconName) => {
  if (!parent) {
    return null
  }
  const components = (parent.$options || {}).components
  const iconComponent = components[iconName]
  return iconComponent || findIconComponent(parent.$parent, iconName)
}

// Helper BIcon component
// Requires the requested icon component to be installed
export const BIcon = /*#__PURE__*/ Vue.extend({
  name: NAME_ICON,
  functional: true,
  props: {
    icon: {
      type: String,
      default: null
    },
    ...commonIconProps,
    stacked: {
      type: Boolean,
      default: false
    }
  },
  render(h, { data, props, parent }) {
    const icon = pascalCase(trim(props.icon || '')).replace(RX_ICON_PREFIX, '')

    // If parent context exists, we check to see if the icon has been registered
    // either locally in the parent component, or globally at the `$root` level
    // If not registered, we render a blank icon
    return h(
      icon ? findIconComponent(parent, `BIcon${icon}`) || BIconBlank : BIconBlank,
      mergeData(data, { props: { ...props, icon: null } })
    )
  }
})

@@ -307,22 +307,19 @@
 nent = (
-parent
+ctx
 , iconNa
@@ -334,22 +334,19 @@
 %0A  if (!
-parent
+ctx
 ) %7B%0A    
@@ -383,22 +383,19 @@
 ents = (
-parent
+ctx
 .$option
@@ -503,22 +503,19 @@
 mponent(
-parent
+ctx
 .$parent

Update icon.js