Skip to content

fix(js): quote property name as es5 compatible#5157

Merged
duailibe merged 1 commit intoprettier:masterfrom
koba04:es5-compatible-property-name
Sep 28, 2018
Merged

fix(js): quote property name as es5 compatible#5157
duailibe merged 1 commit intoprettier:masterfrom
koba04:es5-compatible-property-name

Conversation

@koba04
Copy link
Copy Markdown
Contributor

@koba04 koba04 commented Sep 28, 2018

Currently, Prettier quotes property names if the name isn't es6 compatible.
It means that Prettier might strip the quote for a property name that is es6 compatible but is not es5 compatible.
So this might break scripts on ES5 environments.

For example, the following example doesn't work on some ES5 environments.
You can try the script on Node v0.12.

Prettier 1.14.3
Playground link

--parser babylon

Input:

var obj = {
 "𐊧": 'ok'
};

console.log(obj);

Output:

var obj = {
  𐊧: "ok"
};

console.log(obj);

This PR is to fix this.

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • I’ve read the contributing guidelines.

@j-f1 j-f1 requested a review from duailibe September 28, 2018 15:44
Copy link
Copy Markdown
Member

@lydell lydell left a comment

Choose a reason for hiding this comment

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

I think this makes sense. Haven't we said before that by default we don't want to turn es5 into es6 – that's the reason we won't default trailing-comma to "all"?

I think using this kind of identifiers is not very common, so it should be a non-controversial change.

So 👍 from me.

@duailibe duailibe merged commit 3e05f21 into prettier:master Sep 28, 2018
@koba04
Copy link
Copy Markdown
Contributor Author

koba04 commented Sep 29, 2018

Thank you!

@koba04 koba04 deleted the es5-compatible-property-name branch September 29, 2018 02:28
@ikatyang ikatyang added this to the 1.15 milestone Oct 25, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 23, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants