diff --git a/CHANGELOG.md b/CHANGELOG.md index d8506f9ba8ac..6b13685bcf63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog ##### Unreleased +- [Well-Formed Unicode Strings](https://github.com/tc39/proposal-is-usv-string) proposal: + - Methods: + - `String.prototype.isWellFormed` + - `String.prototype.toWellFormed` + - Moved to Stage 3, [November TC39 meeting](https://github.com/babel/proposals/issues/85#issuecomment-1332180862) + - Added `/actual/` entries, disabled unconditional forced replacement - Fixed a theoretically possible future conflict of polyfills definitions in the pure version - [Compat data targets](/packages/core-js-compat#targets-option) improvements: - [React Native from 0.70 shipped with Hermes as the default engine.](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default) However, bundled Hermes versions differ from standalone Hermes releases. So added **`react-native`** target for React Native with bundled Hermes. diff --git a/README.md b/README.md index 423398e16bd5..90269d2c222c 100644 --- a/README.md +++ b/README.md @@ -128,12 +128,12 @@ queueMicrotask(() => console.log('called as microtask')); - [`Array.fromAsync`](#arrayfromasync) - [`Array` grouping](#array-grouping) - [Change `Array` by copy](#change-array-by-copy) + - [Well-formed unicode strings](#well-formed-unicode-strings) - [Stage 2 proposals](#stage-2-proposals) - [`Iterator` helpers](#iterator-helpers) - [New `Set` methods](#new-set-methods) - [`Map.prototype.emplace`](#mapprototypeemplace) - [`Array.isTemplateObject`](#arrayistemplateobject) - - [Well-formed unicode strings](#well-formed-unicode-strings) - [`Symbol.{ asyncDispose, dispose }` for `using` statement](#symbol-asyncdispose-dispose--for-using-statement) - [`Symbol.metadataKey` for decorators metadata proposal](#symbolmetadatakey-for-decorators-metadata-proposal) - [Stage 1 proposals](#stage-1-proposals) @@ -2174,6 +2174,28 @@ const correctionNeeded = [1, 1, 3]; correctionNeeded.with(1, 2); // => [1, 2, 3] correctionNeeded; // => [1, 1, 3] ```` +##### [Well-formed unicode strings](https://github.com/tc39/proposal-is-usv-string)[⬆](#index) +Modules [`esnext.string.is-well-formed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.string.is-well-formed.js) and [`esnext.string.to-well-formed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.string.to-well-formed.js) +```js +class String { + isWellFormed(): boolean; + toWellFormed(): string; +} +``` +[*CommonJS entry points:*](#commonjs-api) +```js +core-js/proposals/well-formed-unicode-strings +core-js(-pure)/actual|full/string(/virtual)/is-well-formed +core-js(-pure)/actual|full/string(/virtual)/to-well-formed +``` +[*Examples*](https://tinyurl.com/2fulc2ak): +```js +'a💩b'.isWellFormed(); // => true +'a\uD83Db'.isWellFormed(); // => false + +'a💩b'.toWellFormed(); // => 'a💩b' +'a\uD83Db'.toWellFormed(); // => 'a�b' +``` #### Stage 2 proposals[⬆](#index) [*CommonJS entry points:*](#commonjs-api) @@ -2361,28 +2383,6 @@ core-js(-pure)/full/array/is-template-object ```js console.log(Array.isTemplateObject((it => it)`qwe${ 123 }asd`)); // => true ``` -##### [Well-formed unicode strings](https://github.com/tc39/proposal-is-usv-string)[⬆](#index) -Modules [`esnext.string.is-well-formed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.string.is-well-formed.js) and [`esnext.string.to-well-formed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.string.to-well-formed.js) -```js -class String { - isWellFormed(): boolean; - toWellFormed(): string; -} -``` -[*CommonJS entry points:*](#commonjs-api) -```js -core-js/proposals/well-formed-unicode-strings -core-js(-pure)/full/string(/virtual)/is-well-formed -core-js(-pure)/full/string(/virtual)/to-well-formed -``` -[*Examples*](https://tinyurl.com/2fulc2ak): -```js -'a💩b'.isWellFormed(); // => true -'a\uD83Db'.isWellFormed(); // => false - -'a💩b'.toWellFormed(); // => 'a💩b' -'a\uD83Db'.toWellFormed(); // => 'a�b' -``` ##### [`Symbol.{ asyncDispose, dispose }` for `using` statement](https://github.com/tc39/proposal-using-statement)[⬆](#index) Modules [`esnext.symbol.dispose`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.dispose.js) and [`esnext.symbol.async-dispose`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.async-dispose.js). ```js diff --git a/packages/core-js/actual/instance/is-well-formed.js b/packages/core-js/actual/instance/is-well-formed.js new file mode 100644 index 000000000000..a8a8c438cea2 --- /dev/null +++ b/packages/core-js/actual/instance/is-well-formed.js @@ -0,0 +1,10 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../string/virtual/is-well-formed'); + +var StringPrototype = String.prototype; + +module.exports = function (it) { + var own = it.isWellFormed; + return typeof it == 'string' || it === StringPrototype + || (isPrototypeOf(StringPrototype, it) && own === StringPrototype.isWellFormed) ? method : own; +}; diff --git a/packages/core-js/actual/instance/to-well-formed.js b/packages/core-js/actual/instance/to-well-formed.js new file mode 100644 index 000000000000..32e8e030dcf7 --- /dev/null +++ b/packages/core-js/actual/instance/to-well-formed.js @@ -0,0 +1,10 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../string/virtual/to-well-formed'); + +var StringPrototype = String.prototype; + +module.exports = function (it) { + var own = it.toWellFormed; + return typeof it == 'string' || it === StringPrototype + || (isPrototypeOf(StringPrototype, it) && own === StringPrototype.toWellFormed) ? method : own; +}; diff --git a/packages/core-js/actual/string/index.js b/packages/core-js/actual/string/index.js index 4b4a2636bb2a..e75b34e00a0f 100644 --- a/packages/core-js/actual/string/index.js +++ b/packages/core-js/actual/string/index.js @@ -1,3 +1,6 @@ var parent = require('../../stable/string'); +require('../../modules/esnext.string.is-well-formed'); +require('../../modules/esnext.string.to-well-formed'); + module.exports = parent; diff --git a/packages/core-js/actual/string/is-well-formed.js b/packages/core-js/actual/string/is-well-formed.js new file mode 100644 index 000000000000..cc23bc9d128d --- /dev/null +++ b/packages/core-js/actual/string/is-well-formed.js @@ -0,0 +1,3 @@ +require('../../modules/esnext.string.is-well-formed'); + +module.exports = require('../../internals/entry-unbind')('String', 'isWellFormed'); diff --git a/packages/core-js/actual/string/to-well-formed.js b/packages/core-js/actual/string/to-well-formed.js new file mode 100644 index 000000000000..133cc4d0b263 --- /dev/null +++ b/packages/core-js/actual/string/to-well-formed.js @@ -0,0 +1,3 @@ +require('../../modules/esnext.string.to-well-formed'); + +module.exports = require('../../internals/entry-unbind')('String', 'toWellFormed'); diff --git a/packages/core-js/actual/string/virtual/index.js b/packages/core-js/actual/string/virtual/index.js index 8442860839d7..539e1515c173 100644 --- a/packages/core-js/actual/string/virtual/index.js +++ b/packages/core-js/actual/string/virtual/index.js @@ -1,3 +1,6 @@ var parent = require('../../../stable/string/virtual'); +require('../../../modules/esnext.string.is-well-formed'); +require('../../../modules/esnext.string.to-well-formed'); + module.exports = parent; diff --git a/packages/core-js/actual/string/virtual/is-well-formed.js b/packages/core-js/actual/string/virtual/is-well-formed.js new file mode 100644 index 000000000000..482609c47222 --- /dev/null +++ b/packages/core-js/actual/string/virtual/is-well-formed.js @@ -0,0 +1,3 @@ +require('../../../modules/esnext.string.is-well-formed'); + +module.exports = require('../../../internals/entry-virtual')('String').isWellFormed; diff --git a/packages/core-js/actual/string/virtual/to-well-formed.js b/packages/core-js/actual/string/virtual/to-well-formed.js new file mode 100644 index 000000000000..e7416e18f74a --- /dev/null +++ b/packages/core-js/actual/string/virtual/to-well-formed.js @@ -0,0 +1,3 @@ +require('../../../modules/esnext.string.to-well-formed'); + +module.exports = require('../../../internals/entry-virtual')('String').toWellFormed; diff --git a/packages/core-js/full/instance/is-well-formed.js b/packages/core-js/full/instance/is-well-formed.js index a8a8c438cea2..def9c64c7715 100644 --- a/packages/core-js/full/instance/is-well-formed.js +++ b/packages/core-js/full/instance/is-well-formed.js @@ -1,10 +1,3 @@ -var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../string/virtual/is-well-formed'); +var parent = require('../../actual/instance/is-well-formed'); -var StringPrototype = String.prototype; - -module.exports = function (it) { - var own = it.isWellFormed; - return typeof it == 'string' || it === StringPrototype - || (isPrototypeOf(StringPrototype, it) && own === StringPrototype.isWellFormed) ? method : own; -}; +module.exports = parent; diff --git a/packages/core-js/full/instance/to-well-formed.js b/packages/core-js/full/instance/to-well-formed.js index 32e8e030dcf7..a8db323e3b39 100644 --- a/packages/core-js/full/instance/to-well-formed.js +++ b/packages/core-js/full/instance/to-well-formed.js @@ -1,10 +1,3 @@ -var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../string/virtual/to-well-formed'); +var parent = require('../../actual/instance/to-well-formed'); -var StringPrototype = String.prototype; - -module.exports = function (it) { - var own = it.toWellFormed; - return typeof it == 'string' || it === StringPrototype - || (isPrototypeOf(StringPrototype, it) && own === StringPrototype.toWellFormed) ? method : own; -}; +module.exports = parent; diff --git a/packages/core-js/full/string/index.js b/packages/core-js/full/string/index.js index 35b61127bf30..f8ddb599dd9f 100644 --- a/packages/core-js/full/string/index.js +++ b/packages/core-js/full/string/index.js @@ -3,10 +3,8 @@ var parent = require('../../actual/string'); require('../../modules/esnext.string.at'); require('../../modules/esnext.string.cooked'); require('../../modules/esnext.string.code-points'); -require('../../modules/esnext.string.is-well-formed'); // TODO: remove from `core-js@4` require('../../modules/esnext.string.match-all'); require('../../modules/esnext.string.replace-all'); -require('../../modules/esnext.string.to-well-formed'); module.exports = parent; diff --git a/packages/core-js/full/string/is-well-formed.js b/packages/core-js/full/string/is-well-formed.js index cc23bc9d128d..e8815f506c9b 100644 --- a/packages/core-js/full/string/is-well-formed.js +++ b/packages/core-js/full/string/is-well-formed.js @@ -1,3 +1,3 @@ -require('../../modules/esnext.string.is-well-formed'); +var parent = require('../../actual/string/is-well-formed'); -module.exports = require('../../internals/entry-unbind')('String', 'isWellFormed'); +module.exports = parent; diff --git a/packages/core-js/full/string/to-well-formed.js b/packages/core-js/full/string/to-well-formed.js index 133cc4d0b263..9c297370a07d 100644 --- a/packages/core-js/full/string/to-well-formed.js +++ b/packages/core-js/full/string/to-well-formed.js @@ -1,3 +1,3 @@ -require('../../modules/esnext.string.to-well-formed'); +var parent = require('../../actual/string/to-well-formed'); -module.exports = require('../../internals/entry-unbind')('String', 'toWellFormed'); +module.exports = parent; diff --git a/packages/core-js/full/string/virtual/index.js b/packages/core-js/full/string/virtual/index.js index d72428636eb6..5838517a3bcc 100644 --- a/packages/core-js/full/string/virtual/index.js +++ b/packages/core-js/full/string/virtual/index.js @@ -2,10 +2,8 @@ var parent = require('../../../actual/string/virtual'); // TODO: remove from `core-js@4` require('../../../modules/esnext.string.at'); require('../../../modules/esnext.string.code-points'); -require('../../../modules/esnext.string.is-well-formed'); // TODO: remove from `core-js@4` require('../../../modules/esnext.string.match-all'); require('../../../modules/esnext.string.replace-all'); -require('../../../modules/esnext.string.to-well-formed'); module.exports = parent; diff --git a/packages/core-js/full/string/virtual/is-well-formed.js b/packages/core-js/full/string/virtual/is-well-formed.js index 482609c47222..b963805cb132 100644 --- a/packages/core-js/full/string/virtual/is-well-formed.js +++ b/packages/core-js/full/string/virtual/is-well-formed.js @@ -1,3 +1,3 @@ -require('../../../modules/esnext.string.is-well-formed'); +var parent = require('../../../actual/string/virtual/is-well-formed'); -module.exports = require('../../../internals/entry-virtual')('String').isWellFormed; +module.exports = parent; diff --git a/packages/core-js/full/string/virtual/to-well-formed.js b/packages/core-js/full/string/virtual/to-well-formed.js index e7416e18f74a..bc135a4fa234 100644 --- a/packages/core-js/full/string/virtual/to-well-formed.js +++ b/packages/core-js/full/string/virtual/to-well-formed.js @@ -1,3 +1,3 @@ -require('../../../modules/esnext.string.to-well-formed'); +var parent = require('../../../actual/string/virtual/to-well-formed'); -module.exports = require('../../../internals/entry-virtual')('String').toWellFormed; +module.exports = parent; diff --git a/packages/core-js/modules/esnext.string.is-well-formed.js b/packages/core-js/modules/esnext.string.is-well-formed.js index 3e159ef7365c..7c77f380d414 100644 --- a/packages/core-js/modules/esnext.string.is-well-formed.js +++ b/packages/core-js/modules/esnext.string.is-well-formed.js @@ -8,7 +8,7 @@ var charCodeAt = uncurryThis(''.charCodeAt); // `String.prototype.isWellFormed` method // https://github.com/tc39/proposal-is-usv-string -$({ target: 'String', proto: true, forced: true }, { +$({ target: 'String', proto: true }, { isWellFormed: function isWellFormed() { var S = toString(requireObjectCoercible(this)); var length = S.length; diff --git a/packages/core-js/modules/esnext.string.to-well-formed.js b/packages/core-js/modules/esnext.string.to-well-formed.js index 8a37c1be2cbc..6d2c616c8cf7 100644 --- a/packages/core-js/modules/esnext.string.to-well-formed.js +++ b/packages/core-js/modules/esnext.string.to-well-formed.js @@ -12,7 +12,7 @@ var REPLACEMENT_CHARACTER = '\uFFFD'; // `String.prototype.toWellFormed` method // https://github.com/tc39/proposal-is-usv-string -$({ target: 'String', proto: true, forced: true }, { +$({ target: 'String', proto: true }, { toWellFormed: function toWellFormed() { var S = toString(requireObjectCoercible(this)); var length = S.length; diff --git a/packages/core-js/stage/2.js b/packages/core-js/stage/2.js index b96cfe7cf116..b91d985f13bc 100644 --- a/packages/core-js/stage/2.js +++ b/packages/core-js/stage/2.js @@ -6,7 +6,6 @@ require('../proposals/iterator-helpers'); require('../proposals/map-upsert-stage-2'); require('../proposals/set-methods'); require('../proposals/using-statement'); -require('../proposals/well-formed-unicode-strings'); // TODO: Obsolete versions, remove from `core-js@4` require('../proposals/array-grouping'); require('../proposals/decorators'); diff --git a/packages/core-js/stage/3.js b/packages/core-js/stage/3.js index 9097f2dbfd7c..d8bceb3a6f98 100644 --- a/packages/core-js/stage/3.js +++ b/packages/core-js/stage/3.js @@ -3,6 +3,7 @@ var parent = require('./4'); require('../proposals/array-from-async-stage-2'); require('../proposals/array-grouping-stage-3-2'); require('../proposals/change-array-by-copy'); +require('../proposals/well-formed-unicode-strings'); // TODO: Obsolete versions, remove from `core-js@4` require('../proposals/array-grouping-stage-3'); diff --git a/tests/entries/unit.mjs b/tests/entries/unit.mjs index 88465dc1d534..4934d5dc91ea 100644 --- a/tests/entries/unit.mjs +++ b/tests/entries/unit.mjs @@ -614,6 +614,10 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(load(NS, 'array/virtual/to-reversed').call([1, 2, 3])[0] === 3); ok(load(NS, 'array/virtual/to-sorted').call([3, 2, 1])[0] === 1); ok(load(NS, 'array/virtual/to-spliced').call([3, 2, 1], 1, 1, 4, 5).length === 4); + ok(load(NS, 'string/is-well-formed')('a')); + ok(load(NS, 'string/virtual/is-well-formed').call('a')); + ok(load(NS, 'string/to-well-formed')('a') === 'a'); + ok(load(NS, 'string/virtual/to-well-formed').call('a') === 'a'); const instanceGroup = load(NS, 'instance/group'); ok(typeof instanceGroup == 'function'); @@ -662,6 +666,18 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(instanceWith({}) === undefined); ok(typeof instanceWith([]) == 'function'); ok(instanceWith([]).call([1, 2, 3], 1, 4)[1] === 4); + + const instanceIsWellFormed = load(NS, 'instance/is-well-formed'); + ok(typeof instanceIsWellFormed == 'function'); + ok(instanceIsWellFormed({}) === undefined); + ok(typeof instanceIsWellFormed('') == 'function'); + ok(instanceIsWellFormed('').call('a')); + + const instanceToWellFormed = load(NS, 'instance/to-well-formed'); + ok(typeof instanceToWellFormed == 'function'); + ok(instanceToWellFormed({}) === undefined); + ok(typeof instanceToWellFormed('') == 'function'); + ok(instanceToWellFormed('').call('a') === 'a'); } for (const NS of ['full', 'features']) { @@ -787,10 +803,6 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(load(NS, 'string/cooked')`a${ 1 }b` === 'a1b'); ok('next' in load(NS, 'string/code-points')('a')); ok('next' in load(NS, 'string/virtual/code-points').call('a')); - ok(load(NS, 'string/is-well-formed')('a')); - ok(load(NS, 'string/virtual/is-well-formed').call('a')); - ok(load(NS, 'string/to-well-formed')('a') === 'a'); - ok(load(NS, 'string/virtual/to-well-formed').call('a') === 'a'); ok(load(NS, 'symbol/async-dispose')); ok(load(NS, 'symbol/dispose')); ok(load(NS, 'symbol/matcher')); @@ -827,18 +839,6 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(typeof instanceFilterReject([]) == 'function'); ok(instanceFilterReject([]).call([1, 2, 3], it => it % 2).length === 1); - const instanceIsWellFormed = load(NS, 'instance/is-well-formed'); - ok(typeof instanceIsWellFormed == 'function'); - ok(instanceIsWellFormed({}) === undefined); - ok(typeof instanceIsWellFormed('') == 'function'); - ok(instanceIsWellFormed('').call('a')); - - const instanceToWellFormed = load(NS, 'instance/to-well-formed'); - ok(typeof instanceToWellFormed == 'function'); - ok(instanceToWellFormed({}) === undefined); - ok(typeof instanceToWellFormed('') == 'function'); - ok(instanceToWellFormed('').call('a') === 'a'); - const instanceUniqueBy = load(NS, 'instance/unique-by'); ok(typeof instanceUniqueBy == 'function'); ok(instanceUniqueBy({}) === undefined); diff --git a/tests/unit-pure/esnext.string.is-well-formed.js b/tests/unit-pure/esnext.string.is-well-formed.js index c3f5c785bd2b..d15b01e1a88f 100644 --- a/tests/unit-pure/esnext.string.is-well-formed.js +++ b/tests/unit-pure/esnext.string.is-well-formed.js @@ -1,6 +1,6 @@ import { STRICT } from '../helpers/constants'; import Symbol from 'core-js-pure/es/symbol'; -import isWellFormed from 'core-js-pure/full/string/virtual/is-well-formed'; +import isWellFormed from 'core-js-pure/actual/string/virtual/is-well-formed'; QUnit.test('String#isWellFormed', assert => { assert.isFunction(isWellFormed); diff --git a/tests/unit-pure/esnext.string.to-well-formed.js b/tests/unit-pure/esnext.string.to-well-formed.js index b82afaf93ac9..b6927406e670 100644 --- a/tests/unit-pure/esnext.string.to-well-formed.js +++ b/tests/unit-pure/esnext.string.to-well-formed.js @@ -1,6 +1,6 @@ import { STRICT } from '../helpers/constants'; import Symbol from 'core-js-pure/es/symbol'; -import toWellFormed from 'core-js-pure/full/string/virtual/to-well-formed'; +import toWellFormed from 'core-js-pure/actual/string/virtual/to-well-formed'; QUnit.test('String#toWellFormed', assert => { assert.isFunction(toWellFormed);