diff --git a/src/print/CallExpression.js b/src/print/CallExpression.js index 333ac83..f422f06 100644 --- a/src/print/CallExpression.js +++ b/src/print/CallExpression.js @@ -23,11 +23,7 @@ const printCallExpression = (node, path, print) => { // there is exactly one object parameter parts.push(mappedArguments[0], ")"); } else { - parts.push( - indent([softline, join([",", line], mappedArguments)]), - softline, - ")" - ); + parts.push(indent([join([", "], mappedArguments)]), ")"); } wrapExpressionIfNeeded(path, parts, node); diff --git a/src/print/MemberExpression.js b/src/print/MemberExpression.js index 71dc482..7ae0763 100644 --- a/src/print/MemberExpression.js +++ b/src/print/MemberExpression.js @@ -5,13 +5,13 @@ import { wrapExpressionIfNeeded } from "../util/index.js"; -const { group } = doc.builders; +const { group, indent, softline } = doc.builders; const printMemberExpression = (node, path, print) => { node[EXPRESSION_NEEDED] = false; node[STRING_NEEDS_QUOTES] = true; const parts = [path.call(print, "object")]; - parts.push(node.computed ? "[" : "."); + parts.push(node.computed ? "[" : indent([softline, "."])); parts.push(path.call(print, "property")); if (node.computed) { parts.push("]"); diff --git a/tests/Expressions/__snapshots__/chain_indentation.snap.twig b/tests/Expressions/__snapshots__/chain_indentation.snap.twig new file mode 100644 index 0000000..086921c --- /dev/null +++ b/tests/Expressions/__snapshots__/chain_indentation.snap.twig @@ -0,0 +1,25 @@ + + + + +{{ + craft + .entries + .section('news') + .section('news') + .orderBy('postDate DESC') + .limit(10) + .all(a.b) +}} + +{{ craft.entries.all() }} diff --git a/tests/Expressions/chain_indentation.twig b/tests/Expressions/chain_indentation.twig new file mode 100644 index 0000000..e368950 --- /dev/null +++ b/tests/Expressions/chain_indentation.twig @@ -0,0 +1,26 @@ + + + + +{{ craft.entries + .section("news") + .section("news") + .orderBy("postDate DESC") + .limit(10) + .all(a.b) }} + +{{ craft.entries.all() }} diff --git a/tests/Expressions/jsfmt.spec.js b/tests/Expressions/jsfmt.spec.js index 8a67e67..2637e0b 100644 --- a/tests/Expressions/jsfmt.spec.js +++ b/tests/Expressions/jsfmt.spec.js @@ -91,4 +91,14 @@ describe("Expressions", () => { }); await expect(actual).toMatchFileSnapshot(snapshotFile); }); + + it("Properly indent chain method", async () => { + const { actual, snapshotFile } = await run_spec(import.meta.url, { + source: "chain_indentation.twig", + formatOptions: { + experimentalMethodChainIndentation: true + } + }); + await expect(actual).toMatchFileSnapshot(snapshotFile); + }); });