Keep object key with escape sequence as it is (#8160)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-04-27 10:30:00 +08:00
1 parent 99b0fae7e1
commit 82676f6308
4 files changed
+57

No files matched your search

@@ -0,0 +1,20 @@
#### Keep object key with escape sequence as it is ([#8160](https://github.com/prettier/prettier/pull/8160) by [@fisker](https://github.com/fisker))
<!-- prettier-ignore -->
```js
// Input
const a = {
"\u2139": 'why "\\u2139" converted to "i"?',
};
// Prettier stable
const a = {
ℹ: 'why "\\u2139" converted to "i"?',
};
// Prettier master
const a = {
"\u2139": 'why "\\u2139" is converted to "i"?',
};
```
+1
View File
@@ -729,6 +729,7 @@ function isStringPropSafeToCoerceToIdentifier(node, options) {
return (
isStringLiteral(node.key) &&
isIdentifierName(node.key.value) &&
rawText(node.key).slice(1, -1) === node.key.value &&
options.parser !== "json" &&
// With `--strictPropertyInitialization`, TS treats properties with quoted names differently than unquoted ones.
// See https://github.com/microsoft/TypeScript/pull/20075
@@ -1,5 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`escape sequence-key.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
// #6235
const a = {
'\\u2139': 'why "\\\\u2139" is converted to "i"?',
};
const a = {
"\\x66\\x69\\x73\\x6b\\x65\\x72": "\\x66\\x69\\x73\\x6b\\x65\\x72",
};
=====================================output=====================================
// #6235
const a = {
"\\u2139": 'why "\\\\u2139" is converted to "i"?',
};
const a = {
"\\x66\\x69\\x73\\x6b\\x65\\x72": "\\x66\\x69\\x73\\x6b\\x65\\x72",
};
================================================================================
`;
exports[`expand.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
+8
View File
@@ -0,0 +1,8 @@
// #6235
const a = {
'\u2139': 'why "\\u2139" is converted to "i"?',
};
const a = {
"\x66\x69\x73\x6b\x65\x72": "\x66\x69\x73\x6b\x65\x72",
};