Skip to content

feat: don't quote valid IdentifierNames in pretty json of PnP hook #3965

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

Closed
wants to merge 1 commit into from

Conversation

paul-soporan
Copy link
Member

What's the problem this PR addresses?

Reading the serialized state inside of the PnP hook is more painful than it has to be because all object properties are quoted even when they don't need to be, and most themes use the same color for quoted object keys and quoted object values [citation needed].

How did you fix it?

Made generatePrettyJson skip quoting keys when it's not required.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

If we don't quote them it isn't a valid JSON string anymore so I don't think we should do this.

@paul-soporan
Copy link
Member Author

It's not valid JSON on master either because of trailing commas and we currently use JSON.stringify for the split setup anyways.

@merceyz
Copy link
Member

merceyz commented Jan 8, 2022

I've noticed that as well and have a branch fixing it but haven't gotten around to making a PR yet

@paul-soporan
Copy link
Member Author

Ah, I was intending to implement a "strict JSON mode" in a future PR (gating both of these things that make it invalid JSON behind it) so that we can use generatePrettyJson for .pnp.data.json too. In this case, do you want me to gate it behind the flag now and let you fix that issue later and make .pnp.data.json use it too?

@merceyz
Copy link
Member

merceyz commented Jan 8, 2022

The reason I wanted it to be a valid JSON string is because I was working on using JSON.parse on it since it's supposed to be faster for V8 to parse1. Sadly it turns out that using a multiline template literal is slower so I left it alone for now.

With that backstory out of the way, since the function is private we could rename it and my objection would be gone assuming the lack of quotes doesn't affect the startup time 👍

Footnotes

  1. https://v8.dev/blog/cost-of-javascript-2019#json

@paul-soporan paul-soporan deleted the paul/feat/pretty-json-quotes branch January 18, 2022 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants