Skip to content

refactor: remove repeat() polyfill#5837

Merged
voxpelli merged 1 commit intomainfrom
voxpelli/remove-repeat-polyfill
Apr 2, 2026
Merged

refactor: remove repeat() polyfill#5837
voxpelli merged 1 commit intomainfrom
voxpelli/remove-repeat-polyfill

Conversation

@voxpelli
Copy link
Copy Markdown
Member

String.prototype.repeat has existed since ES2015 / Node 4.

The custom repeat() used new Array(n).join(s) which produces n-1 copies — the replacement preserves this semantic with .repeat(n-1).

Also updates a misleading IE7/IE8 comment on boxed String handling.

PR Checklist

`String.prototype.repeat` has existed since ES2015 / Node 4. The custom

repeat() used new Array(n).join(s) which produces n-1 copies — the
replacement preserves this semantic with .repeat(n-1).

Also updates a misleading IE7/IE8 comment on boxed String handling.

Ref: #5357 (v12 Release Plan)
@voxpelli voxpelli added this to the v12.0.0 milestone Mar 31, 2026
@voxpelli voxpelli requested review from a team and Copilot March 31, 2026 14:40
@voxpelli voxpelli self-assigned this Mar 31, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes lib/utils.js by removing a local repeat() helper in favor of String.prototype.repeat(), aligning with Mocha’s modern runtime targets, and clarifies a comment related to boxed String handling during stringification.

Changes:

  • Remove the internal .repeat() polyfill helper (new Array(n).join(s)) from jsonStringify().
  • Replace indentation building with " ".repeat(...) while preserving the previous off-by-one semantics.
  • Update the boxed String comment in exports.stringify() to describe the behavior more accurately.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.74%. Comparing base (661f349) to head (22c9ce3).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5837      +/-   ##
==========================================
+ Coverage   89.70%   89.74%   +0.03%     
==========================================
  Files          64       64              
  Lines        4691     4689       -2     
  Branches      976      976              
==========================================
  Hits         4208     4208              
+ Misses        483      481       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@voxpelli voxpelli added status: needs review a maintainer should (re-)review this pull request type: cleanup a refactor labels Mar 31, 2026
Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Nice find 👌

@voxpelli voxpelli merged commit f988a80 into main Apr 2, 2026
161 of 162 checks passed
@voxpelli voxpelli deleted the voxpelli/remove-repeat-polyfill branch April 2, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs review a maintainer should (re-)review this pull request type: cleanup a refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📌 Mocha 12 Release Plan

3 participants