From 926853ebf175017eea54b41bd657673c758ab038 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sun, 7 Apr 2019 19:35:17 +0200 Subject: [PATCH] jsparser: context fixes --- src/client/app/widgets/common/widget.js | 9 +++++++-- src/client/app/widgets/utils.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/app/widgets/common/widget.js b/src/client/app/widgets/common/widget.js index 0262cd09..bdce25da 100644 --- a/src/client/app/widgets/common/widget.js +++ b/src/client/app/widgets/common/widget.js @@ -417,7 +417,8 @@ class Widget extends EventEmitter { originalPropName = originalPropName || propName var variables = {}, - mathscope = context || this.constructor.parsersContexts[propName] || {}, + defaultScope = this.constructor.parsersContexts[propName] || {}, + mathscope = context || {}, varnumber = 999 if (typeof propValue == 'string') { @@ -582,6 +583,10 @@ class Widget extends EventEmitter { if (!this.parsers[m]) this.parsers[m] = math.compile(m.substr(2, m.length - 3).trim()) + for (var k in defaultScope) { + if (mathscope[k] === undefined) mathscope[k] = defaultScope[k] + } + let r = this.parsers[m].eval(mathscope) if (r instanceof math.type.ResultSet && !r.entries.length) { @@ -601,7 +606,7 @@ class Widget extends EventEmitter { try { propValue = propValue.replace(/JS\{\{([\s\S]*)\}\}/g, (m, code)=>{ - if (!this.parsers[code]) this.parsers[code] = evaljs(code) + if (!this.parsers[code]) this.parsers[code] = evaljs(code, defaultScope) let r = this.parsers[code](mathscope) diff --git a/src/client/app/widgets/utils.js b/src/client/app/widgets/utils.js index b4aecd33..1c4e8cdf 100644 --- a/src/client/app/widgets/utils.js +++ b/src/client/app/widgets/utils.js @@ -144,7 +144,7 @@ module.exports = { if (defaultContext) { for (var k in defaultContext) { - contextInit += `var ${k} = ${k} || ${JSON.stringify(defaultContext[k])}` + contextInit += `var ${k} = ${k} || ${JSON.stringify(defaultContext[k])};` contextKeys.push(k) contextValues.push(defaultContext[k]) }