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.

http://www.ecma-international.org/ecma-262/7.0/index.html#sec-line-terminators

Code Point Unicode Name Abbreviation
U+000A LINE FEED (LF) <LF>
U+000D CARRIAGE RETURN (CR) <CR>
U+2028 LINE SEPARATOR <LS>
U+2029 PARAGRAPH SEPARATOR <PS>

 LineTerminatorSequence::
    <LF>
    <CR>[lookahead ≠ <LF>]
    <LS>
    <PS>
    <CR><LF>

(In practice these days, everyone uses \n/<LF> except Windows which uses \r\n/<CR><LF>.)

It seems like prettier sometimes assumes that \n/<LF> is the only newline. We need to grep through the code base and fix those cases.

A question is how it should be fixed. Use utility functions everywhere? It’s easy to forget, though, and add new places of .indexOf('\n') and similar in the future. Another idea is to replace all other newlines before parsing: text.replace(/\r\n|[\r\u2028\u2029]/g, '\n').

EDIT: No we cannot replace all line terminal sequences before parsing. That would change the contents of template literals and multiline strings.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
vjeuxcommented, Jan 31, 2017

I don’t think that we should handle anything except for \r and \r\n. For those two, we should have good support, if something is broken, please report an error and we’ll fix it. The big things are:

Looks like there’s a few places where we only consider \n in the printer https://github.com/jlongster/prettier/blob/master/src/printer.js that we need to fix (search for \n)

0reactions
lydellcommented, Feb 1, 2017

Just for future reference:

Normalizing \r, \u2028 and \u2029 to either \n or \r\n is a thing that prettier could do, but I guess it’s not worth it.

This statement is wrong. prettier already does exactly this normalization. And it leaves all line terminator characters inside strings alone as it should.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Line terminator - Wikipedia
Line terminator · Newline, a special character or sequence of characters signifying the end of a line of text · Electrical termination, at...
Read more >
What is a Line Terminator and how does it apply to comments?
A line terminator is an actual ascii character which is invisible to humans but important to computers. The line terminator character tells ...
Read more >
Line terminators - Informatica Documentation
A line terminator is a one or two-character sequence that marks the end of a line of the input character sequence. The following...
Read more >
3.4. Line Terminators - The Java® Language Specification ...
3.4. Line Terminators ... A Java compiler next divides the sequence of Unicode input characters into lines by recognizing line terminators. ... Lines...
Read more >
Line terminators on Windows and UNIX - 4Js
On Windows™ platforms, DOS formatted text files use CR/LF as line terminators. You can manage these type of files with the base.Channel class....
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 Hashnode Post

No results found