Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mozilla/nunjucks
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b045b8759988eea7a2d2f0ffbd86c67cddeca527
Choose a base ref
...
head repository: mozilla/nunjucks
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 53d1223bb1de0a3367a8bf13cb6438ad9db32b1b
Choose a head ref
Loading
Showing with 16,247 additions and 40,025 deletions.
  1. +19 −0 .babelrc
  2. 0 .jshintignore → .eslintignore
  3. +52 −0 .eslintrc.js
  4. +6 −0 .gitattributes
  5. +23 −0 .github/PULL_REQUEST_TEMPLATE.md
  6. +10 −1 .gitignore
  7. +0 −31 .jshintrc
  8. +3 −0 .npmignore
  9. +10 −6 .travis.yml
  10. +197 −1 CHANGELOG.md
  11. +15 −0 CODE_OF_CONDUCT.md
  12. +40 −17 CONTRIBUTING.md
  13. +25 −6 README.md
  14. +5 −6 appveyor.yml
  15. +0 −8 bin/bundle
  16. +0 −88 bin/bundle.js
  17. +37 −55 bin/precompile
  18. +3 −2 bower.json
  19. +0 −2,678 browser/nunjucks-slim.js
  20. +0 −2 browser/nunjucks-slim.min.js
  21. +0 −6,330 browser/nunjucks.js
  22. +0 −4 browser/nunjucks.min.js
  23. +2 −0 codecov.yml
  24. +2 −2 docs/README.md
  25. +2 −1 docs/_config.yml
  26. +3 −1 docs/_layouts/page.html
  27. +60 −13 docs/api.md
  28. +12 −12 docs/cn/api.md
  29. +2 −2 docs/cn/getting-started.md
  30. +67 −27 docs/cn/templating.md
  31. +10 −1 docs/css/app.css
  32. +12 −2 docs/faq.md
  33. +45 −8 docs/fr/api.md
  34. +2 −1 docs/fr/faq.md
  35. +16 −12 docs/fr/getting-started.md
  36. +1,054 −111 docs/fr/templating.md
  37. +16 −0 docs/getting-started.md
  38. BIN docs/img/favicon.png
  39. +1 −30 docs/index.html
  40. +994 −74 docs/templating.md
  41. +0 −86 index.js
  42. +88 −0 nunjucks/index.js
  43. +1,200 −0 nunjucks/src/compiler.js
  44. +589 −0 nunjucks/src/environment.js
  45. +24 −0 nunjucks/src/express-app.js
  46. +613 −0 nunjucks/src/filters.js
  47. +73 −0 nunjucks/src/globals.js
  48. +305 −0 nunjucks/src/jinja-compat.js
  49. +539 −0 nunjucks/src/lexer.js
  50. +347 −0 nunjucks/src/lib.js
  51. +14 −0 nunjucks/src/loader.js
  52. 0 { → nunjucks}/src/loaders.js
  53. +150 −0 nunjucks/src/node-loaders.js
  54. +270 −0 nunjucks/src/nodes.js
  55. +85 −0 nunjucks/src/object.js
  56. +1,368 −0 nunjucks/src/parser.js
  57. +24 −0 nunjucks/src/precompile-global.js
  58. +134 −0 nunjucks/src/precompile.js
  59. +27 −0 nunjucks/src/precompiled-loader.js
  60. +380 −0 nunjucks/src/runtime.js
  61. +290 −0 nunjucks/src/tests.js
  62. +217 −0 nunjucks/src/transformer.js
  63. +95 −0 nunjucks/src/web-loaders.js
  64. +67 −12 package.json
  65. +3 −1 {tests/express-sample → samples/express}/js/app.js
  66. +48 −0 samples/express/js/extensions.js
  67. +37 −0 samples/express/main.js
  68. +28 −0 samples/express/pre.js
  69. +1 −1 {tests/express-sample → samples/express}/views/about.html
  70. 0 {tests/express-sample → samples/express}/views/base.html
  71. 0 {tests/express-sample → samples/express}/views/import-context-set.html
  72. +7 −0 samples/express/views/index.html
  73. 0 {tests/express-sample → samples/express}/views/item-base.html
  74. +1 −1 {tests/express-sample → samples/express}/views/item.html
  75. 0 {tests/express-sample → samples/express}/views/set.html
  76. +136 −0 scripts/bundle.js
  77. +17 −0 scripts/lib/arrow-function-coverage-fix.js
  78. +10 −0 scripts/lib/is-main-module.js
  79. +57 −0 scripts/lib/mocha-phantomjs.js
  80. +21 −0 scripts/lib/precompile.js
  81. +71 −0 scripts/lib/runtests.js
  82. +27 −0 scripts/lib/static-server.js
  83. +40 −0 scripts/lib/utils.js
  84. +36 −0 scripts/testrunner.js
  85. +0 −1,179 src/compiler.js
  86. +0 −589 src/environment.js
  87. +0 −577 src/filters.js
  88. +0 −79 src/globals.js
  89. +0 −156 src/jinja-compat.js
  90. +0 −514 src/lexer.js
  91. +0 −299 src/lib.js
  92. +0 −33 src/loader.js
  93. +0 −85 src/node-loaders.js
  94. +0 −303 src/nodes.js
  95. +0 −64 src/object.js
  96. +0 −1,284 src/parser.js
  97. +0 −24 src/precompile-global.js
  98. +0 −137 src/precompile.js
  99. +0 −22 src/precompiled-loader.js
  100. +0 −362 src/runtime.js
  101. +0 −239 src/transformer.js
  102. +0 −96 src/web-loaders.js
  103. +23 −0 tests/.eslintrc.js
  104. +93 −52 tests/api.js
  105. +0 −1,284 tests/browser/expect.js
  106. +17 −4 tests/browser/index.html
  107. +0 −246 tests/browser/mocha.css
  108. +0 −12,417 tests/browser/mocha.js
  109. +65 −0 tests/browser/slim.html
  110. +2,106 −1,298 tests/compiler.js
  111. +76 −0 tests/core.js
  112. +0 −49 tests/express-sample/js/extensions.js
  113. +0 −4,913 tests/express-sample/js/nunjucks-dev.js
  114. +0 −1 tests/express-sample/js/nunjucks-min.js
  115. +0 −1,742 tests/express-sample/js/nunjucks.js
  116. +0 −36 tests/express-sample/js/require.js
  117. +0 −107 tests/express-sample/js/templates.js
  118. +0 −26 tests/express-sample/main.js
  119. +0 −16 tests/express-sample/pre.js
  120. +0 −7 tests/express-sample/views/index.html
  121. +45 −0 tests/express.js
  122. +0 −37 tests/express/express.js
  123. +820 −570 tests/filters.js
  124. +150 −141 tests/globals.js
  125. +126 −0 tests/jinja-compat.js
  126. +705 −369 tests/lexer.js
  127. +142 −59 tests/loader.js
  128. +925 −775 tests/parser.js
  129. +50 −19 tests/precompile.js
  130. +101 −67 tests/runtime.js
  131. +2 −0 tests/setup.js
  132. 0 tests/templates/{async.j2 → async.njk}
  133. +1 −1 tests/templates/{base-inherit.j2 → base-inherit.njk}
  134. +1 −1 tests/templates/{base-set-outside-block.j2 → base-set-and-show.njk}
  135. +1 −0 tests/templates/base-set-inside-block.njk
  136. 0 tests/templates/{base-set-wraps-block.j2 → base-set-wraps-block.njk}
  137. +1 −0 tests/templates/base-set.njk
  138. +1 −0 tests/templates/base-show.njk
  139. 0 tests/templates/{base.j2 → base.njk}
  140. 0 tests/templates/{base2.j2 → base2.njk}
  141. 0 tests/templates/{base3.j2 → base3.njk}
  142. +3 −0 tests/templates/broken-conditional-include.njk
  143. 0 tests/templates/{for-async-content.j2 → for-async-content.njk}
  144. 0 tests/templates/{import-context-set.j2 → import-context-set.njk}
  145. 0 tests/templates/{import-context.j2 → import-context.njk}
  146. +1 −1 tests/templates/{import-macro-call-undefined-macro.j2 → import-macro-call-undefined-macro.njk}
  147. 0 tests/templates/{import.j2 → import.njk}
  148. 0 tests/templates/{include-in-loop.j2 → include-in-loop.njk}
  149. 0 tests/templates/{include-set.j2 → include-set.njk}
  150. 0 tests/templates/{include.j2 → include.njk}
  151. +130 −0 tests/templates/includeMany.njk
  152. 0 tests/templates/{item.j2 → item.njk}
  153. +1 −1 tests/templates/{macro-call-undefined-macro.j2 → macro-call-undefined-macro.njk}
  154. +0 −1 tests/templates/relative/dir1/index.j2
  155. +1 −0 tests/templates/relative/dir1/index.njk
  156. 0 tests/templates/relative/dir1/{macros.j2 → macros.njk}
  157. +0 −1 tests/templates/relative/dir2/index.j2
  158. +1 −0 tests/templates/relative/dir2/index.njk
  159. 0 tests/templates/relative/dir2/{macros.j2 → macros.njk}
  160. +0 −2 tests/templates/relative/test-cache.j2
  161. +2 −0 tests/templates/relative/test-cache.njk
  162. +1 −1 tests/templates/relative/{test1.j2 → test1.njk}
  163. +1 −1 tests/templates/relative/{test2.j2 → test2.njk}
  164. 0 tests/templates/{set.j2 → set.njk}
  165. 0 tests/templates/{simple-base.j2 → simple-base.njk}
  166. +1 −0 tests/templates/throws.njk
  167. 0 tests/templates/{undefined-macro.j2 → undefined-macro.njk}
  168. 0 tests/test-node-pkgs/dummy-pkg/index.js
  169. +12 −0 tests/test-node-pkgs/dummy-pkg/package.json
  170. +1 −0 tests/test-node-pkgs/dummy-pkg/simple-template.html
  171. +260 −0 tests/tests.js
  172. +197 −105 tests/util.js
