Skip to content

Commit 8957db1

Browse files
committed
update pattern matching proposal
1 parent 212ff8a commit 8957db1

File tree

14 files changed

+60
-11
lines changed

14 files changed

+60
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
- [`RegExp.escape` stage 2 proposal](https://github.com/tc39/proposal-regex-escaping)
2525
- Moved to hex-escape semantics, [regex-escaping/67](https://github.com/tc39/proposal-regex-escaping/pull/67)
2626
- It's not the final change of the way of escaping, waiting for [regex-escaping/77](https://github.com/tc39/proposal-regex-escaping/pull/77) soon
27+
- [Pattern matching proposal](https://github.com/tc39/proposal-pattern-matching):
28+
- Built-ins:
29+
- `Symbol.customMatcher`
30+
- Once again, [the used well-known symbol was renamed](https://github.com/tc39/proposal-pattern-matching/pull/295)
31+
- Added new entries for that
2732
- Added [`URL.parse`](https://url.spec.whatwg.org/#dom-url-parse), [url/825](https://github.com/whatwg/url/pull/825)
2833
- Engines bugs fixes:
2934
- Added a fix of [Safari `{ Object, Map }.groupBy` bug that does not support iterable primitives](https://bugs.webkit.org/show_bug.cgi?id=271524)

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
185185
- [`Number.fromString`](#numberfromstring)
186186
- [`String.cooked`](#stringcooked)
187187
- [`String.prototype.codePoints`](#stringprototypecodepoints)
188-
- [`Symbol.matcher` for pattern matching](#symbolmatcher-for-pattern-matching)
188+
- [`Symbol.customMatcher` for pattern matching](#symbolcustommatcher-for-pattern-matching)
189189
- [Stage 0 proposals](#stage-0-proposals)
190190
- [`Function.prototype.demethodize`](#functionprototypedemethodize)
191191
- [`Function.{ isCallable, isConstructor }`](#function-iscallable-isconstructor-)
@@ -2759,6 +2759,7 @@ Symbol.isRegisteredSymbol(Symbol('key')); // => false
27592759
Symbol.isWellKnownSymbol(Symbol.iterator); // => true
27602760
Symbol.isWellKnownSymbol(Symbol('key')); // => false
27612761
```
2762+
27622763
##### [`Uint8Array` to / from base64 and hex](https://github.com/tc39/proposal-arraybuffer-base64)[⬆](#index)
27632764
Modules [`esnext.uint8-array.from-base64`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.uint8-array.from-base64.js), [`esnext.uint8-array.from-hex`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.uint8-array.from-hex.js), [`esnext.uint8-array.to-base64`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.uint8-array.to-base64.js), [`esnext.uint8-array.to-hex`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.uint8-array.to-hex.js).
27642765
```js
@@ -3083,17 +3084,18 @@ for (let { codePoint, position } of 'qwe'.codePoints()) {
30833084
console.log(position); // => 0, 1, 2
30843085
}
30853086
```
3086-
##### [`Symbol.matcher` for pattern matching](https://github.com/tc39/proposal-pattern-matching)[⬆](#index)
3087-
Module [`esnext.symbol.matcher`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.matcher.js).
3087+
3088+
##### [`Symbol.customMatcher` for pattern matching](https://github.com/tc39/proposal-pattern-matching)[⬆](#index)
3089+
Module [`esnext.symbol.custom-matcher`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.custom-matcher.js).
30883090
```js
30893091
class Symbol {
3090-
static matcher: @@matcher;
3092+
static customMatcher: @@customMatcher;
30913093
}
30923094
```
30933095
[*CommonJS entry points:*](#commonjs-api)
30943096
```js
3095-
core-js/proposals/pattern-matching
3096-
core-js(-pure)/full/symbol/matcher
3097+
core-js/proposals/pattern-matching-v2
3098+
core-js(-pure)/full/symbol/custom-matcher
30973099
```
30983100

30993101
#### Stage 0 proposals[⬆](#index)

packages/core-js-compat/src/data.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,8 @@ export const data = {
24092409
// https://github.com/nodejs/node/issues/48699
24102410
node: '20.5.0',
24112411
},
2412+
'esnext.symbol.custom-matcher': {
2413+
},
24122414
'esnext.symbol.dispose': {
24132415
bun: '1.0.23',
24142416
deno: '1.38',
@@ -2427,6 +2429,7 @@ export const data = {
24272429
// TODO: Remove from `core-js@4`
24282430
'esnext.symbol.is-well-known': {
24292431
},
2432+
// TODO: Remove from `core-js@4`
24302433
'esnext.symbol.matcher': {
24312434
},
24322435
'esnext.symbol.metadata': {

packages/core-js-compat/src/modules-by-versions.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export default {
246246
'es.set.symmetric-difference.v2',
247247
'es.set.union.v2',
248248
'esnext.math.sum-precise',
249+
'esnext.symbol.custom-matcher',
249250
'web.url.parse',
250251
],
251252
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
require('../../modules/esnext.symbol.custom-matcher');
3+
var WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');
4+
5+
module.exports = WrappedWellKnownSymbolModule.f('customMatcher');

packages/core-js/full/symbol/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
var parent = require('../../actual/symbol');
33
require('../../modules/esnext.symbol.is-registered-symbol');
44
require('../../modules/esnext.symbol.is-well-known-symbol');
5-
require('../../modules/esnext.symbol.matcher');
5+
require('../../modules/esnext.symbol.custom-matcher');
66
require('../../modules/esnext.symbol.observable');
77
// TODO: Remove from `core-js@4`
88
require('../../modules/esnext.symbol.is-registered');
99
require('../../modules/esnext.symbol.is-well-known');
10+
require('../../modules/esnext.symbol.matcher');
1011
require('../../modules/esnext.symbol.metadata-key');
1112
require('../../modules/esnext.symbol.pattern-match');
1213
require('../../modules/esnext.symbol.replace-all');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
var defineWellKnownSymbol = require('../internals/well-known-symbol-define');
3+
4+
// `Symbol.customMatcher` well-known symbol
5+
// https://github.com/tc39/proposal-pattern-matching
6+
defineWellKnownSymbol('customMatcher');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
// https://github.com/tc39/proposal-pattern-matching
3+
require('../modules/esnext.symbol.custom-matcher');

packages/core-js/stage/1.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ require('../proposals/math-signbit');
1313
require('../proposals/number-from-string');
1414
require('../proposals/object-iteration');
1515
require('../proposals/observable');
16-
require('../proposals/pattern-matching');
16+
require('../proposals/pattern-matching-v2');
1717
require('../proposals/seeded-random');
1818
require('../proposals/string-code-points');
1919
require('../proposals/string-cooked');
2020
// TODO: Obsolete versions, remove from `core-js@4`:
2121
require('../proposals/array-from-async');
2222
require('../proposals/map-upsert');
2323
require('../proposals/number-range');
24+
require('../proposals/pattern-matching');
2425
require('../proposals/string-replace-all');
2526

2627
module.exports = parent;

tests/compat-data/tests-coverage.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const ignore = new Set([
6464
'esnext.string.at',
6565
'esnext.symbol.is-registered',
6666
'esnext.symbol.is-well-known',
67+
'esnext.symbol.matcher',
6768
'esnext.symbol.metadata-key',
6869
'esnext.symbol.pattern-match',
6970
'esnext.symbol.replace-all',

tests/compat/tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,9 @@ GLOBAL.tests = {
18221822
var descriptor = Object.getOwnPropertyDescriptor(Symbol, 'asyncDispose');
18231823
return descriptor.value && !descriptor.enumerable && !descriptor.configurable && !descriptor.writable;
18241824
},
1825+
'esnext.symbol.custom-matcher': function () {
1826+
return Symbol.customMatcher;
1827+
},
18251828
'esnext.symbol.dispose': function () {
18261829
var descriptor = Object.getOwnPropertyDescriptor(Symbol, 'dispose');
18271830
return descriptor.value && !descriptor.enumerable && !descriptor.configurable && !descriptor.writable;
@@ -1832,9 +1835,6 @@ GLOBAL.tests = {
18321835
'esnext.symbol.is-well-known-symbol': function () {
18331836
return Symbol.isWellKnownSymbol;
18341837
},
1835-
'esnext.symbol.matcher': function () {
1836-
return Symbol.matcher;
1837-
},
18381838
'esnext.symbol.metadata': function () {
18391839
return Symbol.metadata;
18401840
},

tests/entries/unit.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
836836
` === 'a1b');
837837
ok('next' in load(NS, 'string/code-points')('a'));
838838
ok('next' in load(NS, 'string/virtual/code-points').call('a'));
839+
ok(load(NS, 'symbol/custom-matcher'));
839840
ok(load(NS, 'symbol/is-registered-symbol')(1) === false);
840841
ok(load(NS, 'symbol/is-well-known-symbol')(1) === false);
841842
ok(load(NS, 'symbol/is-registered')(1) === false);
@@ -948,6 +949,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
948949
load('proposals/object-values-entries');
949950
load('proposals/observable');
950951
load('proposals/pattern-matching');
952+
load('proposals/pattern-matching-v2');
951953
load('proposals/promise-all-settled');
952954
load('proposals/promise-any');
953955
load('proposals/promise-finally');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DESCRIPTORS } from '../helpers/constants.js';
2+
3+
QUnit.test('Symbol.customMatcher', assert => {
4+
assert.true('customMatcher' in Symbol, 'Symbol.customMatcher available');
5+
assert.nonEnumerable(Symbol, 'customMatcher');
6+
assert.true(Object(Symbol.customMatcher) instanceof Symbol, 'Symbol.customMatcher is symbol');
7+
if (DESCRIPTORS) {
8+
const descriptor = Object.getOwnPropertyDescriptor(Symbol, 'customMatcher');
9+
assert.false(descriptor.enumerable, 'non-enumerable');
10+
assert.false(descriptor.writable, 'non-writable');
11+
assert.false(descriptor.configurable, 'non-configurable');
12+
}
13+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Symbol from 'core-js-pure/full/symbol';
2+
3+
QUnit.test('Symbol.customMatcher', assert => {
4+
assert.true('customMatcher' in Symbol, 'Symbol.customMatcher available');
5+
assert.true(Object(Symbol.customMatcher) instanceof Symbol, 'Symbol.customMatcher is symbol');
6+
});

0 commit comments

Comments
 (0)