Fix empty options (#803)
```js
// test.js
var prettier = require('./');
prettier.format('a=1');
```
```js
node test.js
// doesn't crash
```
This commit is contained in:
1 parent
c8c1875fc8
commit
2111f1152c
1 file changed
+5
-4
+5
-4
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user