question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ternary operator > lambda > ternary fails to parse himself after formatting

See original GitHub issue

The following nested ternary

let icecream = what == "cone"
  ? p => !!p ? `here's your ${p} cone` : `just the empty cone for you`
  : p => `here's your ${p} ${what}`;

gets formatted to

let icecream = what == "cone"
  ? p => (!!p ? `here's your ${p} cone` : `just the empty cone for you`)
  : p => `here's your ${p} ${what}`;

which consequently fails a subsequent parsing with SyntaxError: Invalid left-hand side in arrow function parameters (2:11);

(using prettier 1.44)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
existentialismcommented, Oct 2, 2017

I have a PR ready for this, but the latest Babylon version can’t be bumped in Prettier b/c we split the TS/Flow types. I have an update ready for this as well but waiting for an upstream change in typescript-eslint-parser to land.

1reaction
hzoocommented, Jun 19, 2017

Looks related to issues regarding https://github.com/babel/babylon/issues/58

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recursion with ternary operator 'hack' in Python - Stack Overflow
import ast tree = ast.parse('lambda S,b : (g(S[1:],b),S)[len(S)==b]') ast.dump(tree). After some formatting done in vim this is what I got:
Read more >
Conditional (ternary) operator - JavaScript - MDN Web Docs
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?)
Read more >
Ternary Operator in Python - GeeksforGeeks
Ternary operators are also known as conditional expressions are operators that evaluate something based on a condition being true or false.
Read more >
Java static code analysis: The ternary operator should not be ...
While the ternary operator is pleasingly compact, its use can make code more difficult to read. It should therefore be avoided in favor...
Read more >
How to use Java's conditional operator ?: | TheServerSide
Quickly learn how to use the Java ternary operator and see how this ... after question mark, and causes a compile error: Type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found