Skip to content

Conversation

@mathiasbynens
Copy link
Contributor

@mathiasbynens mathiasbynens commented Sep 8, 2016

Q A
Bug fix? no
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets #4477
License MIT
Doc PR none

Fixes #4477.

@mathiasbynens mathiasbynens mentioned this pull request Sep 8, 2016
3 tasks
@codecov-io
Copy link

codecov-io commented Sep 8, 2016

Current coverage is 88.32% (diff: 100%)

No coverage report found for master at 2b4e49d.

Powered by Codecov. Last update 2b4e49d...59e8a7d

'\x20';
"\n\r";
"😂";
`😂`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added this test to indicate that this patch only handles string literals and not template literals. (Regular expression literals are already taken care of through our use of regexpu.)

@mathiasbynens mathiasbynens changed the title transform-es2015-literals: Ensure ASCII-safe output babel-generator: Ensure ASCII-safe output for string literals Sep 8, 2016
let val = jsesc(node.value, {
quotes: t.isJSX(parent) ? "double" : this.format.quotes,
wrap: true
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of jsesc also allows us to get rid of the hacky parts below (i.e. remove double quotes, unescape double quotes, escape single quotes, add single quotes).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to remove all that 😄

Copy link
Member

@kangax kangax Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact: I updated Babel to 6.17 at Facebook and it broke one of our (PHP) parsers and the entire transform pipeline as a result :D After tedious investigation, I think this is the culprit. When someone uses "×" in our codebase (within custom tags) it's then transformed to '×' which Babel represented as '\u00D7' before. Now jsesc turns it into '\xD7'. Apparently PHP parser doesn't understand the latter. ¯_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kangax Which PHP parser is that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear god... Tracked it down further to json_decode returning null whenever there's \x in a string.

Copy link
Contributor Author

@mathiasbynens mathiasbynens Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually makes sense as JSON only supports \uXXXX-style escape sequences. (As a hotfix, you could use jsesc(string, { json: true }) here in Babel to enforce JSON output but really, it sounds like you need another parser since the intention is to parse JavaScript strings rather than JSON strings.)

@hzoo hzoo added the PR: Polish 💅 A type of pull request used for our changelog categories label Sep 8, 2016
@hzoo hzoo added this to the Next Patch milestone Sep 8, 2016
@hzoo
Copy link
Member

hzoo commented Sep 8, 2016

Actually, it would be nice if the changelog included new/removed deps

@hzoo hzoo merged commit b9919bd into babel:master Sep 8, 2016
novemberborn added a commit to novemberborn/babel-plugin-files that referenced this pull request Oct 17, 2016
Babel now generates ASCII-safe output for string literals, see
<babel/babel#4478>.
Copy link

@wenbing wenbing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it unreadable!

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 PR: New Dependency PR: Polish 💅 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure ASCII-safe output

7 participants