Node Red parser not flagging syntax error?

Node Red parser not flagging syntax error?

I was trying to find a flow logic error and wasted about 2 hours double checking everything. Only to find that it appears the javascript parser missed a typo? Do you see it? Hint DEVICE const.

const DEVICE='Device,'
      MONITOR='Monitor',
      STATUS='Status',
      ABORT='Abort',
      LOGOUT='Logout';

The above is not correct, but NR parser did not flag it? Now I suspect this is actually a node parser error, because NR is just using node to validate function nodes?

Are you using the (default) ACE editor, or have you enabled the monaco editor?

What you have shared there is actually valid JavaScript (albeit not 'good' JavaScript). If you open your browser's JavaScript console and paste that in and run it, you won't get an error.

That said, it isn't good JavaScript because you are setting MONITOR etc without having declared them as var/let/const etc. However, the built-in JavaScript parser used by ACE doesn't flag this.

The monaco editor widget has much better defaults for highlighting this type of thing:

We are making monaco the default editor in Node-RED 3.0.

I think you have the comma in the wrong place. And as nick has pointed out, Monaco recognises this kinda thing.

Right, to me this is just a typical typo, comma in the wrong place, was surprised it was not flagged.

No, I have not customized the editor at all.

Yeah, I figured this was not NR per se! Just found it odd.

Oh, so 'good' JavaScript wants explicit declaration per variable/constant? Interesting, my experience with C, C#, VB, VB.NET, python, etc. complex or combined declarations is typical, because JavaScript never flagged it, I never really considered it an issue, live and learn. :slight_smile:

Looking forward to 3.0, I just seem to have all the fun. LOL.

No, you can combine them in a single statement:

const a = 1, b = 2

The problem with your code, as you know, is the missing comma at the end of the first line.

The makes the interpreter see MONITOR as the start of a new statement, rather than a continuation.

Ah... man reminds me of my 'compiler theory' class at University, where there were just 'wonderful' code parsing complexities. Never look at a parser... the code is always ugly... I remember my professor stated.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.