|
1 | 1 | const { registerCoreHelpers } = require('./helpers')
|
2 | 2 |
|
| 3 | +const isPromise = (obj) => !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function' |
| 4 | + |
3 | 5 | function asyncHelpers(hbs) {
|
4 | 6 |
|
5 | 7 | const handlebars = hbs.create(),
|
@@ -40,18 +42,27 @@ function asyncHelpers(hbs) {
|
40 | 42 | handlebars.JavaScriptCompiler = asyncCompiler
|
41 | 43 |
|
42 | 44 | const _compile = handlebars.compile,
|
43 |
| - _template = handlebars.VM.template |
| 45 | + _template = handlebars.VM.template, |
| 46 | + _escapeExpression = handlebars.escapeExpression, |
| 47 | + escapeExpression = function(value) { |
| 48 | + if(isPromise(value)) { |
| 49 | + return value.then((v) => _escapeExpression(v)) |
| 50 | + } |
| 51 | + return _escapeExpression(value) |
| 52 | + } |
| 53 | + |
44 | 54 | handlebars.template = function(spec) {
|
45 | 55 | spec.main_d = (prog, props, container, depth, data, blockParams, depths) => async(context) => {
|
46 | 56 | // const main = await spec.main
|
| 57 | + container.escapeExpression = escapeExpression |
47 | 58 | const v = spec.main(container, context, container.helpers, container.partials, data, blockParams, depths)
|
48 | 59 | return v
|
49 | 60 | }
|
50 | 61 | return _template(spec, handlebars)
|
51 | 62 | }
|
52 | 63 |
|
53 | 64 | handlebars.compile = function(template, options) {
|
54 |
| - const compiled = _compile.apply(handlebars, [template, { ...options, noEscape: true }]) |
| 65 | + const compiled = _compile.apply(handlebars, [template, { ...options }]) |
55 | 66 |
|
56 | 67 | return function(context, execOptions) {
|
57 | 68 | context = context || {}
|
|
0 commit comments