From 57c671263148554fbfbd22cadce3f6c85e4d2515 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sat, 19 Oct 2019 21:45:00 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Correct=C2=A0error=C2=A0message=20when?= =?UTF-8?q?=C2=A0`async=C2=A0!=3D=C2=A0true`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ejs.js | 4 ++-- test/ejs.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/ejs.js b/lib/ejs.js index 0bdabbd0..449d5da9 100755 --- a/lib/ejs.js +++ b/lib/ejs.js @@ -658,9 +658,9 @@ Template.prototype = { e.message += ' while compiling ejs\n\n'; e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n'; e.message += 'https://github.com/RyanZim/EJS-Lint'; - if (!e.async) { + if (!opts.async) { e.message += '\n'; - e.message += 'Or, if you meant to create an async function, pass async: true as an option.'; + e.message += 'Or, if you meant to create an async function, pass `async: true` as an option.'; } } throw e; diff --git a/test/ejs.js b/test/ejs.js index 7daef60c..795fc6d0 100755 --- a/test/ejs.js +++ b/test/ejs.js @@ -183,6 +183,32 @@ suite('ejs.compile(str, options)', function () { done(); }); }); + + test('Non-async error message mentions `async: true`', function (done) { + try { + eval('(async function() {})'); + } catch (e) { + if (e instanceof SyntaxError) { + done(); + return; + } else { + throw e; + } + } + + try { + ejs.compile('<%= await "Hi" %>'); + } + catch (err) { + if (err instanceof SyntaxError) { + assert.ok(err.message.indexOf('async: true') > -1); + return done(); + } else { + throw err; + } + } + throw new Error('no error reported when there should be'); + }); }); suite('client mode', function () {