Skip to content

Commit

Permalink
Merge pull request #28 from prettier/issue-27
Browse files Browse the repository at this point in the history
Fix interpolated issue
  • Loading branch information
Shinigami92 authored Oct 23, 2019
2 parents 39c26f2 + 5cd1721 commit 7f55c6e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/issues/issue-27/formatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tag(key="value") #{identifier}
tag
| #{identifier}
14 changes: 14 additions & 0 deletions test/issues/issue-27/issue-27.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
3 changes: 3 additions & 0 deletions test/issues/issue-27/unformatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tag(key='value') #{identifier}
tag
| #{identifier}

0 comments on commit 7f55c6e

Please sign in to comment.