handlebars-jaylinski 4.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/LICENSE +19 -0
  2. package/README.markdown +169 -0
  3. package/bin/.eslintrc.js +6 -0
  4. package/bin/handlebars +176 -0
  5. package/dist/amd/handlebars/base.js +106 -0
  6. package/dist/amd/handlebars/compiler/ast.js +31 -0
  7. package/dist/amd/handlebars/compiler/base.js +45 -0
  8. package/dist/amd/handlebars/compiler/code-gen.js +165 -0
  9. package/dist/amd/handlebars/compiler/compiler.js +562 -0
  10. package/dist/amd/handlebars/compiler/helpers.js +228 -0
  11. package/dist/amd/handlebars/compiler/javascript-compiler.js +1150 -0
  12. package/dist/amd/handlebars/compiler/parser.js +737 -0
  13. package/dist/amd/handlebars/compiler/printer.js +186 -0
  14. package/dist/amd/handlebars/compiler/visitor.js +138 -0
  15. package/dist/amd/handlebars/compiler/whitespace-control.js +219 -0
  16. package/dist/amd/handlebars/decorators/inline.js +25 -0
  17. package/dist/amd/handlebars/decorators.js +16 -0
  18. package/dist/amd/handlebars/exception.js +64 -0
  19. package/dist/amd/handlebars/helpers/block-helper-missing.js +35 -0
  20. package/dist/amd/handlebars/helpers/each.js +99 -0
  21. package/dist/amd/handlebars/helpers/helper-missing.js +22 -0
  22. package/dist/amd/handlebars/helpers/if.js +41 -0
  23. package/dist/amd/handlebars/helpers/log.js +24 -0
  24. package/dist/amd/handlebars/helpers/lookup.js +14 -0
  25. package/dist/amd/handlebars/helpers/with.js +38 -0
  26. package/dist/amd/handlebars/helpers.js +44 -0
  27. package/dist/amd/handlebars/internal/create-new-lookup-object.js +22 -0
  28. package/dist/amd/handlebars/internal/proto-access.js +71 -0
  29. package/dist/amd/handlebars/internal/wrapHelper.js +21 -0
  30. package/dist/amd/handlebars/logger.js +44 -0
  31. package/dist/amd/handlebars/no-conflict.js +28 -0
  32. package/dist/amd/handlebars/runtime.js +356 -0
  33. package/dist/amd/handlebars/safe-string.js +15 -0
  34. package/dist/amd/handlebars/utils.js +126 -0
  35. package/dist/amd/handlebars.js +52 -0
  36. package/dist/amd/handlebars.runtime.js +44 -0
  37. package/dist/amd/precompiler.js +314 -0
  38. package/dist/cjs/handlebars/base.js +116 -0
  39. package/dist/cjs/handlebars/compiler/ast.js +31 -0
  40. package/dist/cjs/handlebars/compiler/base.js +57 -0
  41. package/dist/cjs/handlebars/compiler/code-gen.js +168 -0
  42. package/dist/cjs/handlebars/compiler/compiler.js +566 -0
  43. package/dist/cjs/handlebars/compiler/helpers.js +228 -0
  44. package/dist/cjs/handlebars/compiler/javascript-compiler.js +1158 -0
  45. package/dist/cjs/handlebars/compiler/parser.js +737 -0
  46. package/dist/cjs/handlebars/compiler/printer.js +186 -0
  47. package/dist/cjs/handlebars/compiler/visitor.js +140 -0
  48. package/dist/cjs/handlebars/compiler/whitespace-control.js +221 -0
  49. package/dist/cjs/handlebars/decorators/inline.js +29 -0
  50. package/dist/cjs/handlebars/decorators.js +16 -0
  51. package/dist/cjs/handlebars/exception.js +64 -0
  52. package/dist/cjs/handlebars/helpers/block-helper-missing.js +39 -0
  53. package/dist/cjs/handlebars/helpers/each.js +104 -0
  54. package/dist/cjs/handlebars/helpers/helper-missing.js +25 -0
  55. package/dist/cjs/handlebars/helpers/if.js +46 -0
  56. package/dist/cjs/handlebars/helpers/log.js +26 -0
  57. package/dist/cjs/handlebars/helpers/lookup.js +16 -0
  58. package/dist/cjs/handlebars/helpers/with.js +43 -0
  59. package/dist/cjs/handlebars/helpers.js +56 -0
  60. package/dist/cjs/handlebars/internal/create-new-lookup-object.js +22 -0
  61. package/dist/cjs/handlebars/internal/proto-access.js +73 -0
  62. package/dist/cjs/handlebars/internal/wrapHelper.js +19 -0
  63. package/dist/cjs/handlebars/logger.js +47 -0
  64. package/dist/cjs/handlebars/no-conflict.js +30 -0
  65. package/dist/cjs/handlebars/runtime.js +372 -0
  66. package/dist/cjs/handlebars/safe-string.js +15 -0
  67. package/dist/cjs/handlebars/utils.js +124 -0
  68. package/dist/cjs/handlebars.js +66 -0
  69. package/dist/cjs/handlebars.runtime.js +66 -0
  70. package/dist/cjs/precompiler.js +328 -0
  71. package/dist/handlebars.amd.js +4639 -0
  72. package/dist/handlebars.amd.min.js +29 -0
  73. package/dist/handlebars.js +5972 -0
  74. package/dist/handlebars.min.js +29 -0
  75. package/dist/handlebars.runtime.amd.js +1302 -0
  76. package/dist/handlebars.runtime.amd.min.js +27 -0
  77. package/dist/handlebars.runtime.js +2563 -0
  78. package/dist/handlebars.runtime.min.js +27 -0
  79. package/lib/.eslintrc.js +8 -0
  80. package/lib/handlebars/base.js +94 -0
  81. package/lib/handlebars/compiler/ast.js +32 -0
  82. package/lib/handlebars/compiler/base.js +34 -0
  83. package/lib/handlebars/compiler/code-gen.js +171 -0
  84. package/lib/handlebars/compiler/compiler.js +594 -0
  85. package/lib/handlebars/compiler/helpers.js +219 -0
  86. package/lib/handlebars/compiler/javascript-compiler.js +1293 -0
  87. package/lib/handlebars/compiler/parser.js +622 -0
  88. package/lib/handlebars/compiler/printer.js +178 -0
  89. package/lib/handlebars/compiler/visitor.js +136 -0
  90. package/lib/handlebars/compiler/whitespace-control.js +234 -0
  91. package/lib/handlebars/decorators/inline.js +22 -0
  92. package/lib/handlebars/decorators.js +5 -0
  93. package/lib/handlebars/exception.js +68 -0
  94. package/lib/handlebars/helpers/block-helper-missing.js +35 -0
  95. package/lib/handlebars/helpers/each.js +101 -0
  96. package/lib/handlebars/helpers/helper-missing.js +15 -0
  97. package/lib/handlebars/helpers/if.js +33 -0
  98. package/lib/handlebars/helpers/log.js +19 -0
  99. package/lib/handlebars/helpers/lookup.js +9 -0
  100. package/lib/handlebars/helpers/with.js +39 -0
  101. package/lib/handlebars/helpers.js +26 -0
  102. package/lib/handlebars/internal/create-new-lookup-object.js +11 -0
  103. package/lib/handlebars/internal/proto-access.js +70 -0
  104. package/lib/handlebars/internal/wrapHelper.js +13 -0
  105. package/lib/handlebars/logger.js +39 -0
  106. package/lib/handlebars/no-conflict.js +23 -0
  107. package/lib/handlebars/runtime.js +450 -0
  108. package/lib/handlebars/safe-string.js +10 -0
  109. package/lib/handlebars/utils.js +116 -0
  110. package/lib/handlebars.js +46 -0
  111. package/lib/handlebars.runtime.js +37 -0
  112. package/lib/index.js +26 -0
  113. package/lib/precompiler.js +341 -0
  114. package/package.json +135 -0
  115. package/release-notes.md +1101 -0
  116. package/runtime.d.ts +5 -0
  117. package/runtime.js +3 -0
  118. package/types/index.d.ts +422 -0
