Repository: mozilla/nunjucks (js)

Issue:
"Invalid type: Is" when using "is defined"
When using "is defined", I'm getting "Template render error: assertType: invalid type: Is".

``` nunjucks
{% if content is defined %}
    {{ content }}
{% endif %}```

Full error output

```
Template render error: Template render error: assertType: invalid type: Is
    at Object._prettifyError (/Users/jonathan/testApp/node_modules/nunjucks/src/lib.js:35:11)
    at /Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:547:19
    at Template.root [as rootRenderFunc] (eval at _compile (/Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:22:3)
    at Template.render (/Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:540:10)
    at /Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:350:27
    at createTemplate (/Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:299:9)
    at handle (/Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:311:11)
    at /Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:323:9
    at next (/Users/jonathan/testApp/node_modules/nunjucks/src/lib.js:281:7)
    at Object.asyncIter (/Users/jonathan/testApp/node_modules/nunjucks/src/lib.js:287:3)
    at Environment.getTemplate (/Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:305:9)
    at Environment.render (/Users/jonathan/testApp/node_modules/nunjucks/src/environment.js:344:10)
    at Object.render (/Users/jonathan/testApp/node_modules/nunjucks/index.js:91:14)
    at Object.processStyles (/Users/jonathan/testApp/utils/css.js:220:27)
    at main (/Users/jonathan/testApp/main.js:16:33)
    at <anonymous>
```

I'm using Nunjucks 3.1.2

Pull request description:
Fixing "Invalid type: Is" error
## Summary

Proposed change:

Fixing "Template render error: assertType: invalid type: Is" error.

`is defined` support was added in https://github.com/mozilla/nunjucks/pull/1033

Closes #1110 .


## 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).
* [ ] [*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 11999e4..defc380 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@ Changelog
 =========
 
 * Add `forceescape` filter. Fixes [#782](https://github.com/mozilla/nunjucks/issues/782)
+* Fix "Invalid type: Is" error for `{% if value is defined %}. Fixes
+  [#1110](https://github.com/mozilla/nunjucks/issues/1110)
 
 3.1.2 (Feb 23 2018)
 -------------------
diff --git a/nunjucks/src/compiler.js b/nunjucks/src/compiler.js
index 03a3bc1..6c000fe 100644
--- a/nunjucks/src/compiler.js
+++ b/nunjucks/src/compiler.js
@@ -166,6 +166,7 @@ class Compiler extends Obj {
       nodes.Compare,
       nodes.InlineIf,
       nodes.In,
+      nodes.Is,
       nodes.And,
       nodes.Or,
       nodes.Not,


Test patch:
diff --git a/tests/tests.js b/tests/tests.js
index ccbb106..ace0842 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -39,6 +39,28 @@
       })).to.be('false');
     });
 
+    it('should support "is defined" in {% if %} expressions', function() {
+      expect(
+        render('{% if foo is defined %}defined{% else %}undefined{% endif %}',
+          {})
+      ).to.be('undefined');
+      expect(
+        render('{% if foo is defined %}defined{% else %}undefined{% endif %}',
+          {foo: null})
+      ).to.be('defined');
+    });
+
+    it('should support "is not defined" in {% if %} expressions', function() {
+      expect(
+        render('{% if foo is not defined %}undefined{% else %}defined{% endif %}',
+          {})
+      ).to.be('undefined');
+      expect(
+        render('{% if foo is not defined %}undefined{% else %}defined{% endif %}',
+          {foo: null})
+      ).to.be('defined');
+    });
+
     it('undefined should detect undefinedness', function() {
       expect(render('{{ foo is undefined }}')).to.be('true');
       expect(render('{{ foo is not undefined }}')).to.be('false');