Skip to content

Commit

Permalink
move Well-Formed Unicode Strings proposal to stage 3
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 9, 2022
1 parent 26e0e6d commit d6ad38c
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 74 deletions.
6 changes: 6 additions & 0 deletions 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.
Expand Down
46 changes: 23 additions & 23 deletions README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions 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;
};
10 changes: 10 additions & 0 deletions 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;
};
3 changes: 3 additions & 0 deletions 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;
3 changes: 3 additions & 0 deletions 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');
3 changes: 3 additions & 0 deletions 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');
3 changes: 3 additions & 0 deletions 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;
3 changes: 3 additions & 0 deletions 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;
3 changes: 3 additions & 0 deletions 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;
11 changes: 2 additions & 9 deletions 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;
11 changes: 2 additions & 9 deletions 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;
2 changes: 0 additions & 2 deletions packages/core-js/full/string/index.js
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions 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;
4 changes: 2 additions & 2 deletions 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;
2 changes: 0 additions & 2 deletions packages/core-js/full/string/virtual/index.js
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions 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;
4 changes: 2 additions & 2 deletions 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;
2 changes: 1 addition & 1 deletion packages/core-js/modules/esnext.string.is-well-formed.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/esnext.string.to-well-formed.js
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/core-js/stage/2.js
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions packages/core-js/stage/3.js
Expand Up @@ -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');

Expand Down
32 changes: 16 additions & 16 deletions tests/entries/unit.mjs
Expand Up @@ -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');
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion 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);
Expand Down
2 changes: 1 addition & 1 deletion 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);
Expand Down

0 comments on commit d6ad38c

Please sign in to comment.