visibleOn 支持 debugger 功能

This commit is contained in:
liaoxuezhi 2019-08-12 15:35:15 +08:00
parent e8ee62152a
commit 18050e6e2d
1 changed files with 8 additions and 1 deletions

View File

@ -30,9 +30,16 @@ export function filter(tpl: string, data: object = {}, ...rest:Array<any>): stri
export function evalExpression(expression: string, data?: object): boolean { export function evalExpression(expression: string, data?: object): boolean {
/* jshint evil:true */ /* jshint evil:true */
try { try {
let debug = false;
const idx = expression.indexOf('debugger');
if (~idx) {
debug = true;
expression = expression.replace(/debugger;?/, '');
}
const fn = new Function( const fn = new Function(
"data", "data",
`with(data) {return !!(${expression});}` `with(data) {${debug ? 'debugger;' : ''}return !!(${expression});}`
); );
data = data || {}; data = data || {};
return fn.call(data, data); return fn.call(data, data);