-
Notifications
You must be signed in to change notification settings - Fork 75
Ban optional chaining delete (and anything else that may be missing?) #40
Comments
See Issue #14. I don’t see the point of forbidding optional deletion. Although I understand you could conflate this case with optional write, it is qualitatively different in two ways:
About other potential constructs, I think they are properly handled:
|
I don't see anyone else supporting deletion in that thread. In the coffeescript data, I think there was only a single use of optional deletion. Would this be worth reconsidering? |
Do you have a strong reason for forbidding optional deletion? Optional deletion has very few practical use cases; but forbidding it has probably no practical utility either. In those sort of edge cases, I think it is better to just try to be consistent with precedents, and see if that leads to something problematic or not. If unproblematic, just leave it as is. The runtime semantics of
As currently specced, The final outcome is exactly what a human would intuit. So, why forbid it? If we had to redesign ECMAScript from scratch, maybe that case 1 would throw an error, and in that case an early error for optional delete would be indicated. |
Hi, I have added in the explainer my justification for supporting optional deletion: f1a9945. Please check, and tell me if there is something to be amended and/or if you disagree. |
I'd like to make a case for the delete operator, here's an example I can imagine coming up (in the land of writing client libraries, which is my life these days): function request (url, opts) {
// if options.headers is provided, remove the "If-Modified-Since".
// such that we always request a new copy of the document.
delete opts?.headers?.['If-Modified-Since']
} |
being nit-picky, but the optional-delete use-case for function middlewareNormalize(req, res, nextMiddleware) {
/*
* this middleware will normalize the <req> and <res> objects
*/
req.headers = req.headers || {};
req.queryDict = require("url").parse(req.url, true).query;
...
nextMiddleware();
}
createServer({
middlewareList:[
middlewareNormalizeRequest,
// rest of middlewares (and helper-functions) assume req.headers has been normalized
middlewareValidate,
...
]
}); the same goes for client-requests -- headers are typically normalized at integration-level, and just assumed to exist:
|
@kaizhu256 I went overboard trying to create a real-world example; I mainly mean to say that I can imagine a scenario where an API accepts |
I've needed to use dynamice delete to remove fields before using I personally would favor keeping optional delete if it does not impede progress on the rest of the proposal. |
Now that we are at Stage 3, we can consider that the semantics are fixed (except for the relatively minor issue of private field access, see #28). In particular, optional deletion is not banned. |
Due to the evidence from CoffeeScript, I thought we agreed to remove all constructs from optional chaining except for
x.?y
,x?.[y]
andx?.(y)
. However, in this thread, @claudepache mentioned that optional chaining deletion is not yet banned. We should make it an early error in the draft spec, shouldn't we? Are there any other constructs that are currently allowed besides those three? The ambiguity here is delaying proper implementation in Babel.The text was updated successfully, but these errors were encountered: