evalJs 优化是否补 return 的判断

This commit is contained in:
2betop 2020-01-15 18:22:01 +08:00
parent dc24cd30e2
commit 4977813a06
1 changed files with 1 additions and 1 deletions

View File

@ -70,7 +70,7 @@ export function evalJS(js: string, data: object): any {
const fn = new Function( const fn = new Function(
'data', 'data',
'utils', 'utils',
`with(data) {${~js.indexOf('return') ? '' : 'return '}${js};}` `with(data) {${/^\s*return\b/.test(js) ? '' : 'return '}${js};}`
); );
data = data || {}; data = data || {};
return fn.call(data, data, getFilters()); return fn.call(data, data, getFilters());