Skip to content

Commit f4a937c

Browse files
committed
tyemplate - allowAssigments op
1 parent 381a23f commit f4a937c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rightech/utils",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"description": "",
55
"main": "index.js",
66
"private": false,
@@ -18,6 +18,7 @@
1818
},
1919
"homepage": "https://github.com/Rightech/node-utils#readme",
2020
"dependencies": {
21+
"acorn-walk": "^7.2.0",
2122
"angular-expressions": "^1.1.1",
2223
"colors": "^1.4.0",
2324
"deepmerge": "^4.2.2",

src/template.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
const expressions = require('angular-expressions');
2020
const mustache = require('mustache');
21+
const walk = require('acorn-walk');
22+
2123
const nanoid = require('nanoid');
2224

2325
const format = require('./format');
@@ -99,6 +101,11 @@ module.exports = function parseTemplate(text = '', context = {}, opts = {}) {
99101
}
100102
try {
101103
const evaluate = expressions.compile(value);
104+
walk.full(evaluate.ast, node => {
105+
if (!opts.allowAssignments && node.type === 'AssignmentExpression') {
106+
throw new Error('no assignments allowed');
107+
}
108+
});
102109
value = evaluate(context);
103110
} catch (err) {
104111
if (opts.noSilentError) {

0 commit comments

Comments
 (0)