Fix empty options (#803)

```js
// test.js
var prettier = require('./');
prettier.format('a=1');
```

```js
node test.js
// doesn't crash
```
master
Christopher Chedeau 2017-02-23 20:34:53 -08:00 committed by James Long
parent c8c1875fc8
commit 2111f1152c
1 changed files with 5 additions and 4 deletions

View File

@ -21,10 +21,12 @@ var exampleConfig = Object.assign({}, defaults, {
// Copy options and fill in default values.
function normalize(options) {
if (typeof options.trailingComma === "boolean") {
const normalized = Object.assign({}, options || {});
if (typeof normalized.trailingComma === "boolean") {
// Support a deprecated boolean type for the trailing comma config
// for a few versions. This code can be removed later.
options.trailingComma = "es5";
normalized.trailingComma = "es5";
console.warn(
"Warning: `trailingComma` without any argument is deprecated. " +
@ -32,8 +34,7 @@ function normalize(options) {
);
}
validate(options, { exampleConfig, deprecatedConfig });
const normalized = Object.assign({}, options || {});
validate(normalized, { exampleConfig, deprecatedConfig });
// For backward compatibility. Deprecated in 0.0.10
if ("useFlowParser" in normalized) {