Skip to content

Commit

Permalink
block-string: print multi line for trailing backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
thenamankumar committed May 18, 2020
1 parent e01cfa8 commit 6a07b6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Binary file not shown.
7 changes: 7 additions & 0 deletions src/language/__tests__/blockString-test.js
Expand Up @@ -155,6 +155,13 @@ describe('printBlockString', () => {
);
});

it('correctly prints single-line with trailing backslash', () => {
const str = 'backslash \\';

expect(printBlockString(str)).to.equal('"""\nbackslash \\\n"""');
expect(printBlockString(str, '', true)).to.equal('"""\nbackslash \\\n"""');
});

it('correctly prints string with a first line indentation', () => {
const str = joinLines(
' first ',
Expand Down
6 changes: 5 additions & 1 deletion src/language/blockString.js
Expand Up @@ -85,8 +85,12 @@ export function printBlockString(
const isSingleLine = value.indexOf('\n') === -1;
const hasLeadingSpace = value[0] === ' ' || value[0] === '\t';
const hasTrailingQuote = value[value.length - 1] === '"';
const hasTrailingSlash = value[value.length - 1] === '\\';
const printAsMultipleLines =
!isSingleLine || hasTrailingQuote || preferMultipleLines;
!isSingleLine ||
hasTrailingQuote ||
hasTrailingSlash ||
preferMultipleLines;

let result = '';
// Format a multi-line block quote to account for leading space.
Expand Down

0 comments on commit 6a07b6a

Please sign in to comment.