tc39/proposal-optional-chaining

Post-operator question mark

stuartpb opened this issue · 6 comments

I looked at all the previous alternative syntax proposals, and none of them seem to propose using .?, [?, and (? as the chaining operators, as I proposed on WICG about three years ago.

Wouldn't this make more sense, as the only case where this overlaps currently valid syntax is the 1.?foo:bar case described in other issues that only propose variations of .? for the other two operators (which, as noted in those issues, is evitable by not allowing this syntax on numbers)?

Hmm - it might be confusing whether obj[?foo] applies the ? to the object or to the foo variable?

Mmh, I’m sure that someone somewhere proposed that syntax, and that I explained why I didn’t like it, but I cannot find it... But @ljharb expressed my main objection in fewer words than I would have been able to.

Also, someone proposed that in a past poll about preferred syntax, but the option wasn’t very popular...

Discussed in #61

#61 doesn't discuss .?, [?, and (? though - it discusses .?, .?[, and .?(.

The reason I think the former is superior to the latter (or ?., ?.[, and ?.( as are currently proposed) is because it doesn't introduce a . to the chained-index-and-call operators, which wouldn't have a . in their non-chained versions.

Zarel commented

[? is mentioned in #61 (comment)

Overall, the arguments in #61 (which are mostly about how ? makes more sense before . than after) apply equally well to [? and (?.

To be fair, you could make an argument that that's worth not having the weird dot in ?.[ and ?.( – but again, it was proposed in the poll and near-unanimously rejected, so I seriously doubt anyone would think it's worth revisiting after Stage 3.

To be fair, you could make an argument that that's worth not having the weird dot in ?.[ and ?.( – but again, it was proposed in the poll and near-unanimously rejected, so I seriously doubt anyone would think it's worth revisiting after Stage 3.

Indeed.

Syntax has been discussed to death in the past, and we’ve reached rough consensus on the least bad option. I’m closing this issue in order to make clear that, as of now, the proposed amendment has about zero chance to be accepted, in absence of very strong and improbable reason. Thanks for your interest.