From 6b7aa83820fc03b13e2b66f150861ecbcfc428d8 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 23 Feb 2017 07:34:52 -0800 Subject: [PATCH] Group [0] at the end of the previous chain instead of beginning of next one (#784) Fixes #775 --- src/printer.js | 7 +++++++ .../method-chain/__snapshots__/jsfmt.spec.js.snap | 15 +++++++++++++++ tests/method-chain/square_0.js | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 tests/method-chain/square_0.js diff --git a/src/printer.js b/src/printer.js index f9327f6a..c61ccf38 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2287,6 +2287,13 @@ function printMemberChain(path, options, print) { if ( hasSeenCallExpression && printedNodes[i].node.type === "MemberExpression" ) { + // [0] should be appended at the end of the group instead of the + // beginning of the next one + if (printedNodes[i].node.computed) { + currentGroup.push(printedNodes[i]); + continue; + } + groups.push(currentGroup); currentGroup = []; hasSeenCallExpression = false; diff --git a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap index 58f38770..604d125a 100644 --- a/tests/method-chain/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method-chain/__snapshots__/jsfmt.spec.js.snap @@ -242,6 +242,21 @@ if (testConfig.ENABLE_ONLINE_TESTS === \\"true\\") { " `; +exports[`square_0.js 1`] = ` +"const version = someLongString + .split('jest version =') + .pop() + .split(EOL)[0] + .trim(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const version = someLongString + .split(\\"jest version =\\") + .pop() + .split(EOL)[0] + .trim(); +" +`; + exports[`test.js 1`] = ` "method().then(x => x) [\\"abc\\"](x => x) diff --git a/tests/method-chain/square_0.js b/tests/method-chain/square_0.js new file mode 100644 index 00000000..89808dfe --- /dev/null +++ b/tests/method-chain/square_0.js @@ -0,0 +1,5 @@ +const version = someLongString + .split('jest version =') + .pop() + .split(EOL)[0] + .trim();