renderCustomElement method

void renderCustomElement(
  1. Element element,
  2. CodeBuffer buffer,
  3. SymbolTable scope,
  4. bool html5,
)

Implementation

void renderCustomElement(
    Element element, CodeBuffer buffer, SymbolTable scope, bool html5) {
  var template = scope.resolve(customElementName(element.tagName.name))!.value
      as RegularElement?;
  var renderAs = element.getAttribute('as')?.value?.compute(scope);
  var attrs = element.attributes.where((a) => a.name != 'as');

  for (var attribute in attrs) {
    if (attribute.name.startsWith('@')) {
      scope.create(attribute.name.substring(1),
          value: attribute.value?.compute(scope), constant: true);
    }
  }

  if (renderAs == false) {
    for (var i = 0; i < template!.children.length; i++) {
      var child = template.children.elementAt(i);
      renderElementChild(
          element, child, buffer, scope, html5, i, element.children.length);
    }
  } else {
    var tagName = renderAs?.toString() ?? 'div';

    var syntheticElement = RegularElement(
        template!.lt,
        SyntheticIdentifier(tagName),
        element.attributes
            .where((a) => a.name != 'as' && !a.name.startsWith('@')),
        template.gt,
        template.children,
        template.lt2,
        template.slash,
        SyntheticIdentifier(tagName),
        template.gt2);

    renderElement(syntheticElement, buffer, scope, html5);
  }
}