Distinguish between ternary's : and arrow fn's return type (#596)
This commit is contained in:
4
test/fixtures/flow/regression/issue-58-ambiguous/actual.js
vendored
Normal file
4
test/fixtures/flow/regression/issue-58-ambiguous/actual.js
vendored
Normal file
@@ -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
test/fixtures/flow/regression/issue-58-ambiguous/options.json
vendored
Normal file
3
test/fixtures/flow/regression/issue-58-ambiguous/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Ambiguous expression: wrap the arrow functions in parentheses to disambiguate. (4:4)"
|
||||
}
|
||||
2
test/fixtures/flow/regression/issue-58-failing-1/actual.js
vendored
Normal file
2
test/fixtures/flow/regression/issue-58-failing-1/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// Function which looks like a return type
|
||||
a ? (b) : (c => d) => e;
|
||||
3
test/fixtures/flow/regression/issue-58-failing-1/options.json
vendored
Normal file
3
test/fixtures/flow/regression/issue-58-failing-1/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Invalid left-hand side in arrow function parameters (2:11)"
|
||||
}
|
||||
2
test/fixtures/flow/regression/issue-58-failing-2/actual.js
vendored
Normal file
2
test/fixtures/flow/regression/issue-58-failing-2/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// Invalid LHS parameter after type parameters
|
||||
a ? <T>(b => c) : d => (e) : f => g;
|
||||
3
test/fixtures/flow/regression/issue-58-failing-2/options.json
vendored
Normal file
3
test/fixtures/flow/regression/issue-58-failing-2/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Invalid left-hand side in arrow function parameters (2:8)"
|
||||
}
|
||||
2
test/fixtures/flow/regression/issue-58-failing-3/actual.js
vendored
Normal file
2
test/fixtures/flow/regression/issue-58-failing-3/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// Invalid LHS parameter after type parameters
|
||||
a ? (b => c) => (e) : f => g;
|
||||
3
test/fixtures/flow/regression/issue-58-failing-3/options.json
vendored
Normal file
3
test/fixtures/flow/regression/issue-58-failing-3/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Invalid left-hand side in arrow function parameters (2:5)"
|
||||
}
|
||||
2
test/fixtures/flow/regression/issue-58-failing-4/actual.js
vendored
Normal file
2
test/fixtures/flow/regression/issue-58-failing-4/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// Invalid LHS parameter
|
||||
a ? async (b => c) => (d) : f => g;
|
||||
3
test/fixtures/flow/regression/issue-58-failing-4/options.json
vendored
Normal file
3
test/fixtures/flow/regression/issue-58-failing-4/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Invalid left-hand side in arrow function parameters (2:11)"
|
||||
}
|
||||
44
test/fixtures/flow/regression/issue-58/actual.js
vendored
Normal file
44
test/fixtures/flow/regression/issue-58/actual.js
vendored
Normal file
@@ -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}`;
|
||||
6551
test/fixtures/flow/regression/issue-58/expected.json
vendored
Normal file
6551
test/fixtures/flow/regression/issue-58/expected.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user