This repository has been archived by the owner on May 19, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 256
Distinguish between ternary's : and arrow fn's return type #573
Merged
hzoo
merged 8 commits into
babel:master
from
nicolo-ribaudo:issue-58-ternary-arrow-flow
Jun 27, 2017
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eaef8f8
Distinguish between ternary's : and arrow fn's return type
nicolo-ribaudo 9d6e62e
Correctly parse nested arrow functions inside conditional expressions
nicolo-ribaudo 1db908a
Check params of arrow fns w/ type params or w/o return type
nicolo-ribaudo 4d93bd7
Fix also async functions
nicolo-ribaudo b43240c
Add test from prettier
nicolo-ribaudo 2f60733
Don't check arrow params if they are valid at the first attemp
nicolo-ribaudo 74ef24e
Use state instead of relying on the "noArrowParamsConversion" parameter
nicolo-ribaudo 8541f2c
Remove noArrowParamsConversion
nicolo-ribaudo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// 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; | ||
3 changes: 3 additions & 0 deletions
3
test/fixtures/flow/regression/issue-58-ambiguous/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate. (4:4)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Function which looks like a return type | ||
a ? (b) : (c => d) => e; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/flow/regression/issue-58-failing-1/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Invalid left-hand side in arrow function parameters (2:11)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Invalid LHS parameter after type parameters | ||
a ? <T>(b => c) : d => (e) : f => g; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/flow/regression/issue-58-failing-2/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Invalid left-hand side in arrow function parameters (2:8)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Invalid LHS parameter after type parameters | ||
a ? (b => c) => (e) : f => g; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/flow/regression/issue-58-failing-3/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Invalid left-hand side in arrow function parameters (2:5)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Invalid LHS parameter | ||
a ? async (b => c) => (d) : f => g; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/flow/regression/issue-58-failing-4/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Invalid left-hand side in arrow function parameters (2:11)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Valid lhs value inside parentheses | ||
a ? (b) : c => d; // a ? b : (c => d) | ||
a ? (b) : c => d : e; // a ? ((b): c => d) : e | ||
a ? (b) : (c) : d => e; // a ? b : ((c): d => e) | ||
|
||
// Nested arrow function inside parentheses | ||
a ? (b = (c) => d) : e => f; // a ? (b = (c) => d) : (e => f) | ||
a ? (b = (c) => d) : e => f : g; // a ? ((b = (c) => d): e => f) : g | ||
|
||
// Nested conditional expressions | ||
b ? c ? (d) : e => (f) : g : h; // b ? (c ? ((d): e => f) : g) : h | ||
a ? b ? c ? (d) : e => (f) : g : h; // a ? (b ? (c ? d : (e => f)) : g) : h | ||
|
||
a ? b ? (c) : (d) : (e) => f : g; // a ? (b ? c : ((d): e => f)) : g | ||
|
||
// Multiple arrow functions | ||
a ? (b) : c => d : (e) : f => g; // a ? ((b): c => d) : ((e): f => g) | ||
|
||
// Multiple nested arrow functions (<T> is needed to avoid ambiguities) | ||
a ? (b) : c => (d) : e => f : g; // a ? ((b): c => ((d): e => f)) : g | ||
a ? (b) : c => <T>(d) : e => f; // a ? b : (c => (<T>(d): e => f)) | ||
a ? <T>(b) : c => (d) : e => f; // a ? (<T>(b): c => d) : (e => f) | ||
|
||
// Invalid lhs value inside parentheses | ||
a ? (b => c) : d => e; // a ? (b => c) : (d => e) | ||
a ? b ? (c => d) : e => f : g; // a ? (b ? (c => d) : (e => f)) : g | ||
|
||
// Invalid lhs value inside parentheses inside arrow function | ||
a ? (b) : c => (d => e) : f => g; // a ? ((b): c => (d => e)) : (f => g) | ||
a ? b ? (c => d) : e => (f => g) : h => i; // a ? (b ? (c => d) : (e => (f => g))) : (h => i) | ||
|
||
// Function as type annotation | ||
a ? (b) : (c => d) => e : f; // a ? ((b): (c => d) => e) : f | ||
|
||
// Async functions or calls | ||
a ? async (b) : c => d; // a ? (async(b)) : (c => d) | ||
a ? async (b) : c => d : e; // a ? (async (b): c => d) : e | ||
a ? async (b => c) : d => e; // a ? (async(b => c)) : (d => e) | ||
a ? async (b) => (c => d) : e => f; // a ? (async (b) => c => d) : (e => f) | ||
|
||
// https://github.com/prettier/prettier/issues/2194 | ||
let icecream = what == "cone" | ||
? p => (!!p ? `here's your ${p} cone` : `just the empty cone for you`) | ||
: p => `here's your ${p} ${what}`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.