What's the difference between LineTerminator and LineTerminatorSequence?

Hi all,

I'm an aspiring runtime developer, and just recently I've taken to trying to implement JavaScript late last year, however, there is one thing I find ambiguous...

What's the difference between LineTerminator and LineTerminatorSequence within the ECMAScript specification? Is it that the latter allows CR LF while the former does not? I'm not too clear on this, and whether they are interchangeable when either appears in the lexical or syntactic grammar. Are they interchangeable? Would an implementation that transforms CR and CR LF into LF when reading JavaScript source code before scanning and parsing be considered conforming to the specification?

They're subtly different, and the references to LineTerminatorSequence hint at this.

LineTerminator is used almost everywhere, but LineTerminatorSequence i used for a few niche cases where the actual code point sequence is important:

  1. Escaped newlines in strings consume the whole sequence (and emit nothing). Critically, it reads a Windows newline (CR+LF) as a single unit when skipping.
  2. In template literals, CR, LF, and CR+LF all three are normalized to LF in both raw and non-raw template literal parts.
  3. HTML comments, I assume for legacy reasons, rely on that for HTML comment end detection.

For everything else, it's fine to treat Windows newlines as two separate newlines, and so the spec doesn't need (or care about) the distinction.


I'm not a TC39 member, so feel free to correct me if I'm wrong about my interpretation.

Ah, thanks Claudia. For extra confidence, can someone from TC39 verify whether their interpretation is correct?