markup_fmt icon indicating copy to clipboard operation
markup_fmt copied to clipboard

Unexpectedly dedents Astro HTML subexpression inside deep JavaScript expression

Open andersk opened this issue 2 months ago • 1 comments

When formatting an Astro file with an HTML subexpression inside a deep JavaScript expression, markup_fmt incorrectly ignores the indentation that represents the JavaScript depth, and instead dedents all the HTML subexpressions to the same level, making complicated expressions harder to read.

Expected:

{
  1
    ? 2
      ? 3
        ? 4
          ? (
            <p>
              all
            </p>
          )
          : (
            <p>
              not four
            </p>
          )
        : (
          <p>
            not three
          </p>
        )
      : (
        <p>
          not two
        </p>
      )
    : (
      <p>
        not one
      </p>
    )
}

Actual:

{
  1
    ? 2
      ? 3
        ? 4
          ? (
    <p>
      all
    </p>
  )
  : (
    <p>
      not four
    </p>
  )
  : (
    <p>
      not three
    </p>
  )
  : (
    <p>
      not two
    </p>
  )
  : (
    <p>
      not one
    </p>
  )
}

andersk avatar Sep 13 '25 00:09 andersk

Or maybe something even stranger is going on.

Expected:

{
  1
    ? [
      "a",
      "b",
      (
        <p>
          c
        </p>
      ),
      "d",
      "e",
      (
        <p>
          f
        </p>
      ),
      "g",
      "h",
      (
        <p>
          i
        </p>
      ),
      "j",
      "k",
    ]
    : []
}

Actual:

{
  1
    ? [
      "a",
      "b",
    (
    <p>
      c
    </p>
  ),
  "d",
  "e",
(
    <p>
      f
    </p>
  ),
  "g",
  "h",
(
    <p>
      i
    </p>
  ),
    "j",
    "k",
  ]
  : []
}

andersk avatar Sep 13 '25 00:09 andersk