19 changes: 19 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
["@babel/env", {
"loose": true,
"targets": {
"browsers": ["last 2 versions", "safari >= 7", "ie 9"],
"node": "6"
}
}]
],
"env": {
"test": {
"plugins": ["./scripts/lib/arrow-function-coverage-fix", "istanbul"]
}
},
"ignore": [
"scripts/lib/arrow-function-coverage-fix.js"
]
}
File renamed without changes.
52 changes: 52 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = {
'extends': [
'airbnb-base/legacy',
],
'parserOptions': {
'sourceType': 'module',
'ecmaVersion': 2017,
},
'env': {
'node': true,
'es6': true,
},
"rules": {
// The one assertion of personal preference: no spaces before parentheses
// of anonymous functions
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
// Temporarily disabled rules
//
// no-use-before-define is a good rule, but it would make the diff for
// linting the code even more inscrutible than it already is.
'no-use-before-define': 'off',
// Relax some rules
'no-cond-assign': ['error', 'except-parens'],
'no-unused-vars': ['error', {
'args': 'none',
}],
// Disable some overly-strict airbnb style rules
'no-underscore-dangle': 'off',
'no-param-reassign': 'off',
'class-methods-use-this': 'off',
'function-paren-newline': 'off',
'no-plusplus': 'off',
'object-curly-spacing': 'off',
'no-multi-assign': 'off',
'no-else-return': 'off',
// While technically useless from the point of view of the regex parser,
// escaping characters inside character classes is more consistent. I
// would say that they make the regular expression more readable, if the
// idea of readable regular expressions wasn't absurd on its face.
'no-useless-escape': 'off',
// I'm inclined to reverse this rule to be ['error', 'always'], but not just yet
// IE 8 is a thing of the past and trailing commas are useful.
'comma-dangle': 'off',
},
'globals': {
'nunjucks': false,
},
};
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Checkout example and test fixtures with linux line ending
# to guarantee test successes
tests/** text eol=lf
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## 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.

* [ ] 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.
* [ ] [*Tests*](https://github.com/mozilla/nunjucks/tree/master/tests) are added / updated to cover proposed change.
* [ ] [*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]` -->
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -2,4 +2,13 @@ node_modules
coverage
.#*
docs/_site
docs/files
docs/files
/src/
/index.js
/index.js.map
/tests/browser/nunjucks*
.nyc_output
/browser
/tests/browser/precompiled-templates.js
/samples/express/js/nunjucks.js
/samples/express/js/templates.js
31 changes: 0 additions & 31 deletions .jshintrc

This file was deleted.

3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
node_modules
coverage
.nyc_output
docs
tests
bench
nunjucks
scripts
16 changes: 10 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
language: node_js
sudo: false
node_js:
- "5"
- "4"
- "1"
- "0.12"
- "0.11"
- "0.10"
- "11"
- "10"
- "8"
install:
- npm install
- npm install codecov
script:
- npm test
- npm run codecov
198 changes: 197 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,206 @@
Changelog
=========

3.2.1 (Mar 17 2020)
-------------------
* Replace yargs with commander to reduce number of dependencies. Merge of
[#1253](https://github.com/mozilla/nunjucks/pull/1253). Thanks
[AlynxZhou](@AlynxZhou).
* Update optional dependency chokidar from `^2.0.0` to `^3.3.0`. Merge of
[#1254](https://github.com/mozilla/nunjucks/pull/1254). Thanks
[eklingen](@eklingen).
* Prevent optional dependency Chokidar from loading when not watching. Merge
of [#1250](https://github.com/mozilla/nunjucks/pull/1250). Thanks
[eklingen](@eklingen).

3.2.0 (Mar 5 2019)
------------------

* Adds [`NodeResolveLoader`](http://mozilla.github.io/nunjucks/api.html#noderesolveloader),
a Loader that loads templates using node's
[`require.resolve`](https://nodejs.org/api/modules.html#modules_all_together).
Fixes [#1175](https://github.com/mozilla/nunjucks/issues/1175).
* Emit 'load' events on `Environment` instances, to allow runtime dependency
tracking. Fixes [#1153](https://github.com/mozilla/nunjucks/issues/1153).

3.1.7 (Jan 12 2019)
------------------

* 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)
* Removes deprecated postinstall-build package in favor of
[npm prepare](https://docs.npmjs.com/misc/scripts#prepublish-and-prepare).
Merge of [#1172](https://github.com/mozilla/nunjucks/pull/1172).
Fixes [#1167](https://github.com/mozilla/nunjucks/issues/1167).

- Note: this means that npm@5 or later is required to install nunjucks
directly from github.

3.1.6 (Dec 13 2018)
-------------------

No code changes; fixed npm packaging issue.

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)
------------------

* Fix engine version for Node v11.1.0
* Fix "Unexpected token" error for U+2028 unicode newline. Fixes [#126](https://github.com/mozilla/nunjucks/issues/126) and [#736](https://github.com/mozilla/nunjucks/issues/736)

3.1.3 (May 19 2018)
-------------------

* Add `forceescape` filter. Fixes [#782](https://github.com/mozilla/nunjucks/issues/782)

* Fix regression that prevented template errors from reporting line and column number.
Fixes [#1087](https://github.com/mozilla/nunjucks/issues/1087) and
[#1095](https://github.com/mozilla/nunjucks/issues/1095).

* Fix "Invalid type: Is" error for `{% if value is defined %}`. Fixes
[#1110](https://github.com/mozilla/nunjucks/issues/1110)

* Formally drop support for node v4 (the upgrade to babel 7 in 3.1.0 made the
build process incompatible with node < 6.9.0).

3.1.2 (Feb 23 2018)
-------------------

* Fix regression to make `chokidar` an optional dependency again. Fixes
[#1073](https://github.com/mozilla/nunjucks/issues/1073)
* Fix issue when running `npm install nunjucks` with the `--no-bin-links` flag
* Fix regression that broke template caching. Fixes
[#1074](https://github.com/mozilla/nunjucks/issues/1074)

3.1.0 (Feb 19 2018)
-------------------

* Support nunjucks.installJinjaCompat() with slim build. Fixes
[#1019](https://github.com/mozilla/nunjucks/issues/1019)

* Fix calling render callback twice when a conditional import throws an error.
Solves [#1029](https://github.com/mozilla/nunjucks/issues/1029)

* Support objects created with Object.create(null). fixes [#468](https://github.com/mozilla/nunjucks/issues/468)

* Support ESNext iterators, using Array.from. Merge of
[#1058](https://github.com/mozilla/nunjucks/pull/1058)

3.0.1 (May 24 2017)
-------------------

* Fix handling methods and attributes of static arrays, objects and primitives.
Solves the issue [#937](https://github.com/mozilla/nunjucks/issues/937)

* Add support for python-style array slices with Jinja compat enabled.
Fixes [#188](https://github.com/mozilla/nunjucks/issues/188); merge of
[#976](https://github.com/mozilla/nunjucks/pull/976).

* Fix call blocks having access to their parent scope. Fixes
[#906](https://github.com/mozilla/nunjucks/issues/906); merge of
[#994](https://github.com/mozilla/nunjucks/pull/994).

* Fix a bug that caused capturing block tags (e.g. set/endset,
filter/endfilter) to write to the global buffer rather than capturing
their contents. Fixes
[#914](https://github.com/mozilla/nunjucks/issues/914) and
[#972](https://github.com/mozilla/nunjucks/issues/972); merge of
[#990](https://github.com/mozilla/nunjucks/pull/990). Thanks [Noah
Lange](@noahlange).


3.0.0 (Nov 5 2016)
----------------

* Allow including many templates without reaching recursion limits. Merge of
[#787](https://github.com/mozilla/nunjucks/pull/787). Thanks Gleb Khudyakov.

* Allow explicitly setting `null` (aka `none`) as the value of a variable;
don't ignore that value and look on up the frame stack or context. Fixes
[#478](https://github.com/mozilla/nunjucks/issues/478). Thanks Jonny Gerig
Meyer for the report.

* Execute blocks in a child frame that can't write to its parent. This means
that vars set inside blocks will not leak outside of the block, base
templates can no longer see vars set in templates that inherit them, and
`super()` can no longer set vars in its calling scope. Fixes the inheritance
portion of [#561](https://github.com/mozilla/nunjucks/issues/561), which
fully closes that issue. Thanks legutierr for the report.

* Prevent macros from seeing or affecting their calling scope. Merge of
[#667](https://github.com/mozilla/nunjucks/pull/667).

* Fix handling of macro arg with default value which shares a name with another
macro. Merge of [#791](https://github.com/mozilla/nunjucks/pull/791).

* Add support for the spaces parameter in the dump template filter.
Merge of [#868](https://github.com/mozilla/nunjucks/pull/868).
Thanks Jesse Eikema

* Add `verbatim` as an alias of `raw` for compatibility with Twig.
Merge of [#874](https://github.com/mozilla/nunjucks/pull/874).

* Add new `nl2br` filter. Thanks Marc-Aurèle Darche

* Add support for python's `list.append` with Jinja compat enabled. Thanks
Conor Flannigan.

* Add variables whitespace control.


2.5.2 (Sep 14 2016)
----------------

* Call `.toString` in safe filter.
Merge of [#849](https://github.com/mozilla/nunjucks/pull/849).


2.x (unreleased)
2.5.1 (Sep 13 2016)
----------------

* Fix `undefined` and `null` behavior in escape and safe filter.
Merge of [#843](https://github.com/mozilla/nunjucks/pull/843).


2.5.0 (Sep 7 2016)
----------------

* Add `elseif` as an alias of `elif` for parity with Twig. Thanks kswedberg.
Merge of [#826](https://github.com/mozilla/nunjucks/pull/826).

* Add nunjucks env to express app settings as `nunjucksEnv`.
Merge of [#829](https://github.com/mozilla/nunjucks/pull/829).

* Add support for finding an object's "length" in length filter.
Merge of [#813](https://github.com/mozilla/nunjucks/pull/813).

* Ensure that precompiling on Windows still outputs POSIX-style path
separators. Merge of [#761](https://github.com/mozilla/nunjucks/pull/761).

* Add support for strict type check comparisons (=== and !==). Thanks
oughter. Merge of [#746](https://github.com/mozilla/nunjucks/pull/746).

* Allow full expressions (incl. filters) in import and from tags. Thanks legutierr.
Merge of [#710](https://github.com/mozilla/nunjucks/pull/710).

* OS agnostic file paths in precompile. Merge of [#825](https://github.com/mozilla/nunjucks/pull/825).


2.4.3 (Sep 7 2016)
----------------

* Fix potential cast-related XSS vulnerability in autoescape mode, and with `escape` filter.
Thanks Matt Austin for the report and Thomas Hunkapiller for the fix.
[#836](https://github.com/mozilla/nunjucks/pull/836)


2.4.2 (Apr 15 2016)
-------------------
Loading