Skip to content

Support optional chaining #835

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

Open
dalbani opened this issue Jan 7, 2025 · 3 comments
Open

Support optional chaining #835

dalbani opened this issue Jan 7, 2025 · 3 comments
Labels

Comments

@dalbani
Copy link

dalbani commented Jan 7, 2025

It would be great if njs could support optional chaining.

Looking at the codebase, I actually found this function pertaining to optional chaining:

njs_parser_optional_chain(njs_parser_t *parser, njs_lexer_token_t *token,

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?

@dalbani dalbani added the feature label Jan 7, 2025
@xeioex
Copy link
Contributor

xeioex commented Jan 7, 2025

Hi @dalbani,

Consider using QuickJS engine if you do not use built-in modules not implemented yet.

@dalbani
Copy link
Author

dalbani commented Jan 7, 2025

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?

@xeioex
Copy link
Contributor

xeioex commented Jan 9, 2025

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.

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