Additional Feature BA
December 8, 2018 · View on GitHub
| Name | Status | Features | Purpose |
|---|---|---|---|
| Core Proposal | Stage 0 | Infix pipelines … |> …Lexical topic # | Unary function/expression application |
| Additional Feature BC | None | Bare constructor calls … |> new … | Tacit application of constructors |
| Additional Feature BA | None | Bare awaited calls … |> await … | Tacit application of async functions |
| Additional Feature BP | None | Block pipeline steps … |> {…} | Application of statement blocks |
| Additional Feature PF | None | Pipeline functions +> | Partial function/expression application Function/expression composition Method extraction |
| Additional Feature TS | None | Pipeline try statements | Tacit application to caught errors |
| Additional Feature NP | None | N-ary pipelines (…, …) |> …Lexical topics ##, ###, and ... | N-ary function/expression application |
Additional Feature BA
ECMAScript No-Stage Proposal. Living Document. J. S. Choi, 2018-12.
This document is not yet intended to be officially proposed to TC39 yet; it merely shows a possible extension of the Core Proposal in the event that the Core Proposal is accepted.
An additional feature – bare awaited calls – would make async function calls terser. It adds
another mode to bare style: if a bare-style pipeline step is preceded by a
await, then instead of a mere function call, it is an awaited function call.
value |> await object.asyncFunction is equivalent to await object.asyncFunction(value). This would be backwards compatible with the Core
Proposal as well as all other additional features.
Additional Feature BA is formally specified in in the draft specification.
| With smart pipelines | Status quo |
|---|---|
|
|
If a pipeline step starts with await, followed by a mere identifier, optionally with
a chain of properties, and with no parentheses or brackets, then that identifier
is interpreted to be a bare awaited function call.
That is: if a pipeline is of the form
topic |> await identifier
or topic |> await identifier0.identifier1
or topic |> await identifier0.identifier1.identifier2
or so forth,
then the pipeline is a bare async function call.
| Valid topic style | Valid bare style | Invalid pipeline |
|---|---|---|
… |> await af(#) | … |> await af | … |> await af() 🚫 |
| ″″ | ″″ | … |> (await f) 🚫 |
| ″″ | ″″ | … |> (await f()) 🚫 |
| ″″ | ″″ | … |> await (f) 🚫 |
| ″″ | ″″ | … |> await (f()) 🚫 |
… |> af |> await # | ″″ | … |> af |> await 🚫 |
… |> await o.f(#) | … |> await o.f | … |> await o.f() 🚫 |
… |> await o.make()(#) | const af = o.make(); … |> await af | … |> await o.make() 🚫 |
… |> await new o.make()(#) | const af = new o.make(); … |> await af | … |> new await o.make() 🚫 |
[Unix pipe]: https://en.wikipedia.org/wiki/Pipeline_(Unix
[untangled flow]: ./goals.md#untangled-flow
[Visual Basic’s select statement]: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement
[WebKit console variables]: https://webkit.org/blog/829/web-inspector-updates/
[WHATWG Fetch + CP]: ./core-real-examples.md#whatwg-fetch-standard
[WHATWG Fetch Standard]: https://fetch.spec.whatwg.org/
[WHATWG Streams + CP + BP + PF + NP]: ./additional-feature-np.md#whatwg-streams-standard-core-proposal--additional-features-bppfmt
[WHATWG Streams + CP + BP + PF]: ./additional-feature-pf.md#whatwg-streams-standard-core-proposal--additional-feature-bppf
[WHATWG Streams Standard]: https://stream.spec.whatwg.org/
[WHATWG-stream piping]: https://streams.spec.whatwg.org/#pipe-chains
[Wikipedia: term rewriting]: https://en.wikipedia.org/wiki/Term_rewriting
[zero runtime cost]: ./goals.md#zero-runtime-cost