Skip to content

Fix pretty-printing strings with \u2028 or \u2029#1056

Merged
eventualbuddha merged 2 commits intobenjamn:masterfrom
djpohly:pretty-u2028-u2029
Feb 6, 2022
Merged

Fix pretty-printing strings with \u2028 or \u2029#1056
eventualbuddha merged 2 commits intobenjamn:masterfrom
djpohly:pretty-u2028-u2029

Conversation

@djpohly
Copy link
Contributor

@djpohly djpohly commented Feb 4, 2022

These two characters are considered ordinary characters by JSON but line
terminators by ECMAScript (prior to ES2019). When pretty-printing a
string containing either character, JSON.stringify leaves it unescaped.
The result in recast.prettyPrint is that fromString, which follows
ECMAScript definitions, converts it mistakenly to a newline character.

Escaping these characters manually when the intent is to generate
ECMAScript (rather than JSON) eliminates the problem.

These two characters are considered ordinary characters by JSON but line
terminators by ECMAScript (prior to ES2019).  When pretty-printing a
string containing either character, JSON.stringify leaves it unescaped.
The result in recast.prettyPrint is that fromString, which follows
ECMAScript definitions, converts it mistakenly to a newline character.

Escaping these characters manually when the intent is to generate
ECMAScript (rather than JSON) eliminates the problem.
@eventualbuddha eventualbuddha merged commit cb7ff9a into benjamn:master Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants