diff --git a/editor/js/ui/editor.js b/editor/js/ui/editor.js index 9164be349..d781a61e7 100644 --- a/editor/js/ui/editor.js +++ b/editor/js/ui/editor.js @@ -1791,37 +1791,43 @@ RED.editor = (function() { var legacyMode = false; try { expr = jsonata(currentExpression); - expr.assign('flow',function(val) { + expr.assign('flowContext',function(val) { usesContext = true; return null; }); - expr.assign('global',function(val) { + expr.assign('globalContext',function(val) { usesContext = true; return null; }); legacyMode = /(^|[^a-zA-Z0-9_'"])msg([^a-zA-Z0-9_'"]|$)/.test(currentExpression); } catch(err) { - testResultEditor.setValue("Invalid jsonata expression:\n "+err.message); + testResultEditor.setValue(RED._("expressionEditor.errors.invalid-expr",{message:err.message})); return; } $(".node-input-expression-legacy").toggle(legacyMode); try { parsedData = JSON.parse(value); } catch(err) { - testResultEditor.setValue("Invalid example message:\n "+err.toString()) + testResultEditor.setValue(RED._("expressionEditor.errors.invalid-msg",{message:err.toString()})) return; } try { var result = expr.evaluate(legacyMode?{msg:parsedData}:parsedData); if (usesContext) { - testResultEditor.setValue("Cannot test a function that uses context values"); + testResultEditor.setValue(RED._("expressionEditor.errors.context-unsupported")); return; } - var formattedResult = JSON.stringify(result,null,4); - testResultEditor.setValue(formattedResult || "No match"); + + var formattedResult; + if (result !== undefined) { + formattedResult = JSON.stringify(result,null,4); + } else { + formattedResult = RED._("expressionEditor.noMatch"); + } + testResultEditor.setValue(formattedResult); } catch(err) { - testResultEditor.setValue("Error evaluating expression:\n "+err.message); + testResultEditor.setValue(RED._("expressionEditor.errors.eval",{message:err.message})); } } diff --git a/red/api/locales/en-US/editor.json b/red/api/locales/en-US/editor.json index 39cdbd6a2..ad9c5be5e 100644 --- a/red/api/locales/en-US/editor.json +++ b/red/api/locales/en-US/editor.json @@ -403,7 +403,14 @@ "result": "Result", "format": "format expression", "compatMode": "Compatibility mode enabled", - "compatModeDesc": "
The current expression appears to still reference msg
so will be evaluated in compatibility mode. Please update the expression to not use msg
as this mode will be removed in the future.
When JSONata support was first added to Node-RED, it required the expression to reference the msg
object. For example msg.payload
would be used to access the payload.
That is no longer necessary as the expression will be evaluated against the message directly. To access the payload, the expression should be just payload
.
The current expression appears to still reference msg
so will be evaluated in compatibility mode. Please update the expression to not use msg
as this mode will be removed in the future.
When JSONata support was first added to Node-RED, it required the expression to reference the msg
object. For example msg.payload
would be used to access the payload.
That is no longer necessary as the expression will be evaluated against the message directly. To access the payload, the expression should be just payload
.