babel round trip bugs

two places where parse then generate does not give you back what you put in. every parser on this page is a real build from the babel monorepo; each pair differs only by the patch shown under it. the buttons swap which build runs.

1. a printed string literal becomes a directive

@babel/generator · not filed yet

("use strict") is not a directive: it is parenthesized, so the parser keeps it in body and the surrounding code stays sloppy. the generator drops the parens, and the string is read back as a directive. the code turns strict, and sometimes stops parsing altogether.


parse, print, parse again

inputbabel printsround trip

the change, packages/babel-generator

2. a line continuation that does not count as a line

@babel/parser · #17395

a backslash followed by U+2028 or U+2029 is a line continuation, same as a backslash followed by a newline. the parser forgot to count it, so every position after it landed one line short.


four inputs, each with one line break inside the string

sourcebreak isstring ends onx is onshould be

what a babel error would point at, for case 2

the change, packages/babel-helper-string-parser/src/index.ts