Skip to content

Commit

Permalink
fix(core/reports): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 committed Mar 16, 2023
1 parent 1a3501d commit 8dc334b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions projects/core/models/src/utils/expression-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,28 +213,28 @@ type Func = (c?: AjfContext) => any;

export function createFunction(expression: string): Func {
if (!expression) {
return c => '';
return _ => '';
}
if (expression === 'true') {
return c => true;
return _ => true;
}
if (expression === 'false') {
return c => false;
return _ => false;
}
if (/^[a-zA-Z_$][\w$]*$/.test(expression)) { // expression is an identifier
return c => c == null || c[expression] === undefined ? null : c[expression];
}
if (/^"[^"]*"$/.test(expression) || /^'[^']*'$/.test(expression)) {
let str = expression.slice(1, -1);
return c => str;
return _ => str;
}

const argNames = [...new Set(getCodeIdentifiers(expression, true)).add('execContext')];
let func: Function;
try {
func = new Function(...argNames, 'return ' + expression);
} catch {
return c => false;
return _ => false;
}
return context => {
const argValues = argNames.map(name => {
Expand Down

0 comments on commit 8dc334b

Please sign in to comment.