Support optional chaining
It would be great if njs could support optional chaining.
Looking at the codebase, I actually found this function pertaining to optional chaining: https://github.com/nginx/njs/blob/855aa4c9fac01bd9fbdb1602b523edc00117ff09/src/njs_parser.c#L2962
But, unless I'm doing something silly, it doesn't seem to work as I expected.
For example, a simple call like the following produces an error:
>> Object.xxx?.();
Thrown:
SyntaxError: Unexpected token "(" in shell:1
Whereas the same code in, say, Node.js, Firefox or Chrome will succeed:
undefined
So am I missing something obvious?
Thanks for your answer, @xeioex.
I wasn't aware of the existence of the QuickJS alternative.
Unfortunately, given that I happen to use ngx.fetch() and querystring in my code, I guess QuickJS is not (yet) an option for me.
But by the way, what does this njs_parser_optional_chain() function do then?
hi @dalbani,
yes this code was intended to support optional chaining in njs, and this looks like a bug. I will look into it as time permits. No ETA though, as we have QuickJS engine integration as a priority.
@dalbani since 0.9.1 qjs engine supports ngx.fetch() and querystring module.