-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Ensure ASCII-safe output #4477
Comments
Agreed. Seems like we should add an encoding argument to the code generator and have it default to ASCII. |
I don’t think we need an option for it — this should just be the default behavior with no way to disable it. There’s no good reason to disable it, really. |
Patch that ensures the generated code for string literals is ASCII-safe: #4478. I can do the same thing for template literals, but that warrants more discussion. E.g., should this: var x = `
foo
bar
baz
`; …turn into this: var x = `\nfoo\nbar\nbaz\n`; …or not? I think it should, but a lot of tests expect otherwise, so I figured I’d ask. |
Input:
Current output: https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015&experimental=false&loose=false&spec=false&code=console.log(%0A%20%20'%5Cu%7B1D306%7D'%2C%0A%20%20%60%5Cu%7B1D306%7D%60%2C%0A%20%20%2F%5Cu%7B1D306%7D%2Fu%0A)%3B
Note that the output contains non-ASCII symbols, leading to potential encoding issues (e.g. if the server is not configured to serve the file as UTF-8) or just confusion. By transpiling to a pair of Unicode escape sequences (i.e.
\uD834\uDF06
in this case) this issue is avoided.cc @jayphelps
TL;DR we should ensure any generated code for the following literals is ASCII-safe:
The text was updated successfully, but these errors were encountered: