Additional syntax for safe navigation
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- compilers
Research direction
Start by reviewing the original proposal #89 and the discussion linked in the issue, then compare the requested ?.[] and ?.() forms with the existing safe-navigation behavior. Done means the proposal's scope and implementation requirements for array access and function calls are established.
Written by the indexing model from the issue text.
Description
I wanted to make a new home for a topic of discussion that is somewhat dispersed right now.
Safe navigation was implemented for object field access in 4.3.0, however it was not implemented for array access or function calls, despite being included in the original proposal #89 .
Array Access
The original proposal dictated that accessing nullArray?.[0] would return null, as opposed to nullArray[0] which currently throws a TypeError.
This syntax is notably useful in cases where you are working with nested arrays, like nullArray?.[i]?.[j]?.[k]. The fallback behavior is also very clear.
The syntax of ?.[] is used over ?[] since the latter is indistinguishable from a ternary operator by the parser. This syntax would notably be shared with Javascript and no other language.
Function Calls
The original proposal dictated that accessing nullFunction?.() would return null, as opposed to nullFunction() which currently throws a TypeError.
This syntax is notably useful primarily in the case where you are performing multiple object chaining operations in one line, such as object1?.object2?.myFunction?.(). It also may be used in the case where you use an optional callback function.
The main reasoning behind these not being implemented with the original proposal, as stated here: https://www.youtube.com/watch?v=lkpoTcHKjSE&t=454s
We didn't add the other variants, you sometimes see
?[or?(to make calls. We weren't sure if this was really needed, to me it looks kind of... it looks a bit awkward, and there might be use cases for it, but for now we decided to just stick to this one.
- Dominant language
- No language data
- Stars
- 120
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HaxeFoundation/haxe-evolution
-
Difficulty 1/5 Under an hour Newbie friendliness 5/100
HaxeFoundation/haxe-evolution#126 · 2 comments · 1 reaction ·
-
License for RFCsOpen
Difficulty 5/5 Over a week Newbie friendliness 35/100
HaxeFoundation/haxe-evolution#121 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
HaxeFoundation/haxe-evolution#120 · 9 comments · 5 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
HaxeFoundation/haxe-evolution#107 · 1 comment · 1 reaction ·
-
EcmaScript 4 syntaxOpen
Difficulty 5/5 Over a week Newbie friendliness 30/100
HaxeFoundation/haxe-evolution#106 · 1 comment · 3 reactions ·
All issues in HaxeFoundation/haxe-evolution
Similar issues
-
node:url: url.parse and url.resolve report name parse/resolve instead of Node's urlParse/urlResolveOpenarea:stdlib effort:S impact:low parity type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bad-antics/lateralus-lang#880 · 1 comment ·
Maintainers usually reply within 1 day
-
bug fixed form parser medium priority tokenizer
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 80/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
swc-project/swc-next-issues#817 ·