From 40168538c471cb3f922b317a7a95a52413cb2d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vasseur?= Date: Thu, 17 Nov 2022 14:51:06 +0100 Subject: [PATCH] Fix part beeing remove with unindented placeholders --- index.test.ts | 7 +++++++ index.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/index.test.ts b/index.test.ts index 7facf3e..de5fbc3 100644 --- a/index.test.ts +++ b/index.test.ts @@ -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']; diff --git a/index.ts b/index.ts index 290a14d..0a24656 100644 --- a/index.ts +++ b/index.ts @@ -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