Repository: mozilla/nunjucks
Pull request #1171 (2018-12-04 11:56:34)

Fixes for replace example
Replace example set a string variable but was never used, fixed to put replace example in line with following and preceding replace examples

## Summary

Proposed change:

<!--
	Please replace this with a human-friendly description of your proposed change.
	* If you have multiple changes, try to split them into separate PRs.
	* If this change closes an issue, please write "Closes #{number}".
-->

Closes # .


## Checklist

I've completed the checklist below to ensure I didn't forget anything. This makes reviewing this PR as easy as possible for the maintainers. And it gets this change released as soon as possible.

* [x] Proposed change helps towards [*purpose of this project*](https://github.com/mozilla/nunjucks/blob/master/CONTRIBUTING.md#purpose).
* [x] [*Documentation*](https://github.com/mozilla/nunjucks/tree/master/docs/) is added / updated to describe proposed change.
* [x] [*Tests*](https://github.com/mozilla/nunjucks/tree/master/tests) are added / updated to cover proposed change.
* [x] [*Changelog*](https://github.com/mozilla/nunjucks/blob/master/CHANGELOG.md) has an entry for proposed change (if user-facing fix or feature).

<!-- Tick of items by replacing `[ ]` by `[x]` -->


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 169e41f..9c065bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,21 @@
 Changelog
 =========
 
+3.1.6 (unreleased)
+------------------
+
+* Fix bug where exceptions were silently swallowed with synchronous render.
+  Fixes [#678](https://github.com/mozilla/nunjucks/issues/678),
+  [#1116](https://github.com/mozilla/nunjucks/issues/1116),
+  [#1127](https://github.com/mozilla/nunjucks/issues/1127), and
+  [#1164](https://github.com/mozilla/nunjucks/issues/1164)
+
+3.1.5 (Dec 13 2018)
+-------------------
+
+* Fix engine dependency version for Node versions > 11.1.0;
+  Fixes [#1168](https://github.com/mozilla/nunjucks/issues/1168).
+
 3.1.4 (Nov 9 2018)
 ------------------
 
diff --git a/docs/templating.md b/docs/templating.md
index bdbc212..c02e72a 100644
--- a/docs/templating.md
+++ b/docs/templating.md
@@ -43,6 +43,7 @@ Plugins are available in various editors to support the `jinja` syntax highlight
 * brackets <https://github.com/axelboc/nunjucks-brackets>
 * sublime <https://github.com/mogga/sublime-nunjucks/blob/master/Nunjucks.tmLanguage>
 * emacs <http://web-mode.org>
+* vscode <https://github.com/ronnidc/vscode-nunjucks>
 
 ## Variables
 
@@ -1435,13 +1436,13 @@ and replacing them surrounding an item:
 
 ```jinja
 {% set letters = aaabbbccc%}
-{{ "letters" | replace("", ".") }}
+{{ letters | replace("", ".") }}
 ```
 
 **Output**
 
 ```jinja
-.l.e.t.t.e.r.s.
+.a.a.a.b.b.b.c.c.c.
 
 ```
 
diff --git a/nunjucks/src/environment.js b/nunjucks/src/environment.js
index e7fd163..bb1c3b9 100644
--- a/nunjucks/src/environment.js
+++ b/nunjucks/src/environment.js
@@ -468,7 +468,11 @@ class Template extends Obj {
     this.rootRenderFunc(this.env, context, frame, globalRuntime, (err, res) => {
       if (didError) {
         // prevent multiple calls to cb
-        return;
+        if (cb) {
+          return;
+        } else {
+          throw err;
+        }
       }
       if (err) {
         err = lib._prettifyError(this.path, this.env.opts.dev, err);
diff --git a/package.json b/package.json
index 3b7e0f2..6378dcf 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,11 @@
 {
   "name": "nunjucks",
   "description": "A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)",
-  "version": "3.1.4",
+  "version": "3.1.6",
   "author": "James Long <longster@gmail.com>",
   "dependencies": {
     "a-sync-waterfall": "^1.0.0",
     "asap": "^2.0.3",
-    "postinstall-build": "^5.0.1",
     "yargs": "^3.32.0"
   },
   "browser": "./browser/nunjucks.js",
@@ -63,7 +62,7 @@
     "babel-register": "@babel/register"
   },
   "engines": {
-    "node": ">= 6.9.0 <= 11.1.0"
+    "node": ">= 6.9.0"
   },
   "scripts": {
     "build:transpile": "babel nunjucks --out-dir .",
@@ -72,7 +71,7 @@
     "codecov": "codecov",
     "mocha": "mocha -R spec tests",
     "lint": "eslint nunjucks scripts tests",
-    "postinstall": "node postinstall-build.js src",
+    "prepare": "npm run build",
     "test:instrument": "cross-env NODE_ENV=test scripts/bundle.js",
     "test:runner": "cross-env NODE_ENV=test scripts/testrunner.js",
     "test": "npm run lint && npm run test:instrument && npm run test:runner"
diff --git a/postinstall-build.js b/postinstall-build.js
deleted file mode 100755
index 010954f..0000000
--- a/postinstall-build.js
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-require('postinstall-build/index')();
-


Test patch:
diff --git a/tests/compiler.js b/tests/compiler.js
index d6b590d..a282ecc 100644
--- a/tests/compiler.js
+++ b/tests/compiler.js
@@ -795,6 +795,14 @@
     });
 
     if (!isSlim) {
+      it('should throw exceptions when called synchronously', function() {
+        var tmpl = new Template('{% from "doesnotexist" import foo %}');
+        function templateRender() {
+          tmpl.render();
+        }
+        expect(templateRender).to.throwException(/template not found: doesnotexist/);
+      });
+
       it('should include error line in raised TemplateError', function(done) {
         var tmplStr = [
           '{% set items = ["a", "b",, "c"] %}',
diff --git a/tests/core.js b/tests/core.js
index 948f589..56c2406 100644
--- a/tests/core.js
+++ b/tests/core.js
@@ -20,7 +20,7 @@
 
   function rmdir(dirPath) {
     fs.emptyDirSync(dirPath);
-    fs.rmdir(dirPath);
+    fs.rmdirSync(dirPath);
   }
 
   describe('nunjucks.configure', function() {