jsparser: context fixes

This commit is contained in:
jean-emmanuel 2019-04-07 19:35:17 +02:00
parent 6d1e4b4e8b
commit 926853ebf1
2 changed files with 8 additions and 3 deletions

View file

@ -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)

View file

@ -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])
}