diff --git a/src/printer/print/liquid.ts b/src/printer/print/liquid.ts index 47f5e02..008a2f8 100644 --- a/src/printer/print/liquid.ts +++ b/src/printer/print/liquid.ts @@ -370,10 +370,11 @@ export function printLiquidBlockStart( } if (lines.length > 1) { + const reindentedLines = reindent(lines, true); return group([ '{%', whitespaceStart, - indent([hardline, node.name, ' ', join(hardline, lines.map(trim))]), + indent([hardline, node.name, ' ', join(hardline, reindentedLines)]), hardline, whitespaceEnd, '%}', diff --git a/test/twig-set-object-indentation/fixed.liquid b/test/twig-set-object-indentation/fixed.liquid new file mode 100644 index 0000000..06a46b7 --- /dev/null +++ b/test/twig-set-object-indentation/fixed.liquid @@ -0,0 +1,14 @@ +It should preserve nested object indentation in multi-line set tags +{% + set defaultAttributes = { + id: null, + alt: null, + class: 'w-full h-full rounded-lg aspect-square object-cover border bg-neutral image-preview', + stimulus: { + controllers: { + target: 'target-name' + } + } + } +%} + diff --git a/test/twig-set-object-indentation/index.liquid b/test/twig-set-object-indentation/index.liquid new file mode 100644 index 0000000..afa0c3c --- /dev/null +++ b/test/twig-set-object-indentation/index.liquid @@ -0,0 +1,14 @@ +It should preserve nested object indentation in multi-line set tags +{% +set defaultAttributes = { + id: null, + alt: null, + class: 'w-full h-full rounded-lg aspect-square object-cover border bg-neutral image-preview', + stimulus: { + controllers: { + target: 'target-name' + } + } +} +%} + diff --git a/test/twig-set-object-indentation/index.spec.ts b/test/twig-set-object-indentation/index.spec.ts new file mode 100644 index 0000000..4587999 --- /dev/null +++ b/test/twig-set-object-indentation/index.spec.ts @@ -0,0 +1,6 @@ +import { assertFormattedEqualsFixed } from '../test-helpers'; +import * as path from 'path'; + +describe(`Unit: ${path.basename(__dirname)}`, () => { + assertFormattedEqualsFixed(__dirname); +});