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.

ES6 string and boolean operator and ternary produces strange result

See original GitHub issue

Prettier 1.10.2 Playground link

Input:

const message =
  `${originalErrorMessageString}\n` +
    `${normalizedError.stack}\n` +
    originalErrorStringified !== originalErrorMessageString
      ? `Original error: ${originalErrorStringified}`
      : "";

Output:

const message =
  `${originalErrorMessageString}\n` +
    `${normalizedError.stack}\n` +
    originalErrorStringified !==
  originalErrorMessageString
    ? `Original error: ${originalErrorStringified}`
    : "";

Expected behavior:

const message =
  `${originalErrorMessageString}\n` +
    `${normalizedError.stack}\n` +
    originalErrorStringified !== originalErrorMessageString
      ? `Original error: ${originalErrorStringified}`
      : "";

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xixixaocommented, Feb 16, 2018

@j-f1 updated, missed your comment.

1reaction
j-f1commented, Feb 2, 2018

Can you fill out the issue template please?

You should be able to go to the playground, put in your original code, click “Report issue,” then paste the result into your issue body.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rethinking the JavaScript ternary operator - James Sinclair
With the ternary operator, the second and third expressions can be any type. But the interpreter will always cast the first to a...
Read more >
Logical AND (&&) - JavaScript - MDN Web Docs
The logical AND (&&) (logical conjunction) operator for a set of boolean operands will be true if and only if all the operands...
Read more >
How do you use the ? : (conditional) operator in JavaScript?
The conditional (ternary) operator is the only JavaScript operator that takes three operands. This operator is frequently used as a shortcut for the...
Read more >
How the Question Mark (?) Operator Works in JavaScript
The term ternary means composed of three items or parts. The ? operator is also called the ternary operator because, unlike other operators...
Read more >
Conditional branching: if, '?'
Boolean conversion. The if (…) statement evaluates the expression in its parentheses and converts the result to a boolean. Let's recall the ...
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