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

Ensure ASCII-safe output #4477

Closed
2 of 3 tasks
mathiasbynens opened this issue Sep 8, 2016 · 3 comments · Fixed by #4478
Closed
2 of 3 tasks

Ensure ASCII-safe output #4477

mathiasbynens opened this issue Sep 8, 2016 · 3 comments · Fixed by #4478
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@mathiasbynens
Copy link
Contributor

mathiasbynens commented Sep 8, 2016

Input:

console.log(
  '\u{1D306}',
  `\u{1D306}`,
  /\u{1D306}/u
);

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

'use strict';

console.log('𝌆', '𝌆', /(?:\uD834\uDF06)/);

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:

@loganfsmyth
Copy link
Member

loganfsmyth commented Sep 8, 2016

Agreed. Seems like we should add an encoding argument to the code generator and have it default to ASCII.

@mathiasbynens
Copy link
Contributor Author

mathiasbynens commented Sep 8, 2016

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.

@mathiasbynens mathiasbynens changed the title transform-es2015-literals: ensure ASCII-safe output Ensure ASCII-safe output Sep 8, 2016
@mathiasbynens
Copy link
Contributor Author

mathiasbynens commented Sep 8, 2016

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.

@hzoo hzoo closed this as completed in #4478 Sep 8, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 6, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants