From 2111f1152c314d287338de77066eca00a3854632 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 23 Feb 2017 20:34:53 -0800 Subject: [PATCH] Fix empty options (#803) ```js // test.js var prettier = require('./'); prettier.format('a=1'); ``` ```js node test.js // doesn't crash ``` --- src/options.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/options.js b/src/options.js index 997af9edc..1c83cce80 100644 --- a/src/options.js +++ b/src/options.js @@ -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) {