Skip to content

Caching splitted and trimmed lines for indentable block comments#18981

Merged
fisker merged 11 commits intoprettier:mainfrom
Janther:trimmed-lines-cache
Apr 12, 2026
Merged

Caching splitted and trimmed lines for indentable block comments#18981
fisker merged 11 commits intoprettier:mainfrom
Janther:trimmed-lines-cache

Conversation

@Janther
Copy link
Copy Markdown
Contributor

@Janther Janther commented Mar 27, 2026

Description

isIndentableBlockComment and printIndentableBlockComment both split and trim the value of a comment I suspect this is why you decided to cache isIndentableBlockComment.
I propose to cache the splitter trimmed lines. so the printing won't have to do extra work.

This might even remove the need for the original cache for isIndentableBlockComment.

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 27, 2026

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@18981.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@18981.tgz
yarn add https://pkg.pr.new/prettier@18981.tgz

commit: 13f995e

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 27, 2026

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3622ded
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/69c6edb906b36f00087541e5
😎 Deploy Preview https://deploy-preview-18981--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 27, 2026

Deploy Preview for prettier ready!

Name Link
🔨 Latest commit 13f995e
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/69db7d7938a7df0008d292af
😎 Deploy Preview https://deploy-preview-18981--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread src/language-js/parse/postprocess/merge-nestled-jsdoc-comments.js Outdated
Comment thread src/language-js/utilities/is-indentable-block-comment.js Outdated

const trimmedLines = [];

for (let line of `*${comment.value}*`.split("\n")) {
Copy link
Copy Markdown
Contributor Author

@Janther Janther Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fisker I added a last commit to this where instead of doing 2 iterations, one to trimStart and one to check startsWith("*"), there is only one iteration where we early exit as soon as we fail the check. (similar to how Array.prototype.every() works)
Also the cache now is an array of the indentable lines, and an empty array if the block is not indentable. This way we can remove the original cache since now it's only a check for the length of the indentable lines.

@Janther Janther force-pushed the trimmed-lines-cache branch from 06bace6 to 7b051fd Compare April 2, 2026 02:20
@Janther Janther requested a review from fisker April 2, 2026 02:28
@fisker fisker merged commit aa89018 into prettier:main Apr 12, 2026
36 checks passed
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.

2 participants