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

feat(json): enforce StringLiteral-style property key #4371

Merged
merged 2 commits into from Apr 25, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+19 −2
Diff settings

Always

Just for now

Prev

feat(json): enforce StringLiteral-style property key

  • Loading branch information...
ikatyang committed Apr 25, 2018
commit 0d4fddb785cdcea07a89900c2f3c055bf7591618
@@ -3068,6 +3068,23 @@ function printPropertyKey(path, options, print) {
const node = path.getNode();
const key = node.key;

if (
key.type === "Identifier" &&
!node.computed &&
options.parser === "json"
) {
// a -> "a"
return path.call(
keyPath =>
comments.printComments(
keyPath,
() => JSON.stringify(key.name),
options
),
"key"
);
}

if (
isStringLiteral(key) &&
isIdentifierName(key.value) &&
@@ -698,7 +698,7 @@ exports[`propertyKey.json 1`] = `
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
a: 123
"a": 123
}

`;
@@ -709,7 +709,7 @@ exports[`propertyKey.json 2`] = `
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
a: 123
"a": 123
}

`;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.