Skip to content

Commit

Permalink
Handle nested Angular translations (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Jan 19, 2022
1 parent 4bc3084 commit f5e5ef1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,14 @@ export class PugPrinter {
...this.codeInterpolationOptions,
singleQuote: !this.options.pugSingleQuote,
};
val = format(val, { parser, ...options });
try {
val = format(val, { parser, ...options });
} catch (error) {
logger.warn(
'The following expression could not be formatted correctly. Please try to fix it yourself and if there is a problem, please open a bug issue:',
val,
);
}
val = unwrapLineFeeds(val);
}
val = handleBracketSpacing(this.options.pugBracketSpacing, val, [
Expand Down
1 change: 1 addition & 0 deletions tests/issues/issue-329/formatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some-component(title="{{ '{type}-text' | translate: { type: someType | translate } }}")
27 changes: 27 additions & 0 deletions tests/issues/issue-329/issue-329.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 nested angular translations', () => {
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',
plugins: [plugin],

printWidth: 120,
pugFramework: 'angular',
});

expect(actual).toBe(expected);
});
});
3 changes: 3 additions & 0 deletions tests/issues/issue-329/unformatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
some-component(
title="{{ '{type}-text' | translate: { type: someType | translate } }}"
)

0 comments on commit f5e5ef1

Please sign in to comment.