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
Support right precedence hack-style pipeline #11557
Support right precedence hack-style pipeline #11557
Conversation
b0184cd
to
9fa6e27
Compare
|> (await %) | ||
|> % || throw new Error(\`foo \${bar1}\`) | ||
|> bar2(%, ", ") | ||
|> bar3(%) | ||
|> % + "!" | ||
|> new Bar.Foo(%) | ||
|> (await bar.bar(%)) | ||
|> console.log(%); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the best way, but following official explainer, we don't add indent on here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's clear for me to indent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fisker I prefer no indentation. Also other languages code formatter outputs following:
Elixir (by mix format
)
Input:
100 |> foo(1) |> bar(2) |> baz(3) |> bar(2) |> baz(3) |> bar(2) |> baz(3)
output:
100
|> foo(1)
|> bar(2)
|> baz(3)
|> bar(2)
|> baz(3)
|> bar(2)
|> baz(3)
F# (by Fantomas)
input:
100 |> function1 |> function2 |> function1 |> function2 |> function1 |> function2 |> function1 |> function2
output:
100
|> function1
|> function2
|> function1
|> function2
|> function1
|> function2
|> function1
|> function2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't convince me. I'd like to hear opinions from other maintainers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I have no strong opinion for this. So for now, let's use indentation version, same as current Prettier.
d86a003
to
38e5972
Compare
Let me understand the problem here
|
No!
Why? Hack pipeline is right-associative operators, so it is no problem to flat it?
When we don't flat it... input: const searchResults$ = fromEvent(document.querySelector('input'), 'input')
|> map(%, event => event.target.value)
|> filter(%, searchText => searchText.length > 2)
|> debounce(%, 300)
|> distinctUntilChanged(%)
|> switchMap(%, searchText => queryApi(searchText) |> retry(%, 3))
|> share(%); output: const searchResults$ =
fromEvent(document.querySelector("input"), "input")
|> (map(%, (event) => event.target.value)
|> (filter(%, (searchText) => searchText.length > 2)
|> (debounce(%, 300)
|> (distinctUntilChanged(%)
|> (switchMap(%, (searchText) => queryApi(searchText) |> retry(%, 3))
|> share(%)))))); |
I don't know, my guess.
|
Bumps [@babel/parser](https://github.com/babel/babel/tree/HEAD/packages/babel-parser) from 7.15.5 to 7.15.7. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.15.7/packages/babel-parser) --- updated-dependencies: - dependency-name: "@babel/parser" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [@babel/parser](https://github.com/babel/babel/tree/HEAD/packages/babel-parser) from 7.15.5 to 7.15.6. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.15.6/packages/babel-parser) --- updated-dependencies: - dependency-name: "@babel/parser" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
38e5972
to
634138a
Compare
@@ -149,7 +149,8 @@ function createParse(parseMethod, ...optionsCombinations) { | |||
throw createBabelParseError(error); | |||
} | |||
|
|||
return postprocess(ast, { ...opts, originalText: text }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of scope: opts
is big object, so maybe it is good that we don't copy it for other parsers too.
@fisker Can you review again? |
|
yes. (Babel) Input: 1 + 100 |> a(%) Output: "use strict";
var _ref;
_ref = 1 + 100, a(_ref); |
|> (yield %) | ||
|> (await %) | ||
|> y(%) | ||
|> a.b(%) | ||
|> a.b(%) | ||
|> a.b(%) | ||
|> a.b?.(%) | ||
|> a.b?.(%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fisker I've updated snapshots with indentation version (#11557 (comment)). What do you think this change? ( After seeing this change, I personally reconsidered and decided that it would be better to be consistent without indentation. )
e441842
to
634138a
Compare
I don't like that this PR is blocker to update babel/parser. So I'll merge this with the unindent version for now. Let's discuss in another issue. Since this syntax is not used by most users, there is no pain to change the behavior. |
Description
Hack-style pipeline operators are right-associative.
babel/parser@7.15.5
treats it as left-associative,babel/parser@7.15.6
treats it as right-associative.ref: babel/babel#13668
ref: babel/babel#13668 (comment)
Clsoes #11540
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