Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Windows line endings correctly in inline templates #247

Merged
merged 3 commits into from
Jan 14, 2022

Conversation

dfreeman
Copy link
Member

Fixes #224.

Today I learned that, according to the ECMAScript spec, when the sequence \r\n (not the escapes, but the actual characters they represent) appears in the contents of a template string, they're normalized to be treated the same as a single \n.

The TRV of LineTerminatorSequence :: <CR> <LF> is the String value consisting of the code unit 0x000A (LINE FEED).

Babel honors this, causing template strings parsed from files using Windows line endings to be "missing" their \rs in the value their AST node contains. This, in turn, meant we were getting off-by-n errors in inline templates, where n was the number of lines into the template we were looking at any given time.

To avoid this problem, when we deal with embedded templates, we now determine their contents by slicing them directly from the original source text instead of retrieving their parsed value from the TemplateElement node.

@dfreeman dfreeman added the bug Something isn't working label Jan 14, 2022
@dfreeman dfreeman merged commit f2a6d6e into main Jan 14, 2022
@dfreeman dfreeman deleted the windows-line-endings branch January 14, 2022 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[windows] incorrect errors mapping for templates
1 participant