Replies: 1 comment 6 replies
-
I'm not really getting what you're trying to do. Optional Chaining is working on maps and structs, but not for index accessing. get([1,2,3], 4) // => null |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I didn't see it documented, but found things like #547 that suggest that the syntax
foo?.[0]
can be used to allow optional array indexing.I guess to step back, the problem I'm trying to solve is in my use case, I actually don't care about undefined parameters, and it would be nice, if I could just have everything be treated as nil, if not defined. That could be a distinct feature request, I suppose.
To get around this, I've decided to Patch the AST, I've been using this.
I've also tried on a few test programs, but they all error with some variation of:
Here is the output from my test program:
I believe it supports the following conclusions:
Case #2, suggests that the rewriting works correctly, as it was able to rewrite it (although maybe actually it didn't and the AllowUnedifiedVariables() is what is doing it).
Case #2,#4,#6,#8 suggest that I'm rewriting ... something, because I'm printing the output of the program
.Node().String()
.Case #1,#2 and #3, #4, suggest the rewritten syntax is correct (that is the patched AST has the same Node().String().
So the possible bugs I would like to suggest are:
Do let me know if I'm just doing something wrong.
Beta Was this translation helpful? Give feedback.
All reactions