diff --git a/src/printer.ts b/src/printer.ts index edfa189e..8dfead66 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -450,7 +450,13 @@ export class PugPrinter { } private frameworkFormat(code: string): string { - const options: Options = { ...this.codeInterpolationOptions }; + const options: Options = { + ...this.codeInterpolationOptions, + // we need to keep the original singleQuote option + // see https://github.com/prettier/plugin-pug/issues/339 + singleQuote: this.options.singleQuote, + }; + switch (this.framework) { case 'angular': options.parser = '__ng_interpolation'; diff --git a/tests/issues/issue-339/double-quotes.pug b/tests/issues/issue-339/double-quotes.pug new file mode 100644 index 00000000..2ff93f52 --- /dev/null +++ b/tests/issues/issue-339/double-quotes.pug @@ -0,0 +1,2 @@ +p {{ transform("text") }} +p Hello {{ "World" }}. diff --git a/tests/issues/issue-339/issue-339.test.ts b/tests/issues/issue-339/issue-339.test.ts new file mode 100644 index 00000000..867a4180 --- /dev/null +++ b/tests/issues/issue-339/issue-339.test.ts @@ -0,0 +1,45 @@ +import { readFileSync } from 'fs'; +import { resolve } from 'path'; +import { format } from 'prettier'; +import { describe, expect, test } from 'vitest'; +import { plugin } from './../../../src/index'; + +describe('Issues', () => { + test('should handle singleQuote:true + pugSingleQuote:false in framework interpolation', () => { + const expected: string = readFileSync( + resolve(__dirname, 'single-quotes.pug'), + 'utf8', + ); + const code: string = readFileSync( + resolve(__dirname, 'double-quotes.pug'), + 'utf8', + ); + const actual: string = format(code, { + parser: 'pug', + plugins: [plugin], + singleQuote: true, + pugSingleQuote: false, + }); + + expect(actual).toBe(expected); + }); + + test('should handle singleQuote:false + pugSingleQuote:true in framework interpolation', () => { + const expected: string = readFileSync( + resolve(__dirname, 'double-quotes.pug'), + 'utf8', + ); + const code: string = readFileSync( + resolve(__dirname, 'single-quotes.pug'), + 'utf8', + ); + const actual: string = format(code, { + parser: 'pug', + plugins: [plugin], + singleQuote: false, + pugSingleQuote: true, + }); + + expect(actual).toBe(expected); + }); +}); diff --git a/tests/issues/issue-339/single-quotes.pug b/tests/issues/issue-339/single-quotes.pug new file mode 100644 index 00000000..4b6545fb --- /dev/null +++ b/tests/issues/issue-339/single-quotes.pug @@ -0,0 +1,2 @@ +p {{ transform('text') }} +p Hello {{ 'World' }}.