Skip to content

Build error in standalone prettier plugin tries to reassign const #1109

@EskiMojo14

Description

@EskiMojo14

Describe the bug
Image
Plugin throws above issue when used.

Expected behaviour
Plugin should format code

Actual behaviour

function hasOrIsNode<N extends LiquidHtmlNode, K extends keyof N>(node: N, key: K) {
const v = node[key];
// this works because there's no ()[] type that is string | Node, it only
// happens for singular nodes such as name: string | LiquidDrop, etc.
return Array.isArray(v) || isNode(v);
}
function isNode(x: unknown): x is LiquidHtmlNode {
return x !== null && typeof x === 'object' && 'type' in x && typeof x.type === 'string';
}

In the minified build, this becomes (reformatted for readability):

function C(e, t) {
  const r = e[t];
  return (
    Array.isArray(r) ||
    (null !== (i = r) &&
      "object" == typeof i &&
      "type" in i &&
      "string" == typeof i.type)
  );
  var i;
}

The issue is because the "chunk" this function is inside already has const i = r(849) earlier, so instead of the var getting hoisted and assigned, it tries to reassign the const and throws an error. (in fact when i checked in the browser sources, the var i; statement was missing completely - possibly due to some DCE)

Debugging information

  • MacOS
  • Tahoe 26.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions