denoland / denoland/std

`text/unstable-dedent` still gives poor results when interpolating multi-line text into tagged template in certain edge cases

Open
#6,830 1 comment 0 reactions 0 assignees View on GitHub
bug needs triage
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

`text/unstable-dedent` still gives poor results when interpolating multi-line text into tagged template in certain edge cases.

See also https://github.com/denoland/std/issues/6665 — the example from that specific issue was fixed, but behavior is still buggy in some edge cases. As with that issue, `npm:string-dedent` gives the expected result.

**Steps to Reproduce**

```ts
import { assertEquals } from 'jsr:@std/assert';
import { dedent as stdDedent } from 'jsr:@std/text@1.0.16/unstable-dedent';
import npmDedent from 'npm:string-dedent@3.0.2';

for (const [name, dedent] of Object.entries({
'jsr:@std': stdDedent,
'npm:string-dedent': npmDedent,
})) {
Deno.test(name, async (t) => {
const inner = dedent`
[
...
...
]
`;

// ok
await t.step('inner', () => assertEquals(inner, ' [\n ...\n...\n ]'));

const outerV1 = dedent`
a
b
${inner}
`;

const outerV2 = dedent`
a
b
${inner}
`;

// throws for @std/dedent, ok for npm:string-dedent
await t.step('outerV1', () => assertEquals(outerV1, `a\n b\n${inner}`));

// ok
await t.step('outerV2', () => assertEquals(outerV2, `a\n b\n${inner}`));
});
}
```

Not sure why `outerV1` and `outerV2` give different results, as they should be exactly equivalent, the only difference being that the indent to be stripped is two spaces wider in `V2`.

**Environment**

text@1.0.16

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.