diff --git a/src/index.ts b/src/index.ts index 2eced5ba..ac96c40f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -435,8 +435,17 @@ export const plugin: Plugin = { break; } case 'interpolated-code': - if (previousToken && previousToken.type === 'tag') { - result += ' '; + if (previousToken) { + switch (previousToken.type) { + case 'tag': + case 'end-attributes': + result += ' '; + break; + case 'indent': + result = printIndent(previousToken, result, indent, indentLevel); + result += '| '; + break; + } } result += `#{${token.val}}`; break; diff --git a/test/issues/issue-27/formatted.pug b/test/issues/issue-27/formatted.pug new file mode 100644 index 00000000..184725a8 --- /dev/null +++ b/test/issues/issue-27/formatted.pug @@ -0,0 +1,3 @@ +tag(key="value") #{identifier} +tag + | #{identifier} diff --git a/test/issues/issue-27/issue-27.test.ts b/test/issues/issue-27/issue-27.test.ts new file mode 100644 index 00000000..fd207974 --- /dev/null +++ b/test/issues/issue-27/issue-27.test.ts @@ -0,0 +1,14 @@ +import { readFileSync } from 'fs'; +import { resolve } from 'path'; +import { format } from 'prettier'; +import { plugin } from './../../../src/index'; + +describe('Issues', () => { + test('should interpolation', () => { + const expected: string = readFileSync(resolve(__dirname, 'formatted.pug'), 'utf8'); + const code: string = readFileSync(resolve(__dirname, 'unformatted.pug'), 'utf8'); + const actual: string = format(code, { parser: 'pug' as any, plugins: [plugin] }); + + expect(actual).toBe(expected); + }); +}); diff --git a/test/issues/issue-27/unformatted.pug b/test/issues/issue-27/unformatted.pug new file mode 100644 index 00000000..3cc1f697 --- /dev/null +++ b/test/issues/issue-27/unformatted.pug @@ -0,0 +1,3 @@ +tag(key='value') #{identifier} +tag + | #{identifier}