Skip to content
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

& lifting above function call when it's part of the function #1458

Closed
bbrk24 opened this issue Oct 13, 2024 · 2 comments
Closed

& lifting above function call when it's part of the function #1458

bbrk24 opened this issue Oct 13, 2024 · 2 comments

Comments

@bbrk24
Copy link
Contributor

bbrk24 commented Oct 13, 2024

`a${&}b` c
// vvv
($) => `a${$}b`(c);
@edemaine edemaine changed the title Missing parens -- calling string & lifting above function call when it's part of the function Oct 13, 2024
@edemaine
Copy link
Collaborator

edemaine commented Oct 13, 2024

The fundamental question here is whether & should lift above a function call when it's part of the function. Currently it does:

& x  $ => $(x)
&.simplify() x  $ => $.simplify()(x)

We definitely want e.g. &.toUpperCase() to lift above the call, so I think it makes sense.

Some of this might be related to ongoing discussion in #1450 about call chains, though that was for the . placeholder and this is about &.

If you need a way to stop lifting, I recommend do (though the output is pretty verbose here):

(do `a${&}b`) c
// vvv
(()=>{{ return $ => `a${$}b` }})()(c)

@STRd6
Copy link
Contributor

STRd6 commented Oct 13, 2024

I think this is the correct behavior. Another example to illustrate:

items.forEach .add 1
// items.forEach(($) => $.add(1));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants