Coder Social home page Coder Social logo

Comments (3)

JoshuaKGoldberg avatar JoshuaKGoldberg commented on July 21, 2024

🤔 maybe this is me not understanding template literal strings well, but I don't follow why that should be the case. The dedent function isn't doing anything special with escaping special characters such as $ and {. Can you help me explain why the behavior should be changed?

from dedent.

G-Rath avatar G-Rath commented on July 21, 2024

Because otherwise you can't dedent strings with ${ i.e. https://github.com/jest-community/eslint-plugin-jest/blob/02ec945f0794949ce38a11addb0ef3ceafa1aed2/src/rules/__tests__/no-identical-title.test.ts#L108-L113

    dedent`
      describe("foo", () => {
        it(\`ignores $\{someVar} with the same title\`, () => {});
        it(\`ignores $\{someVar} with the same title\`, () => {});
      });
    `.replace(/\\\{/u, '{'),

The replace is the workaround for this - note that I don't have to do it for backticks because that was already addressed in #2.

Technically the best form would be detecting that it's ${, but I think it's reasonable to say that special template string characters should be handled like this because you can otherwise just add a second \ i.e. say I was testing a JS parser and that it didn't pick up escaped interpolation:

    dedent`
      describe("foo", () => {
        it(\`ignores $\\{someVar} with the same title\`, () => {});
        it(\`ignores $\\{someVar} with the same title\`, () => {});
      });
    `

from dedent.

meowtec avatar meowtec commented on July 21, 2024

My workaround be like:

dedent`
  export function Demo({ active }) {
    return (
      <div
        className={\`demo $${''}{active ? 'active' : ''}\`}
      ></div>
    )
  }
`

It is ugly

from dedent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.