Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug (?): Newlines after template substitution. #11

Open
ryan-roemer opened this issue Oct 6, 2022 · 0 comments
Open

Bug (?): Newlines after template substitution. #11

ryan-roemer opened this issue Oct 6, 2022 · 0 comments

Comments

@ryan-roemer
Copy link

Really neat to see this slim library! I think I've encountered a bug in the handling of whitespace/newlines after template replacements...

Situation

I have multiline template strings that I'm switching away from chalk to this library of the form:

colorize`
{gray One}

{cyan Two}

Expected behavior: Output preserves newlines, so One\n\nTwo with color chars.

Actual behavior: Output strips newlines and whitespace after template replacement, so OneTwo with color chars.

Failing Unit Tests

I think these unit tests demonstrate the issue:

diff --git a/tests/index.js b/tests/index.js
index 8c731ec..5f40410 100644
--- a/tests/index.js
+++ b/tests/index.js
@@ -80,6 +80,15 @@ test('correctly parse newline escapes', () => {
   assert.equal(colorize`Hello\nthere!`, 'Hello\nthere!')
 })
 
+test('correctly parse newline literals after template', () => {
+  assert.equal(colorize`Hello {red there}
+after`, 'Hello ' + pc.red('there') + '\nafter')
+})
+
+test('correctly parse newline escapes after template', () => {
+  assert.equal(colorize`Hello {red there}\nafter`, 'Hello ' + pc.red('there') + '\nafter')
+})
+
 test('correctly parse escape in parameters', () => {
   const string = '\\'
   assert.equal(colorize`{red ${string}}`, pc.red('\\'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant