Skip to content

Extract IStringFmt.js from IString.js (Phase 2) - #511

Open
gouniLee wants to merge 2 commits into
refactor-istring-plural-utilsfrom
extract-istringfmt
Open

Extract IStringFmt.js from IString.js (Phase 2)#511
gouniLee wants to merge 2 commits into
refactor-istring-plural-utilsfrom
extract-istringfmt

Conversation

@gouniLee

@gouniLee gouniLee commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • At least one test case is included for this feature or bug fix.
  • ReleaseNotes has been updated or is not needed.
  • This PR has passed all test cases on Node.js and Chrome Browser.
  • This is an API breaking change.
  • Requires a major version change.

Summary

Phase 2 of the IString.js split described in docs/IString-Refactoring.md. Extracts the formatting-method cluster (format, _testChoice, _isIntlPluralAvailable, formatChoice, setLocale, getLocale) out of IString.js into a new IStringFmt.js, mixed back onto IString.prototype via Object.assign. No change to the public API.

  • Move the six formatting methods into js/lib/IStringFmt.js as a plain object (mirrors the PluralUtils.js pattern from Phase 1), required and mixed into IString.prototype from IString.js
  • formatChoice's internal new IString(...) calls become new this.constructor(...) so IStringFmt.js never requires IString.js (no circular dependency)
  • Restore IString.prototype.constructor = IString, which is lost when .prototype is replaced with an object literal — required for the this.constructor calls above to resolve correctly
  • _testChoice/setLocale call PluralUtils directly instead of going through the IString._fncs/IString.loadPlurals static aliases
  • Add js/test/root/teststringfmt.js and register it in testSuiteFiles.js

IString.js: 1158 → 712 lines. IStringFmt.js: 482 lines (new).

Notes

This is a pure move — no behavior changes. Several pre-existing logic bugs in the moved formatChoice/format code were found during review (not caused by this extraction, just carried over verbatim) and are being fixed separately in the fix-istringfmt-logic-bugs branch, to keep the structural move and the behavioral fixes easy to review independently.

This PR's base branch is refactor-istring-plural-utils, which is #509. (Phase 1 — extract PluralUtils.js) needs to be merged first; this PR should be rebased onto development (or its base updated) once that lands.

Test plan

  • ant test.root — 7092 assertions, all passing
  • ant test.address / test.date / test.units / test.name — consumer suites (formatChoice/format/setLocale callers: DateFmt, DurationFmt, UnitFmt, ResBundle, NameFmt, AddressFmt) all passing, no regressions
  • docs/IString-Refactoring.md updated to mark Phase 2 done

Move formatting methods (format, _testChoice, _isIntlPluralAvailable,
formatChoice, setLocale, getLocale) out of IString.js into a standalone
IStringFmt.js module, mixed back onto IString.prototype via
Object.assign. This completes Phase 2 of the split described in
docs/IString-Refactoring.md (IString.js: 1158 -> 712 lines).

- formatChoice's `new IString(...)` calls become `new this.constructor(...)`
  so IStringFmt.js never requires IString.js directly (no circular dep)
- IString.prototype.constructor is restored explicitly, since replacing
  .prototype with an object literal drops it, which broke the
  this.constructor calls above
- _testChoice/setLocale now call PluralUtils directly instead of
  reaching through the IString._fncs/loadPlurals aliases
- Add js/test/root/testistringfmt.js covering format/formatChoice/
  setLocale/getLocale end-to-end

No functional changes intended; several pre-existing bugs in the moved
code (found during review) are left untouched for a follow-up commit.
The formatting-mixin test file (added in the IStringFmt extraction
commit) was never added to testSuiteFiles.js, so `ant test.root`
silently skipped it entirely. Also rename it from testistringfmt.js
to teststringfmt.js and its internal test names from testIStringFmt*
to testStringFmt*, matching the existing teststrings.js convention of
dropping the "I" prefix from IString-family class names.

Also fix testStringFmtFormatCanBeAppliedTwice, which only surfaces
once the file actually runs: format() returns a plain JS string, not
an IString, so chaining .format() on its result needs to be re-wrapped
in new IString(...) first.
@gouniLee
gouniLee requested a review from ehoogerbeets August 7, 2026 07:29
@gouniLee gouniLee self-assigned this Aug 7, 2026
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.

1 participant