1import { createFrame, extend, toString } from './utils';
2import Exception from './exception';
3import { registerDefaultHelpers } from './helpers';
4import { registerDefaultDecorators } from './decorators';
5import logger from './logger';
6import { resetLoggedProperties } from './internal/proto-access';
7
8export const VERSION = '4.7.8';
9export const COMPILER_REVISION = 8;
10export const LAST_COMPATIBLE_COMPILER_REVISION = 7;
11
12export const REVISION_CHANGES = {
13  1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
14  2: '== 1.0.0-rc.3',
15  3: '== 1.0.0-rc.4',
16  4: '== 1.x.x',
17  5: '== 2.0.0-alpha.x',
18  6: '>= 2.0.0-beta.1',
19  7: '>= 4.0.0 <4.3.0',
20  8: '>= 4.3.0'
21};
22
23const objectType = '[object Object]';
24
25export function HandlebarsEnvironment(helpers, partials, decorators) {
26  this.helpers = helpers || {};
27  this.partials = partials || {};
28  this.decorators = decorators || {};
29
30  registerDefaultHelpers(this);
31  registerDefaultDecorators(this);
32}
33
34HandlebarsEnvironment.prototype = {
35  constructor: HandlebarsEnvironment,
36
37  logger: logger,
38  log: logger.log,
39
40  registerHelper: function(name, fn) {
41    if (toString.call(name) === objectType) {
42      if (fn) {
43        throw new Exception('Arg not supported with multiple helpers');
44      }
45      extend(this.helpers, name);
46    } else {
47      this.helpers[name] = fn;
48    }
49  },
50  unregisterHelper: function(name) {
51    delete this.helpers[name];
52  },
53
54  registerPartial: function(name, partial) {
55    if (toString.call(name) === objectType) {
56      extend(this.partials, name);
57    } else {
58      if (typeof partial === 'undefined') {
59        throw new Exception(
60          `Attempting to register a partial called "${name}" as undefined`
61        );
62      }
63      this.partials[name] = partial;
64    }
65  },
66  unregisterPartial: function(name) {
67    delete this.partials[name];
68  },
69
70  registerDecorator: function(name, fn) {
71    if (toString.call(name) === objectType) {
72      if (fn) {
73        throw new Exception('Arg not supported with multiple decorators');
74      }
75      extend(this.decorators, name);
76    } else {
77      this.decorators[name] = fn;
78    }
79  },
80  unregisterDecorator: function(name) {
81    delete this.decorators[name];
82  },
83  /**
84   * Reset the memory of illegal property accesses that have already been logged.
85   * @deprecated should only be used in handlebars test-cases
86   */
87  resetLoggedPropertyAccesses() {
88    resetLoggedProperties();
89  }
90};
91
92export let log = logger.log;
93
94export { createFrame, logger };
95