-
-
Notifications
You must be signed in to change notification settings - Fork 256
Distinguish between ternary's : and arrow fn's return type #573
Distinguish between ternary's : and arrow fn's return type #573
Conversation
Codecov Report
@@ Coverage Diff @@
## master #573 +/- ##
==========================================
+ Coverage 98.14% 98.18% +0.03%
==========================================
Files 22 22
Lines 3663 3737 +74
Branches 1024 1038 +14
==========================================
+ Hits 3595 3669 +74
Misses 25 25
Partials 43 43
Continue to review full report at Codecov.
|
Defer the conversion of arrow function parameters to assignable nodes so that it is possible to use the (invalid) ast to get the exact position of the (wrong) arrow functions.
I'm not 100% sure, but I couldn't find any example for which this check is wrong
|
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 don't like having changed the main parser (adding noArrowParamsConversion
— checkFunctionLVals
was created just to avoid duplicationg code in flow.js) to fix a bug in a plugin, but I couldn't find a better method.
// This can be parsed in two ways: | ||
// a ? b : (c => ((d): e => f)) | ||
// a ? ((b): c => d) : (e => f) | ||
a ? (b) : c => (d) : e => f; |
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.
Here throwing is the most future-compatible behavior. Probably we should ask to the flow team how to handle this cases.
Would be awesome if you could add prettier/prettier#2194 (comment) as a test case. Thanks so much for fixing a bug before it was even discovered in prettier! |
@vjeux Test added 👍 @anyoneFromTheBabelTeam Do you prefer that I resolve the merge conflicts by rebasing or by merging |
@nicolo-ribaudo awesome, thanks a ton! I can't wait for it to ship! |
@nicolo-ribaudo rebase although if it's a simple change with 1 author we just squash merge it anyway |
Fyi, this bug was also found by a Facebook employee during a conversion. So it's at least impacting two people :) |
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 struggled with the same "wish we didn't have to add yet-another-param in the core parser code" for this a while back, but I think we can just improve our param-sanity later :)
@existentialism I'm trying to remove that parameter, but I can't guarantee I will succeed: this PR could be merged with that ugly parameter and I'll open another one when it will be ready |
@existentialism I managed to remove that parameter! (And magically solved the merge conflicts while doing that 😎) 8541f2c ( |
@nicolo-ribaudo nice! @hzoo and I were discussing using state for this vs a param a while back too! Can also use a set for But for now, LGTM 👍 |
I searched in the babylon source code and it doesn't seem to use any ES6 function: wouldn't using Anyway, I think EDIT: It looks that if the array is short, Array#indexOf is faster than Set#has (at least on Chrome & Firefox on Ubuntu 17):
|
The initial purpose of Babel 7 was just to drop Node 0.10/0.12. We are using Set in other parts of Babel already and it helped us to drop babel-runtime as dep (Symbol as well), so that's not an idea. But yeah if those specific cases won't have a lot of items then we don't have to change it. |
Actually was getting a lot of errors locally for flow |
Errors fixed in #596 |
Only the flow test suite is optional, not the type checks. Actually it looks like they pass on travis-ci: https://travis-ci.org/babel/babylon/jobs/246895911
|
Oh ok that was confusing then |
I took this approach:
?
, try to parse an assignment expression (consequent)a. Disallow arrow functions in the first position
a. Parse the assignment expression again (consequent)
:
a. Find every typed arrow function in that expression
b. If there are more than one, trow an "Ambiguity" error ¹
c. Mark the arrow function so that it is parsed as
ParenthesizedExpression : ArrowFunctionExpression
d. Parse the assignment expression again (consequent)
:
a ? (b) : c => (d => e) : f => g;
. I think I have to rewrite 3.b and 3.c