From be2ebd2dc55e89b601d87e2f964a53f9551ca698 Mon Sep 17 00:00:00 2001 From: N247S Date: Tue, 3 Jan 2023 22:26:12 +0100 Subject: [PATCH] Added async handling of the `includer` --- lib/ejs.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ejs.js b/lib/ejs.js index 65590eae..9145b219 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -872,11 +872,19 @@ Template.prototype = { break; // Exec, esc, and output case Template.modes.ESCAPED: - this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n'; + if(this.opts.async) { + this.source += ' ; __append(escapeFn(await Promise.resolve(' + stripSemi(line) + ')))' + '\n'; + } else { + this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n'; + } break; // Exec and output case Template.modes.RAW: - this.source += ' ; __append(' + stripSemi(line) + ')' + '\n'; + if(this.opts.async) { + this.source += ' ; __append(await Promise.resolve(' + stripSemi(line) + '))' + '\n'; + } else { + this.source += ' ; __append(' + stripSemi(line) + ')' + '\n'; + } break; case Template.modes.COMMENT: // Do nothing