Does not support escape sequences
lydell opened this issue · 1 comments
lydell commented
$ node
> dedent = require(".").default
[Function: dedent]
> `a\xa0\tb`
'a \tb'
> dedent`a\xa0b`
'a\\xa0\\tb'
> ⏎
(For people stumbling upon this issue: https://github.com/MartinKolarik/dedent-js might work better for you.)
theneva commented
Hi! I just stumbled on a variation of this surprising-to-me behaviour.
As a worksaround, it's possible to do what I do in the second ('works'
): Replace \${hi}
with ${'${hi}'}
. That way, dedent
only sees a string literal and doesn't have to care about escaping.
I figured I'd share in case anyone else comes here looking for answers 😄
// test.js
const dedent = require('dedent');
test('fails', () => {
const text = dedent`\${hi}`;
expect(text).toBe('${hi}');
});
test('works', () => {
const text = dedent`${'${hi}'}`;
expect(text).toBe('${hi}');
});
(y
is an alias for yarn
.)