Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect syntax highlighting in the JSONata Expression editor in the change node. #2701

Closed
5 tasks done
janvda opened this issue Sep 20, 2020 · 1 comment
Closed
5 tasks done
Labels
Milestone

Comments

@janvda
Copy link

janvda commented Sep 20, 2020

What are the steps to reproduce?

[{"id":"e9e09a72.fc9348","type":"change","z":"bfd23e84.79e77","name":"bad syntax highlighting","rules":[{"t":"set","p":"cases","pt":"msg","to":"/* returns an array of\t     { \"x\" : date_in_ms,\t       \"y\" : average_number_of_cases }\t*/\t( $subset := COVID19BE_CASES_AGESEX[     PROVINCE = $$.PROVINCE \t                                      and AGEGROUP = $$.AGEGROUP\t                                      and SEX      = $$.SEX].{ \"date_int\" : $toMillis(DATE)/(24*60*60*1000),\t                                                               \"cases\"  : CASES};\t  $first_day := $subset.date_int~>$min();\t  $last_day := $subset.date_int~>$max();\t  [ $first_day ..  ( $last_day -AVERAGE_PERIOD+1)].(\t      $start_period :=$;\t      $end_period   :=$start_period + $$.AVERAGE_PERIOD -1;\t      $sum_cases    := $subset[ date_int >= $start_period and date_int <= $end_period].cases~>$sum();\t      {\t     \"x\" : ($start_period + $end_period )*24*60*60*1000/2,\t     \"y\" :$sum_cases~>$exists()?$sum_cases/($$.AVERAGE_PERIOD): 0\t     })\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":520,"wires":[[]]}]

What happens?

image

What do you expect to happen?

From the end of line 7 up to the end of line 16 is highlighted as comment. This is not correct.

The / is apparently interpreted as the start or end of the comment. Which is not always correct. / can also mean the "division operator". Only /* and */should be considered the start and end of a comment.

Please tell us about your environment:

  • Node-RED version: v1.1.3
  • Node.js version: v12.18.3
  • npm version: 6.14.6
  • Platform/OS: Linux 4.18.0-193.6.3.el8_2.x86_64 x64 LE
  • Browser: chrome
@knolleary
Copy link
Member

Have pushed a fix to the dev branch.

The syntax highlighting mode had no support for comments at all (as its a relatively new addition to JSONata). What you were seeing was an issue with the regular expression highlighting - any section starting with a / was being identified as a regex - including the comment block at the start.

It needed some additional logic to prevent it mistaking a divide for the start of a regex. Thankfully the existing JavaScript highlight mode showed me the way to disambiguate the two.

I've also added support for /* ... */ comments, and fixed up some highlighting of variables that contain a known function name (eg $sum_cases was getting $sum highlighted as a known function).

Here's what it looks like with the fixes:

image

@knolleary knolleary added this to the 1.2 milestone Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants