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

Does not support escape sequences #24

Open
lydell opened this issue Sep 6, 2018 · 1 comment
Open

Does not support escape sequences #24

lydell opened this issue Sep 6, 2018 · 1 comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(

Comments

@lydell
Copy link

lydell commented Sep 6, 2018

$ 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
Copy link

theneva commented Jul 6, 2021

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}');
});

image

(y is an alias for yarn.)

@JoshuaKGoldberg JoshuaKGoldberg added type: bug Something isn't working :( status: accepting prs Please, send a pull request to resolve this! labels May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(
Projects
None yet
Development

No branches or pull requests

3 participants