<commit_before>/**
 * Provides a high level wrapper around the Template/Compiler.
 *
 * @author  <NAME>
 * @copyright  2001-2019 WoltLab GmbH
 * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @module  WoltLabSuite/Core/Template
 */

import * as Core from "./Core";
import * as I18nPlural from "./I18n/Plural";
import * as LanguageStore from "./Language/Store";
import * as StringUtil from "./StringUtil";
import { compile, CompiledTemplate } from "./Template/Compiler";

// @todo: still required?
// work around bug in AMD module generation of Jison
/*function Parser() {
  this.yy = {};
}

Parser.prototype = parser;
parser.Parser = Parser;
parser = new Parser();*/

class Template {
  private compiled: CompiledTemplate;

  constructor(template: string) {
    try {
      this.compiled = compile(template);
    } catch (e) {
      console.debug(e.message);
      throw e;
    }
  }

  /**
   * Evaluates the Template using the given parameters.
   */
  fetch(v: object): string {
    return this.compiled(StringUtil, LanguageStore, I18nPlural, v);
  }
}

Object.defineProperty(Template, "callbacks", {
  enumerable: false,
  configurable: false,
  get: function () {
    throw new Error("WCF.Template.callbacks is no longer supported");
  },
  set: function (_value) {
    throw new Error("WCF.Template.callbacks is no longer supported");
  },
});

Core.enableLegacyInheritance(Template);

export = Template;
<commit_msg>Mark Core/Template#compiled as readonly<commit_after>/**
 * Provides a high level wrapper around the Template/Compiler.
 *
 * @author  <NAME>
 * @copyright  2001-2019 WoltLab GmbH
 * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @module  WoltLabSuite/Core/Template
 */

import * as Core from "./Core";
import * as I18nPlural from "./I18n/Plural";
import * as LanguageStore from "./Language/Store";
import * as StringUtil from "./StringUtil";
import { compile, CompiledTemplate } from "./Template/Compiler";

// @todo: still required?
// work around bug in AMD module generation of Jison
/*function Parser() {
  this.yy = {};
}

Parser.prototype = parser;
parser.Parser = Parser;
parser = new Parser();*/

class Template {
  private readonly compiled: CompiledTemplate;

  constructor(template: string) {
    try {
      this.compiled = compile(template);
    } catch (e) {
      console.debug(e.message);
      throw e;
    }
  }

  /**
   * Evaluates the Template using the given parameters.
   */
  fetch(v: object): string {
    return this.compiled(StringUtil, LanguageStore, I18nPlural, v);
  }
}

Object.defineProperty(Template, "callbacks", {
  enumerable: false,
  configurable: false,
  get: function () {
    throw new Error("WCF.Template.callbacks is no longer supported");
  },
  set: function (_value) {
    throw new Error("WCF.Template.callbacks is no longer supported");
  },
});

Core.enableLegacyInheritance(Template);

export = Template;

{'fraction_non_alphanumeric': 0.1294867494129487, 'fraction_numerical': 0.009392821200939282, 'mean_word_length': 3.6739811912225706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6938509', 'n_tokens_mistral': 934, 'n_tokens_neox': 894, 'n_words': 262}