Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single quotes in framework interpolation #354

Merged
merged 6 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions tests/issues/issue-339/double-quotes.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
p {{ transform("text") }}
p Hello {{ "World" }}.
45 changes: 45 additions & 0 deletions tests/issues/issue-339/issue-339.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 2 additions & 0 deletions tests/issues/issue-339/single-quotes.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
p {{ transform('text') }}
p Hello {{ 'World' }}.