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
Implement f# pipeline in parser #9450
Implement f# pipeline in parser #9450
Conversation
0ce397e
to
2fd61a8
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10691/ |
2fd61a8
to
b08f341
Compare
Just pushed solo await parsing in the pipeline, courtesy of @thiagoarrais. Want to confirm the tests pass, but will also be pushing some tests so Thiago & I can collaborate on them. |
Actually may have gotten parenless arrow functions parsing. cc @littledan & @nicolo-ribaudo Definitely interested in suggested tests to add here / what cases I haven't covered. |
Remove the lookahead check and just set that a potential arrow function is there.
2857ab2
to
7b75aa4
Compare
Note that this AST is a modified implementation of what I inquired about here. The idea is to treat the x => x |> y => y + 1 |> z => z * 2 which parses as (fully paren'd): x => (x |> (y => y + 1) |> (z => z * 2)) I don't know yet if the fact that it's feasible in babel means it's feasible from a spec perspective. Will need those with more expertise to weigh in. Also note that accepting F# w/ parenless arrows may conflict with the movements toward making Smart Pipelines a superset of F# Pipelines. |
Needs to be solo or wrapped in parens. Also update function name to test in `await` tests so we can use `await f` in the ban test name.
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.
Question: why do we need the PipelineHead
and PipelineBody
nodes?
Can't a |> b
just be BinaryOperator(op: |>, left: Identifier, right: Identifier)
? They can be parsed differently even if the nodes aren't present in the AST.
...ges/babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/input.js
Outdated
Show resolved
Hide resolved
.../babel-parser/test/fixtures/experimental/pipeline-operator/proposal-fsharp-await/output.json
Show resolved
Hide resolved
My understanding of the spec was we needed the different nodes to provide different precedence values related to the arrow function, depending on whether it's in the Head or Body. But this is not my strong suit, so I would need someone else to weigh in here. |
I think that we should remove those nodes if (and only if) it is possible to understand if a node is the equivalent of a To my understanding, if |
@nicolo-ribaudo Yeah, that's correct. I can remove those nodes, but we do want to keep babel's produced AST in line with the spec, correct? If so, and we decide the spec requires them, would changing the AST be a breaking change? I'm not entirely clear on the spec needs here, and my understanding is Babel's AST should match the spec's AST, so I want to make sure we keep them in alignment before we remove anything. That said, I could easily be wrong about the spec's needs here, so I want to keep an eye on potential paths forward as we settle on the F# parenless AST. |
It occurred to me this might be fixed in master. Merged that up. |
.../pipeline-operator/proposal-fsharp-arrow-in-body-no-parens-indented-with-arg-parens/input.js
Show resolved
Hide resolved
Dismissing approval because the test I commented asking to add a comment in the code was actually wrong
This should resolve the scoping issues we're seeing in the transform.
a0a2ece
to
7e17e56
Compare
...est/fixtures/experimental/pipeline-operator/proposal-fsharp-arrow-and-array-in-body/input.js
Show resolved
Hide resolved
This also needs to check, when there's a pipeline operator within the arrow or object, that it parses correctly.
More nested pipeline logic.
@nicolo-ribaudo Addressed your comments / questions. I think we still need |
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 think so. The Smart proposal has a PipelineBody node as well.
Actually it looks like it's defined in types.js
but it is never created in the parser. The Smart proposals has nodes like PipelineBareFunction
, but it's there because it's different from a simple identifier/member expression.
Also, in the Smart proposal makes sense to have different nodes since, for example, a PipelineBareFunction
and a PipelineTopicExpression
have different meanings, while in the F# proposal it would always only be PipelineBody
This isn't strictly need, as it's just an extra layer of nesting and provides no additional information.
Removed the |
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.
Nice work!
Was wondering (not specific to this PR) about how we would go about removing the different options in the future (once a proposal moves forward). I guess with the new state it doesn't seem that bad to remove (wish it was easier but unlikely that is possible to do easily). But would love to write more docs on the overall process we are going to take moving forward regarding multiple proposals and also the lifecycle of this process (implementation, deprecation, removal, acceptance, etc)
This reverts commit d6c39ee.
This is still very much "Work-in-Progress", but since I mostly don't know what I'm doing, I wanted to get this up early so I can get some feedback on alternate approaches, suggestions on the AST, etc. The two main things left are:
await
parsingcc @js-choi @littledan