Skip to content

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

@lionel-rowe

Description

@lionel-rowe

Describe the bug

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

See also #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

import { assertEquals } from 'jsr:@std/assert';
import { dedent as stdDedent } from 'jsr:@std/[email protected]/unstable-dedent';
import npmDedent from 'npm:[email protected]';

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

[email protected]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions