From 8efa29ca0c15b05a2da9ad110c91ee2476c228d3 Mon Sep 17 00:00:00 2001 From: Georgii Dolzhykov Date: Tue, 21 Jan 2020 17:55:43 +0200 Subject: [PATCH] fix object literal checks in isSimpleCallArgument (#7403) --- src/language-js/utils.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 42 +++++++++++++++++++ tests/method-chain/object-literal.js | 15 +++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/method-chain/object-literal.js diff --git a/src/language-js/utils.js b/src/language-js/utils.js index 5d94ff4e7..48431a0d1 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -926,9 +926,7 @@ function isSimpleCallArgument(node, depth) { } if (node.type === "ObjectExpression") { return node.properties.every( - p => - p.shorthand || - (isSimpleCallArgument(p.key, depth) && isChildSimple(p.value)) + p => !p.computed && (p.shorthand || (p.value && isChildSimple(p.value))) ); } if (node.type === "ArrayExpression") { diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index 5e6ca9bf0..cf8c4fe30 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -1176,6 +1176,48 @@ wrapper ================================================================================ `; +exports[`object-literal.js 1`] = ` +====================================options===================================== +parsers: ["flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +of("test") + .pipe(throwIfEmpty()) + .subscribe({ + error(err) { + thrown = err; + } + }); + +of("test") + .pipe(throwIfEmpty()) + .subscribe({ + get foo() { + bar(); + } + }); + +=====================================output===================================== +of("test") + .pipe(throwIfEmpty()) + .subscribe({ + error(err) { + thrown = err; + }, + }); + +of("test") + .pipe(throwIfEmpty()) + .subscribe({ + get foo() { + bar(); + }, + }); + +================================================================================ +`; + exports[`short-names.js 1`] = ` ====================================options===================================== parsers: ["flow", "typescript"] diff --git a/tests/method-chain/object-literal.js b/tests/method-chain/object-literal.js new file mode 100644 index 000000000..5b2d06ca4 --- /dev/null +++ b/tests/method-chain/object-literal.js @@ -0,0 +1,15 @@ +of("test") + .pipe(throwIfEmpty()) + .subscribe({ + error(err) { + thrown = err; + } + }); + +of("test") + .pipe(throwIfEmpty()) + .subscribe({ + get foo() { + bar(); + } + });