From 17c0e64eca39ef04c38c0c031225f7c022021b53 Mon Sep 17 00:00:00 2001 From: bordun Date: Sun, 26 Jan 2020 17:15:25 +0100 Subject: [PATCH] mathjs; downgrade version & deprecate syntax --- CHANGELOG.md | 1 + package.json | 2 +- .../docs/docs/advanced-property-syntax.md | 22 ++++++++++--------- src/client/app/widgets/common/widget.js | 8 +++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 146ed186..8de0e2be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.49.0 +- **deprecation** MathJS syntax is deprecated and will be removed in the future in favor of the Javascript syntax - bug fixes: - widgets: missing `target` property for `plots/*` widgets, required for MIDI bindings - editor: set `label` to `auto` instead of `true` when using the toggle button diff --git a/package.json b/package.json index 7fed3b4e..b7a03c60 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "keyboardjs": "github:jean-emmanuel/KeyboardJS", "licensify": "3.1.3", "loop-protect": "github:jean-emmanuel/loop-protect#v1.0.1", - "mathjs": "6.5.0", + "mathjs": "5.10.0", "minimatch": "3.0.4", "nanohtml": "1.9.0", "nanoid": "2.1.10", diff --git a/resources/docs/docs/advanced-property-syntax.md b/resources/docs/docs/advanced-property-syntax.md index 4fbb0174..a6457cc1 100644 --- a/resources/docs/docs/advanced-property-syntax.md +++ b/resources/docs/docs/advanced-property-syntax.md @@ -70,9 +70,21 @@ By default, osc listeners inherit the widget's `preArgs` and (these must be matc OSC{color, "auto", false} ``` +## Javascript: `JS{{}}` + +This syntax allows writing formulas in pure javascript. The code will be compiled as a function and executed a restricted context. + +- if no `return` statement is found, the formula will return an empty string +- javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled +- `setTimeout` and `setInterval` functions are not available +- the `global` object is shared between all javascript formulas (changing its properties *does not* trigger any synchronisation even if the value is used somewhere else) + ## Formulas: `#{}` +!!! warning "Deprecated" + This syntax is deprecated and will be removed in the future. Use the javascript syntax instead. + The following syntax allow writing mathematical formulas in widgets' properties: ``` @@ -101,13 +113,3 @@ Additionnal functions: !!! tip "" A single widget property can contain multiple formulas. Variables and functions declared in a formula are available to subsequent formulas in the same property definition. - - -## Javascript: `JS{{}}` - -This syntax allows writing formulas in pure javascript. The code will be compiled as a function and executed a restricted context. - -- if no `return` statement is found, the formula will return an empty string -- javascript [strict mode](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode) is always enabled -- `setTimeout` and `setInterval` functions are not available -- the `global` object is shared between all javascript formulas (changing its properties *does not* trigger any synchronisation even if the value is used somewhere else) diff --git a/src/client/app/widgets/common/widget.js b/src/client/app/widgets/common/widget.js index 38063f93..903a054e 100644 --- a/src/client/app/widgets/common/widget.js +++ b/src/client/app/widgets/common/widget.js @@ -9,8 +9,11 @@ var EventEmitter = require('../../events/event-emitter'), OscReceiver = require('./osc-receiver'), {deepCopy, deepEqual} = require('../../utils'), html = require('nanohtml'), + ipc = require('../../ipc'), updateWidget = ()=>{} + +var mathjsDeprecationWarned = false var oscReceiverState = {} var OSCProps = [ @@ -583,6 +586,11 @@ class Widget extends EventEmitter { propValue = propValue.replace(/#\{(?:[^{}]|\{[^{}]*\})*\}/g, (m)=>{ // one bracket nesting allowed, if we need two: #\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\} + if (!mathjsDeprecationWarned) { + mathjsDeprecationWarned = true + ipc.send('error', 'Warning: MathJS syntax (#{}) is deprecated and will be removed in the future. Consider using the Javascript syntax instead.') + } + // unescape brackets (not needed anymore, just here for backward compatibility) m = m.replace(/\\(\{|\})/g, '$1')