Skip to content

group not needed if we know there's a hardline or a breakParent inside#15795

Merged
fisker merged 2 commits intoprettier:mainfrom
Janther:main
Dec 17, 2023
Merged

group not needed if we know there's a hardline or a breakParent inside#15795
fisker merged 2 commits intoprettier:mainfrom
Janther:main

Conversation

@Janther
Copy link
Copy Markdown
Contributor

@Janther Janther commented Dec 14, 2023

Description

group containing hardline or breakParent only make sense if the rest of the code relies on the Group type to make a different decision.

This one doesn't affect any test.

I also found one here:

const linebreak =
options.htmlWhitespaceSensitivity === "ignore"
? hardline
: leadingWhitespace && trailingWhitespace
? line
: null;
if (linebreak) {
return group(["`", indent([linebreak, group(contentDoc)]), linebreak, "`"]);
}

which could be replaced by

  const linebreak =
    options.htmlWhitespaceSensitivity === "ignore"
      ? hardline
      : leadingWhitespace && trailingWhitespace
        ? line
        : null;

  if (linebreak) {
    return linebreak !== hardline
      ? group(["`", indent([linebreak, group(contentDoc)]), linebreak, "`"])
      : ["`", indent([linebreak, group(contentDoc)]), linebreak, "`"];
  }

and another here:

return group([
join(line, path.map(print, "decorators")),
hasNewlineBetweenOrAfterDecorators(node, options) ? hardline : line,
]);

  return hasNewlineBetweenOrAfterDecorators(node, options)
    ? [join(line, path.map(print, "decorators")), hardline]
    : group([join(line, path.map(print, "decorators")), line]);
  ]);

But the benefit is so small that you can make that decision.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants