New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Placeholder scope/visibility #262
Comments
Yes, no, yes, yes. |
|
Each pipeline step needs a placeholder, and i would assume that a pipeline, being an expression, would be entirely contained by parens - meaning, your third example there seems like it might not parse. |
Potential userland scenario: to make functions reusable, fake stack can be organized in underscore chain fashion: let arg
const _ = a => arg = a,
add = a => arg += a
_(source) |> add(a) |> output(#) |
Does it mean parens are limitations to placeholder visibility? In that case boundaries should be more clearly defined... // if that's not valid
source |> a + (# |> b + #)
// then what about
source |> a + (a => # |> b + a)(#)
source |> a + (a => (# |> b + a))(#)
value |> foo(() => class { constructor() { return addEvent('x', function () { return () => [await x`${ # }`]})} } ) |
No, it’s saying that the inner pipeline could only parse in its entirety because it’s inside parens. Parens don’t affect placeholder visibility. |
although, it also might parse so the LHS of the inner pipeline is the outer pipeline’s placeholder? |
That's what I'd guess |
Keep in mind the following paragraphs from the explainer’s description:
This is formally defined in this early-errors section of the specification. So the lines in each of the following code blocks are equivalent to one another. source |> a => # + a |> output(#)
SyntaxError: Pipe body `a => # + a` is unparenthesized arrow function. Arrow function must be parenthesized. source |> (a => # + a) |> output(#)
output(a => source + a) source |> (a => # + a |> output(#))
a => output(source + a) const add= a => # + a
SyntaxError: Unbound topic `#` was found in `# + a`. Topics may only be used within pipe bodies. source |> add(a) |> output(#)
SyntaxError: Topic was not used within pipe body `add(a)`. source |> setTimeout(() => # + 1)
setTimeout(() => source + 1) _(source) |> add(a) |> output()
SyntaxError: Topic was not used within pipe body `add(a)`. let add = source |> a => # + a;
SyntaxError: Pipe body `a => # + a` is unparenthesized arrow function. Arrow function must be parenthesized. let add = source |> (a => #) + a;
let add = (a => source) + a; let add = source |> (a => # + a);
let add = (a => source + a); source |> a + # |> b + #
source |> (a + #) |> (b + #)
b + (a + source) source |> (a + # |> b) + #
SyntaxError: Topic was not used within pipe body `b`. source |> a + (# |> b + #)
source |> a + (b + #)
a + (b + source) source |> a + (# |> b + #)
source |> (a + #) |> (b + #)
b + (a + source) source |> a + (a => #.x |> b + a)(#)
source |> a + (a => (#.x |> b + a))(#)
SyntaxError: Topic was not used within pipe body `b + a`. source |> a + (a => #.x |> b + a + #)(#)
source |> a + (a => b + a + (#.x))(#)
source |> a + (a => (#.x |> b + a + #))(#)
source |> a + (a => (b + a + (#.x)))(#)
a + (a => b + a + source.x)(source)
a + (a => (b + a + source.x))(source) source |> a + (a => (# |> b + a))(#)
SyntaxError: Topic was not used within pipe body `b + a`. value |> foo(() => class { constructor() { return addEvent('x', function () { return () => [await x`${ # }`]})} } )
foo(() => class { constructor() { return addEvent('x', function () { return () => [await x`${ value }`]})} } ) In general, I would encourage developers to keep their pipe expressions’ bodies as small, simple, and readable as possible. In particular, I would avoid nesting pipe expressions within parentheses within pipe expressions: the purpose of pipes is to untangle nested parentheses, not to create more. |
Ternary has higher precedence than assignment, I guess there should not be a problem with |
After talking with some others, I’ve been reminded that talking about “precedence” with ternary operators (rather than only with binary/unary operators) is not very meaningful (thanks @bakkot). So we should rather reword the proposal explainer’s statement to say “similar precedence” rather than the “same precedence”. The proposal specification is still correct; it already distinguishes “identical precedence” from the conditional operator: “A PipeBody must not be an unparenthesized expression that is formed from any other operator with identical precedence (such as YieldExpression or ArrowFunction) or from the conditional operator.” |
This comment was marked as off-topic.
This comment was marked as off-topic.
This is a little off topic, but the weirdness here is that To the extent that ternary operators can even be considered to have precedence, it binds less tightly than |
This comment was marked as off-topic.
This comment was marked as off-topic.
Speaking of precedence, to clarify:
|
I think we intend to ban |
Prohibit ambiguous conditional expression ending with pipe expression, e.g., `a ? b : c |> d(%) |> e(%)`. See #262 (comment).
Following #261 − what are the boundaries for placeholder? (sorry if question was asked.)
The text was updated successfully, but these errors were encountered: