diff --git a/src/conditions.ts b/src/conditions.ts index 64ec65a5ce..7af6b8c04d 100644 --- a/src/conditions.ts +++ b/src/conditions.ts @@ -1,6 +1,6 @@ import { HashTable } from "./helpers"; import { ProcessValue } from "./conditionProcessValue"; - +import { ConsoleWarnings } from "./console-warnings"; import { Operand, FunctionOperand } from "./expressions/expressions"; import { ConditionsParser } from "./conditionsParser"; @@ -90,8 +90,12 @@ export class ExpressionExecutor implements IExpresionExecutor { values: HashTable, properties: HashTable = null ): any { - if (!this.operand) return null; - + if (!this.operand) { + if(!!this.expression) { + ConsoleWarnings.warn("Invalid expression: " + this.expression); + } + return null; + } this.processValue.values = values; this.processValue.properties = properties; if (!this.isAsync) return this.runValues(); diff --git a/src/functionsfactory.ts b/src/functionsfactory.ts index f686d0b5cd..7f653c8b1a 100644 --- a/src/functionsfactory.ts +++ b/src/functionsfactory.ts @@ -1,5 +1,6 @@ import { HashTable, Helpers } from "./helpers"; import { settings } from "./settings"; +import { ConsoleWarnings } from "./console-warnings"; export class FunctionFactory { public static Instance: FunctionFactory = new FunctionFactory(); @@ -41,7 +42,10 @@ export class FunctionFactory { properties: HashTable = null ): any { var func = this.functionHash[name]; - if (!func) return null; + if (!func) { + ConsoleWarnings.warn("Function name is unknown: " + name); + return null; + } let classRunner = { func: func, }; diff --git a/tests/expressions/expressionParserTest.ts b/tests/expressions/expressionParserTest.ts index d1ea7cfcf0..4b59ef7dd5 100644 --- a/tests/expressions/expressionParserTest.ts +++ b/tests/expressions/expressionParserTest.ts @@ -7,7 +7,7 @@ import { import { ConditionRunner, ExpressionRunner } from "../../src/conditions"; import { ConditionsParser } from "../../src/conditionsParser"; - +import { ConsoleWarnings } from "../../src/console-warnings"; import { Const, Variable, @@ -1469,4 +1469,31 @@ QUnit.test("Sum two float numbers as string", function(assert) { let runner = new ExpressionRunner("{a} + {b}"); assert.equal(runner.run({ a: "1.1", b: "2.2" }), 3.3, "#1"); assert.equal(runner.run({ a: "0.1", b: "0.2" }), 0.3, "#2"); +}); +QUnit.test("Warn in console if the expression is invalid", function(assert) { + const prev = ConsoleWarnings.warn; + let reportText: string = ""; + ConsoleWarnings.warn = (text: string) => { + reportText = text; + }; + const runner = new ExpressionRunner("{a} ++"); + assert.notOk(reportText); + runner.run({ a: 1 }); + assert.equal(reportText, "Invalid expression: {a} ++"); + + reportText = ""; + runner.expression = "{a} + 1"; + runner.run({ a: 1 }); + assert.notOk(reportText); + + runner.expression = "tooday()"; + assert.notOk(reportText); + runner.run({}); + assert.equal(reportText, "Function name is unknown: tooday"); + + reportText = ""; + runner.expression = "today"; + runner.run({}); + assert.notOk(reportText); + ConsoleWarnings.warn = prev; }); \ No newline at end of file