@@ -0,0 +1,101 @@
1
+ import {
2
+ appendContextPath,
3
+ blockParams,
4
+ createFrame,
5
+ isArray,
6
+ isFunction
7
+ } from '../utils';
8
+ import Exception from '../exception';
9
+
10
+ export default function(instance) {
11
+ instance.registerHelper('each', function(context, options) {
12
+ if (!options) {
13
+ throw new Exception('Must pass iterator to #each');
14
+ }
15
+
16
+ let fn = options.fn,
17
+ inverse = options.inverse,
18
+ i = 0,
19
+ ret = '',
20
+ data,
21
+ contextPath;
22
+
23
+ if (options.data && options.ids) {
24
+ contextPath =
25
+ appendContextPath(options.data.contextPath, options.ids[0]) + '.';
26
+ }
27
+
28
+ if (isFunction(context)) {
29
+ context = context.call(this);
30
+ }
31
+
32
+ if (options.data) {
33
+ data = createFrame(options.data);
34
+ }
35
+
36
+ function execIteration(field, index, last) {
37
+ if (data) {
38
+ data.key = field;
39
+ data.index = index;
40
+ data.first = index === 0;
41
+ data.last = !!last;
42
+
43
+ if (contextPath) {
44
+ data.contextPath = contextPath + field;
45
+ }
46
+ }
47
+
48
+ ret =
49
+ ret +
50
+ fn(context[field], {
51
+ data: data,
52
+ blockParams: blockParams(
53
+ [context[field], field],
54
+ [contextPath + field, null]
55
+ )
56
+ });
57
+ }
58
+
59
+ if (context && typeof context === 'object') {
60
+ if (isArray(context)) {
61
+ for (let j = context.length; i < j; i++) {
62
+ if (i in context) {
63
+ execIteration(i, i, i === context.length - 1);
64
+ }
65
+ }
66
+ } else if (typeof Symbol === 'function' && context[Symbol.iterator]) {
67
+ const newContext = [];
68
+ const iterator = context[Symbol.iterator]();
69
+ for (let it = iterator.next(); !it.done; it = iterator.next()) {
70
+ newContext.push(it.value);
71
+ }
72
+ context = newContext;
73
+ for (let j = context.length; i < j; i++) {
74
+ execIteration(i, i, i === context.length - 1);
75
+ }
76
+ } else {
77
+ let priorKey;
78
+
79
+ Object.keys(context).forEach(key => {
80
+ // We're running the iterations one step out of sync so we can detect
81
+ // the last iteration without have to scan the object twice and create
82
+ // an itermediate keys array.
83
+ if (priorKey !== undefined) {
84
+ execIteration(priorKey, i - 1);
85
+ }
86
+ priorKey = key;
87
+ i++;
88
+ });
89
+ if (priorKey !== undefined) {
90
+ execIteration(priorKey, i - 1, true);
91
+ }
92
+ }
93
+ }
94
+
95
+ if (i === 0) {
96
+ ret = inverse(this);
97
+ }
98
+
99
+ return ret;
100
+ });
101
+ }
@@ -0,0 +1,15 @@
1
+ import Exception from '../exception';
2
+
3
+ export default function(instance) {
4
+ instance.registerHelper('helperMissing', function(/* [args, ]options */) {
5
+ if (arguments.length === 1) {
6
+ // A missing field in a {{foo}} construct.
7
+ return undefined;
8
+ } else {
9
+ // Someone is actually trying to call something, blow up.
10
+ throw new Exception(
11
+ 'Missing helper: "' + arguments[arguments.length - 1].name + '"'
12
+ );
13
+ }
14
+ });
15
+ }
@@ -0,0 +1,33 @@
1
+ import { isEmpty, isFunction } from '../utils';
2
+ import Exception from '../exception';
3
+
4
+ export default function(instance) {
5
+ instance.registerHelper('if', function(conditional, options) {
6
+ if (arguments.length != 2) {
7
+ throw new Exception('#if requires exactly one argument');
8
+ }
9
+ if (isFunction(conditional)) {
10
+ conditional = conditional.call(this);
11
+ }
12
+
13
+ // Default behavior is to render the positive path if the value is truthy and not empty.
14
+ // The `includeZero` option may be set to treat the condtional as purely not empty based on the
15
+ // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
16
+ if ((!options.hash.includeZero && !conditional) || isEmpty(conditional)) {
17
+ return options.inverse(this);
18
+ } else {
19
+ return options.fn(this);
20
+ }
21
+ });
22
+
23
+ instance.registerHelper('unless', function(conditional, options) {
24
+ if (arguments.length != 2) {
25
+ throw new Exception('#unless requires exactly one argument');
26
+ }
27
+ return instance.helpers['if'].call(this, conditional, {
28
+ fn: options.inverse,
29
+ inverse: options.fn,
30
+ hash: options.hash
31
+ });
32
+ });
33
+ }
@@ -0,0 +1,19 @@
1
+ export default function(instance) {
2
+ instance.registerHelper('log', function(/* message, options */) {
3
+ let args = [undefined],
4
+ options = arguments[arguments.length - 1];
5
+ for (let i = 0; i < arguments.length - 1; i++) {
6
+ args.push(arguments[i]);
7
+ }
8
+
9
+ let level = 1;
10
+ if (options.hash.level != null) {
11
+ level = options.hash.level;
12
+ } else if (options.data && options.data.level != null) {
13
+ level = options.data.level;
14
+ }
15
+ args[0] = level;
16
+
17
+ instance.log(...args);
18
+ });
19
+ }
@@ -0,0 +1,9 @@
1
+ export default function(instance) {
2
+ instance.registerHelper('lookup', function(obj, field, options) {
3
+ if (!obj) {
4
+ // Note for 5.0: Change to "obj == null" in 5.0
5
+ return obj;
6
+ }
7
+ return options.lookupProperty(obj, field);
8
+ });
9
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ appendContextPath,
3
+ blockParams,
4
+ createFrame,
5
+ isEmpty,
6
+ isFunction
7
+ } from '../utils';
8
+ import Exception from '../exception';
9
+
10
+ export default function(instance) {
11
+ instance.registerHelper('with', function(context, options) {
12
+ if (arguments.length != 2) {
13
+ throw new Exception('#with requires exactly one argument');
14
+ }
15
+ if (isFunction(context)) {
16
+ context = context.call(this);
17
+ }
18
+
19
+ let fn = options.fn;
20
+
21
+ if (!isEmpty(context)) {
22
+ let data = options.data;
23
+ if (options.data && options.ids) {
24
+ data = createFrame(options.data);
25
+ data.contextPath = appendContextPath(
26
+ options.data.contextPath,
27
+ options.ids[0]
28
+ );
29
+ }
30
+
31
+ return fn(context, {
32
+ data: data,
33
+ blockParams: blockParams([context], [data && data.contextPath])
34
+ });
35
+ } else {
36
+ return options.inverse(this);
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,26 @@
1
+ import registerBlockHelperMissing from './helpers/block-helper-missing';
2
+ import registerEach from './helpers/each';
3
+ import registerHelperMissing from './helpers/helper-missing';
4
+ import registerIf from './helpers/if';
5
+ import registerLog from './helpers/log';
6
+ import registerLookup from './helpers/lookup';
7
+ import registerWith from './helpers/with';
8
+
9
+ export function registerDefaultHelpers(instance) {
10
+ registerBlockHelperMissing(instance);
11
+ registerEach(instance);
12
+ registerHelperMissing(instance);
13
+ registerIf(instance);
14
+ registerLog(instance);
15
+ registerLookup(instance);
16
+ registerWith(instance);
17
+ }
18
+
19
+ export function moveHelperToHooks(instance, helperName, keepHelper) {
20
+ if (instance.helpers[helperName]) {
21
+ instance.hooks[helperName] = instance.helpers[helperName];
22
+ if (!keepHelper) {
23
+ delete instance.helpers[helperName];
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ import { extend } from '../utils';
2
+
3
+ /**
4
+ * Create a new object with "null"-prototype to avoid truthy results on prototype properties.
5
+ * The resulting object can be used with "object[property]" to check if a property exists
6
+ * @param {...object} sources a varargs parameter of source objects that will be merged
7
+ * @returns {object}
8
+ */
9
+ export function createNewLookupObject(...sources) {
10
+ return extend(Object.create(null), ...sources);
11
+ }
@@ -0,0 +1,70 @@
1
+ import { createNewLookupObject } from './create-new-lookup-object';
2
+ import logger from '../logger';
3
+
4
+ const loggedProperties = Object.create(null);
5
+
6
+ export function createProtoAccessControl(runtimeOptions) {
7
+ let defaultMethodWhiteList = Object.create(null);
8
+ defaultMethodWhiteList['constructor'] = false;
9
+ defaultMethodWhiteList['__defineGetter__'] = false;
10
+ defaultMethodWhiteList['__defineSetter__'] = false;
11
+ defaultMethodWhiteList['__lookupGetter__'] = false;
12
+
13
+ let defaultPropertyWhiteList = Object.create(null);
14
+ // eslint-disable-next-line no-proto
15
+ defaultPropertyWhiteList['__proto__'] = false;
16
+
17
+ return {
18
+ properties: {
19
+ whitelist: createNewLookupObject(
20
+ defaultPropertyWhiteList,
21
+ runtimeOptions.allowedProtoProperties
22
+ ),
23
+ defaultValue: runtimeOptions.allowProtoPropertiesByDefault
24
+ },
25
+ methods: {
26
+ whitelist: createNewLookupObject(
27
+ defaultMethodWhiteList,
28
+ runtimeOptions.allowedProtoMethods
29
+ ),
30
+ defaultValue: runtimeOptions.allowProtoMethodsByDefault
31
+ }
32
+ };
33
+ }
34
+
35
+ export function resultIsAllowed(result, protoAccessControl, propertyName) {
36
+ if (typeof result === 'function') {
37
+ return checkWhiteList(protoAccessControl.methods, propertyName);
38
+ } else {
39
+ return checkWhiteList(protoAccessControl.properties, propertyName);
40
+ }
41
+ }
42
+
43
+ function checkWhiteList(protoAccessControlForType, propertyName) {
44
+ if (protoAccessControlForType.whitelist[propertyName] !== undefined) {
45
+ return protoAccessControlForType.whitelist[propertyName] === true;
46
+ }
47
+ if (protoAccessControlForType.defaultValue !== undefined) {
48
+ return protoAccessControlForType.defaultValue;
49
+ }
50
+ logUnexpecedPropertyAccessOnce(propertyName);
51
+ return false;
52
+ }
53
+
54
+ function logUnexpecedPropertyAccessOnce(propertyName) {
55
+ if (loggedProperties[propertyName] !== true) {
56
+ loggedProperties[propertyName] = true;
57
+ logger.log(
58
+ 'error',
59
+ `Handlebars: Access has been denied to resolve the property "${propertyName}" because it is not an "own property" of its parent.\n` +
60
+ `You can add a runtime option to disable the check or this warning:\n` +
61
+ `See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details`
62
+ );
63
+ }
64
+ }
65
+
66
+ export function resetLoggedProperties() {
67
+ Object.keys(loggedProperties).forEach(propertyName => {
68
+ delete loggedProperties[propertyName];
69
+ });
70
+ }
@@ -0,0 +1,13 @@
1
+ export function wrapHelper(helper, transformOptionsFn) {
2
+ if (typeof helper !== 'function') {
3
+ // This should not happen, but apparently it does in https://github.com/wycats/handlebars.js/issues/1639
4
+ // We try to make the wrapper least-invasive by not wrapping it, if the helper is not a function.
5
+ return helper;
6
+ }
7
+ let wrapper = function(/* dynamic arguments */) {
8
+ const options = arguments[arguments.length - 1];
9
+ arguments[arguments.length - 1] = transformOptionsFn(options);
10
+ return helper.apply(this, arguments);
11
+ };
12
+ return wrapper;
13
+ }
@@ -0,0 +1,39 @@
1
+ import { indexOf } from './utils';
2
+
3
+ let logger = {
4
+ methodMap: ['debug', 'info', 'warn', 'error'],
5
+ level: 'info',
6
+
7
+ // Maps a given level value to the `methodMap` indexes above.
8
+ lookupLevel: function(level) {
9
+ if (typeof level === 'string') {
10
+ let levelMap = indexOf(logger.methodMap, level.toLowerCase());
11
+ if (levelMap >= 0) {
12
+ level = levelMap;
13
+ } else {
14
+ level = parseInt(level, 10);
15
+ }
16
+ }
17
+
18
+ return level;
19
+ },
20
+
21
+ // Can be overridden in the host environment
22
+ log: function(level, ...message) {
23
+ level = logger.lookupLevel(level);
24
+
25
+ if (
26
+ typeof console !== 'undefined' &&
27
+ logger.lookupLevel(logger.level) <= level
28
+ ) {
29
+ let method = logger.methodMap[level];
30
+ // eslint-disable-next-line no-console
31
+ if (!console[method]) {
32
+ method = 'log';
33
+ }
34
+ console[method](...message); // eslint-disable-line no-console
35
+ }
36
+ }
37
+ };
38
+
39
+ export default logger;
@@ -0,0 +1,23 @@
1
+ /* global globalThis */
2
+ export default function(Handlebars) {
3
+ /* istanbul ignore next */
4
+ // https://mathiasbynens.be/notes/globalthis
5
+ (function() {
6
+ if (typeof globalThis === 'object') return;
7
+ Object.prototype.__defineGetter__('__magic__', function() {
8
+ return this;
9
+ });
10
+ __magic__.globalThis = __magic__; // eslint-disable-line no-undef
11
+ delete Object.prototype.__magic__;
12
+ })();
13
+
14
+ const $Handlebars = globalThis.Handlebars;
15
+
16
+ /* istanbul ignore next */
17
+ Handlebars.noConflict = function() {
18
+ if (globalThis.Handlebars === Handlebars) {
19
+ globalThis.Handlebars = $Handlebars;
20
+ }
21
+ return Handlebars;
22
+ };
23
+ }