From 4c0d897838976ba9fc3f1c623af9552ee9f26b13 Mon Sep 17 00:00:00 2001 From: Christopher Quadflieg Date: Sat, 4 Jan 2020 17:53:46 +0100 Subject: [PATCH 1/3] Add test for issue 52 --- test/issues/issue-52/formatted.pug | 3 +++ test/issues/issue-52/issue-52.test.ts | 14 ++++++++++++++ test/issues/issue-52/unformatted.pug | 3 +++ 3 files changed, 20 insertions(+) create mode 100644 test/issues/issue-52/formatted.pug create mode 100644 test/issues/issue-52/issue-52.test.ts create mode 100644 test/issues/issue-52/unformatted.pug diff --git a/test/issues/issue-52/formatted.pug b/test/issues/issue-52/formatted.pug new file mode 100644 index 00000000..dbe9c6b2 --- /dev/null +++ b/test/issues/issue-52/formatted.pug @@ -0,0 +1,3 @@ +- const variableWithHtmlString = ''; +div + | !{variableWithHtmlString} diff --git a/test/issues/issue-52/issue-52.test.ts b/test/issues/issue-52/issue-52.test.ts new file mode 100644 index 00000000..c8c08aea --- /dev/null +++ b/test/issues/issue-52/issue-52.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 handle literal line', () => { + 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-52/unformatted.pug b/test/issues/issue-52/unformatted.pug new file mode 100644 index 00000000..dbe9c6b2 --- /dev/null +++ b/test/issues/issue-52/unformatted.pug @@ -0,0 +1,3 @@ +- const variableWithHtmlString = ''; +div + | !{variableWithHtmlString} From c27fbdcac6a10c90e26b7eeb33d2958f4b4a2d58 Mon Sep 17 00:00:00 2001 From: Christopher Quadflieg Date: Sat, 4 Jan 2020 18:11:08 +0100 Subject: [PATCH 2/3] Reproduce problem --- test/issues/issue-52/formatted.pug | 5 +++++ test/issues/issue-52/unformatted.pug | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/test/issues/issue-52/formatted.pug b/test/issues/issue-52/formatted.pug index dbe9c6b2..fb553c04 100644 --- a/test/issues/issue-52/formatted.pug +++ b/test/issues/issue-52/formatted.pug @@ -1,3 +1,8 @@ - const variableWithHtmlString = ''; div | !{variableWithHtmlString} + +div + a(href="") + h6 A + | !{veranstaltung.renderedPresseText()} diff --git a/test/issues/issue-52/unformatted.pug b/test/issues/issue-52/unformatted.pug index dbe9c6b2..fb553c04 100644 --- a/test/issues/issue-52/unformatted.pug +++ b/test/issues/issue-52/unformatted.pug @@ -1,3 +1,8 @@ - const variableWithHtmlString = ''; div | !{variableWithHtmlString} + +div + a(href="") + h6 A + | !{veranstaltung.renderedPresseText()} From 7a513a9e549a9a97cc1511c7fa2226d288041340 Mon Sep 17 00:00:00 2001 From: Christopher Quadflieg Date: Sat, 4 Jan 2020 18:15:24 +0100 Subject: [PATCH 3/3] Indent interpolated-code after outdent --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index 2f406f0e..82764511 100644 --- a/src/index.ts +++ b/src/index.ts @@ -508,6 +508,7 @@ export const plugin: Plugin = { break; case 'indent': case 'newline': + case 'outdent': result = printIndent(previousToken, result, indent, indentLevel); result += '| '; break;