Fix key quotes omission for flow parser (#203)

```js
echo 'var { "key": val } = 1;' | ./bin/prettier.js --stdin --flow-parser
var { key: val } = 1;
```
master
Christopher Chedeau 2017-01-14 20:40:26 -08:00 committed by James Long
parent fe959631c1
commit 15cc3bb778
3 changed files with 7 additions and 3 deletions

View File

@ -1587,7 +1587,11 @@ function printStatementSequence(path, options, print) {
function printPropertyKey(path, print) {
var node = path.getNode().key;
if (node.type === "StringLiteral" && isIdentifierName(node.value)) {
if (
(node.type === "StringLiteral" ||
node.type === "Literal" && typeof node.value === "string") &&
isIdentifierName(node.value)
) {
// 'a' -> a
return node.value;
}

View File

@ -555,7 +555,7 @@ exports[`test string_lit.js 1`] = `
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };
(with_dash: \"motivating example\"); // ok
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var { \"key\": val } = { key: \"val\" };
var { key: val } = { key: \"val\" };
(val: void);
// error: string ~> void
var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" };

View File

@ -161,7 +161,7 @@ var f: typeof numberAlias = 42;
* These provoke a specific error, not just the generic
* \"type is incompatible\"
*/
var Map = { \"A\": \"this is A\", \"B\": \"this is B\", \"C\": \"this is C\" };
var Map = { A: \"this is A\", B: \"this is B\", C: \"this is C\" };
var keys: $Keys<Map> = \"A\"; // Error: ineligible value used in type anno
"
`;