Comments (3)
🤔 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.
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.
My workaround be like:
dedent`
export function Demo({ active }) {
return (
<div
className={\`demo $${''}{active ? 'active' : ''}\`}
></div>
)
}
`
It is ugly
from dedent.
Related Issues (20)
- `babel-plugin-macros` should be an optional peer dependency HOT 1
- Add a changelog HOT 5
- Convert dedent.ts and tests to TypeScript
- Convert macro.js to TypeScript
- Onboard to create-typescript-app@1 HOT 1
- Node ESM compatibility issue HOT 2
- 🚀 Feature: Add an option to disable special character escaping HOT 2
- Avoid escaping $ without a { after it? HOT 1
- dedent.d.mts missing in package.json > files
- Consider being `String.dedent` HOT 3
- Bug(?) JSON.serialize(..., null, 2) throws off indentation HOT 2
- error with npm install on firebase project HOT 1
- 🛠 Tooling: Set up tokens for automated publishing & contributor recognition
- 🐛 Bug: Doesn't do dedent if first character is a space character HOT 2
- 📝 Docs: add an 'install' section to the README? HOT 5
- 🛠 Tooling: Build failures on main from references to yarn HOT 1
- 🐛 Bug: babel-plugin-macros isn't an optional peer anymore HOT 1
- 🐛 Bug: \\n -> \n should only happen with template strings HOT 1
- 🐛 Bug: Upgrading Node to verison 18 broke builds HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dedent.