Skip to content

Misc types fixes #7618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/core/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,19 @@ const string = {
*
* @param {...number} args - The code points to convert to a string.
* @returns {string} The converted string.
* @ignore
*/
fromCodePoint(/* ...args */) {
const chars = [];
let current;
let codePoint;
let units;
for (let i = 0; i < arguments.length; ++i) {
current = Number(arguments[i]);
codePoint = current - 0x10000;
units = current > 0xFFFF ? [(codePoint >> 10) + 0xD800, (codePoint % 0x400) + 0xDC00] : [current];
chars.push(String.fromCharCode.apply(null, units));
}
return chars.join('');
fromCodePoint(...args) {
return args.map((codePoint) => {
if (codePoint > 0xFFFF) {
codePoint -= 0x10000;
return String.fromCharCode(
(codePoint >> 10) + 0xD800,
(codePoint % 0x400) + 0xDC00
);
}
return String.fromCharCode(codePoint);
}).join('');
}
};

Expand Down
2 changes: 0 additions & 2 deletions src/framework/components/scroll-view/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,6 @@ class ScrollViewComponent extends Component {

/**
* @param {string} onOrOff - 'on' or 'off'.
* @param {ScrollViewComponentSystem} system - The ComponentSystem that
* created this Component.
* @private
*/
_toggleLifecycleListeners(onOrOff) {
Expand Down
32 changes: 32 additions & 0 deletions test/core/string.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,36 @@ describe('string', function () {

});

describe('#fromCodePoint', function () {
it('converts basic ASCII code points to characters', function () {
expect(string.fromCodePoint(65)).to.equal('A');
expect(string.fromCodePoint(66, 67)).to.equal('BC');
expect(string.fromCodePoint(97, 98, 99)).to.equal('abc');
});

it('handles code points beyond the BMP (Basic Multilingual Plane)', function () {
// Emoji: 😀 (U+1F600 GRINNING FACE)
expect(string.fromCodePoint(0x1F600)).to.equal('😀');

// Musical note: 𝄞 (U+1D11E MUSICAL SYMBOL G CLEF)
expect(string.fromCodePoint(0x1D11E)).to.equal('𝄞');
});

it('handles multiple code points including surrogate pairs', function () {
// Mix of BMP and astral code points
expect(string.fromCodePoint(65, 0x1F600, 66)).to.equal('A😀B');

// Multiple astral code points: 💩 (U+1F4A9) and 🚀 (U+1F680)
expect(string.fromCodePoint(0x1F4A9, 0x1F680)).to.equal('💩🚀');
});

it('matches native String.fromCodePoint behavior', function () {
// Only run if native method is available
if (String.fromCodePoint) {
const testPoints = [65, 0x1F600, 0x1D11E, 0x10437];
expect(string.fromCodePoint(...testPoints)).to.equal(String.fromCodePoint(...testPoints));
}
});
});

});