<commit_before>/**
 * Helpers for dynamically creating and patching component templates.
 *
 * The [ShadowTemplateMixin](ShadowTemplateMixin) lets you define a component
 * template that will be used to popuplate the shadow subtree of new component
 * instances. These helpers, especially the [html](#html) function, are intended
 * to simplify the creation of such templates.
 *
 * In particular, these helpers can be useful in [patching
 * templates](customizing#template-patching) inherited from a base class.
 *
 * Some of these functions take _descriptors_ that can either be a class, a tag
 * name, or an HTML template. These are generally used to fill specific roles in
 * an element's template; see [element roles](customizing#element-part-types).
 *
 * @module template
 */

// Used by registerCustomElement.
const mapBaseTagToCount = new Map();

/**
 * Create an element from a role descriptor (a component class constructor or
 * an HTML tag name).
 *
 * If the descriptor is an HTML template, and the resulting document fragment
 * contains a single top-level node, that node is returned directly (instead of
 * the fragment).
 *
 * @param {PartDescriptor} descriptor - the descriptor that will be used to
 * create the element
 * @returns {Element} the new element
 */
export function createElement(descriptor) {
  if (typeof descriptor === "function") {
    // Instantiable component class constructor
    let element;
    try {
      element = new descriptor();
    } catch (e) {
      if (e.name === "TypeError") {
        // Most likely this error results from the fact that the indicated
        // component class hasn't been registered. Register it now with a random
        // name and try again.
        registerCustomElement(descriptor);
        element = new descriptor();
      } else {
        // The exception was for some other reason.
        throw e;
      }
    }
    return element;
    // @ts-ignore
  } else if (descriptor instanceof HTMLTemplateElement) {
    // Template
    /* eslint-disable no-console */
    console.warn(
      "Deprecation warning: template.createElement and template.transmute will soon stop accepting an HTMLTemplateElement as a part descriptor."
    );
    const fragment = document.importNode(descriptor.content, true);
    // @ts-ignore
    return fragment.children.length === 1 ? fragment.children[0] : fragment;
  } else {<commit_msg>Remove deprecated support for an HTMLTemplateElement as a PartDescriptor.<commit_after>/**
 * Helpers for dynamically creating and patching component templates.
 *
 * The [ShadowTemplateMixin](ShadowTemplateMixin) lets you define a component
 * template that will be used to popuplate the shadow subtree of new component
 * instances. These helpers, especially the [html](#html) function, are intended
 * to simplify the creation of such templates.
 *
 * In particular, these helpers can be useful in [patching
 * templates](customizing#template-patching) inherited from a base class.
 *
 * Some of these functions take _descriptors_ that can either be a class, a tag
 * name, or an HTML template. These are generally used to fill specific roles in
 * an element's template; see [element roles](customizing#element-part-types).
 *
 * @module template
 */

// Used by registerCustomElement.
const mapBaseTagToCount = new Map();

/**
 * Create an element from a role descriptor (a component class constructor or
 * an HTML tag name).
 *
 * If the descriptor is an HTML template, and the resulting document fragment
 * contains a single top-level node, that node is returned directly (instead of
 * the fragment).
 *
 * @param {PartDescriptor} descriptor - the descriptor that will be used to
 * create the element
 * @returns {Element} the new element
 */
export function createElement(descriptor) {
  if (typeof descriptor === "function") {
    // Instantiable component class constructor
    let element;
    try {
      element = new descriptor();
    } catch (e) {
      if (e.name === "TypeError") {
        // Most likely this error results from the fact that the indicated
        // component class hasn't been registered. Register it now with a random
        // name and try again.
        registerCustomElement(descriptor);
        element = new descriptor();
      } else {
        // The exception was for some other reason.
        throw e;
      }
    }
    return element;
    // @ts-ignore
  } else {
{'fraction_non_alphanumeric': 0.08271017448447768, 'fraction_numerical': 0.00045320643553138455, 'mean_word_length': 3.2979552093476143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3058760', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1079, 'n_words': 500}