Skip to content

Commit

Permalink
Merge pull request #5 from jvasseur/fix-unintended-placeholder
Browse files Browse the repository at this point in the history
Fix part beeing remove with unindented placeholders
  • Loading branch information
jvasseur authored Nov 17, 2022
2 parents f618ac7 + 4016853 commit 676e598
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ test('It correctly detect indentation when last line is empty', () => {
`).toBe('Test\n\n');
});

test('It works when placeholder is not indented', () => {
expect(indent`
Foo
${'Bar'}
`).toBe('Foo\nBar\n');
});

test('Nested indent test', () => {
const list = ['First', 'Second'];

Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const indentTag = (strings: TemplateStringsArray, ... expressions: any[]) => {
const indentation = match[1];

// Fix previous and next parts
parts[i] = parts[i].slice(0, -indentation.length);
parts[i] = parts[i].slice(0, parts[i].length - indentation.length);
parts[i + 1] = parts[i + 1].slice(1);

// Fix value end of line if needed
Expand Down

0 comments on commit 676e598

Please sign in to comment.