Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/utils/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ export class BaseEvaluator {
evaluate: /\{%([\s\S]+?)%\}/g,
escape: /\{\{\{([\s\S]+?)\}\}\}/g,
};
public static noeval: boolean = false;
private static _noeval = false;

public static get noeval(): boolean {
return BaseEvaluator._noeval;
}

public static set noeval(value: boolean) {
BaseEvaluator._noeval = value;
}

public static evaluator(func: any, ...params: any) {
if (Evaluator.noeval) {
console.warn('No evaluations allowed for this renderer.');
Expand Down
23 changes: 23 additions & 0 deletions src/utils/__tests__/Evaluator.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Evaluator } from '../Evaluator';
import { assert } from 'chai';
import { noop } from 'lodash';

describe('Evaluator', function () {
it('Should be able to interpolate a string with Evaluator', function () {
Expand Down Expand Up @@ -228,4 +229,26 @@ describe('Evaluator', function () {
'<span>Sun, 02 May 2021 21:00:00 GMT</span>',
);
});

it('Should enable or disable evaluation based on the noeval option', function () {
Evaluator.noeval = true;
assert.equal(
Evaluator.evaluator(`<span>{{ data.firstName }}</span>`, {
data: {
firstName: 'Travis',
},
}),
noop,
);

Evaluator.noeval = false;
assert.equal(
Evaluator.interpolate(`<span>{{data.firstName }}</span>`, {
data: {
firstName: 'Travis',
},
}),
'<span>Travis</span>',
);
});
});
Loading