Fix empty options (#803)
```js // test.js var prettier = require('./'); prettier.format('a=1'); ``` ```js node test.js // doesn't crash ```master
parent
c8c1875fc8
commit
2111f1152c
|
@ -21,10 +21,12 @@ var exampleConfig = Object.assign({}, defaults, {
|
||||||
|
|
||||||
// Copy options and fill in default values.
|
// Copy options and fill in default values.
|
||||||
function normalize(options) {
|
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
|
// Support a deprecated boolean type for the trailing comma config
|
||||||
// for a few versions. This code can be removed later.
|
// for a few versions. This code can be removed later.
|
||||||
options.trailingComma = "es5";
|
normalized.trailingComma = "es5";
|
||||||
|
|
||||||
console.warn(
|
console.warn(
|
||||||
"Warning: `trailingComma` without any argument is deprecated. " +
|
"Warning: `trailingComma` without any argument is deprecated. " +
|
||||||
|
@ -32,8 +34,7 @@ function normalize(options) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(options, { exampleConfig, deprecatedConfig });
|
validate(normalized, { exampleConfig, deprecatedConfig });
|
||||||
const normalized = Object.assign({}, options || {});
|
|
||||||
|
|
||||||
// For backward compatibility. Deprecated in 0.0.10
|
// For backward compatibility. Deprecated in 0.0.10
|
||||||
if ("useFlowParser" in normalized) {
|
if ("useFlowParser" in normalized) {
|
||||||
|
|
Loading…
Reference in New Issue