p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Make reserved word assignment regex work better with function calls

Open davepagurek opened this issue 3 years ago • 0 comments

Resolves https://github.com/processing/p5.js/issues/5734

Changes:

  • Made the assignment statement regex a little bigger to handle more edge cases:
    • Instead of splitting on all commas, it uses a regex to parse the whole list of assignments
    • It will now correctly parse single-level function calls and ignore them
    • It will stop parsing after anything it doesn't match so that it doesn't introduce new false positives
    • It still uses regexes instead of writing a simple recursive parser to avoid complexity/bugs
  • Added tests to make sure function parameters on right hand sides of assignments are ignored

PR Checklist

  • [x] npm run lint passes
  • [x] [Inline documentation] is included / updated
  • [x] [Unit tests] are included / updated

davepagurek avatar Aug 06 '22 00:08 davepagurek

Pretty complex regex there that took some time to wrap my head around. If we didn't miss anything obvious it should be good enough for now. Thanks!

limzykenneth avatar Aug 11 '22 15:08 limzykenneth

Thanks @davepagurek and @limzykenneth ✨

Qianqianye avatar Aug 13 '22 02:08 Qianqianye