fix function bug

This commit is contained in:
Orion Reed 2024-07-31 19:55:18 +01:00
parent 85a7b1632a
commit 987902c3be
1 changed files with 10 additions and 5 deletions

View File

@ -108,12 +108,12 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
// console.log("VALS", vals) // console.log("VALS", vals)
// Check for "sum" or "average" followed by whitespace or end of string // Check for "sum" or "average" followed by whitespace or end of string
const invalidFunctionUsage = /\b(sum|average)(\s|$)/.test(shape.props.text) // const invalidFunctionUsage = /\b(sum|average)(\s|$)/.test(shape.props.text)
if (invalidFunctionUsage) { // if (invalidFunctionUsage) {
this.updateProps(shape, { syntaxError: true }) // this.updateProps(shape, { syntaxError: true })
return // return
} // }
const functionBody = `return ${shape.props.text.replace(valueType, 'VALUES')};` const functionBody = `return ${shape.props.text.replace(valueType, 'VALUES')};`
@ -140,6 +140,11 @@ export class SocialShapeUtil extends BaseBoxShapeUtil<ISocialShape> {
try { try {
const func = new Function('sum', 'average', 'VALUES', functionBody) const func = new Function('sum', 'average', 'VALUES', functionBody)
const result = func(sum, average, vals) const result = func(sum, average, vals)
const resultIsFunction = typeof result === 'function'
if (resultIsFunction) {
this.updateProps({ ...shape, props: { ...shape.props, value: null } }, { syntaxError: true })
return
}
console.log("VALUE", result) console.log("VALUE", result)
this.updateProps(shape, { value: result, syntaxError: false }) this.updateProps(shape, { value: result, syntaxError: false })
} catch (e) { } catch (e) {