Skip to content

Commit

Permalink
update pattern matching proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 16, 2024
1 parent 212ff8a commit 8957db1
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
- [`RegExp.escape` stage 2 proposal](https://github.com/tc39/proposal-regex-escaping)
- Moved to hex-escape semantics, [regex-escaping/67](https://github.com/tc39/proposal-regex-escaping/pull/67)
- 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
- [Pattern matching proposal](https://github.com/tc39/proposal-pattern-matching):
- Built-ins:
- `Symbol.customMatcher`
- Once again, [the used well-known symbol was renamed](https://github.com/tc39/proposal-pattern-matching/pull/295)
- Added new entries for that
- Added [`URL.parse`](https://url.spec.whatwg.org/#dom-url-parse), [url/825](https://github.com/whatwg/url/pull/825)
- Engines bugs fixes:
- Added a fix of [Safari `{ Object, Map }.groupBy` bug that does not support iterable primitives](https://bugs.webkit.org/show_bug.cgi?id=271524)
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
- [`Number.fromString`](#numberfromstring)
- [`String.cooked`](#stringcooked)
- [`String.prototype.codePoints`](#stringprototypecodepoints)
- [`Symbol.matcher` for pattern matching](#symbolmatcher-for-pattern-matching)
- [`Symbol.customMatcher` for pattern matching](#symbolcustommatcher-for-pattern-matching)
- [Stage 0 proposals](#stage-0-proposals)
- [`Function.prototype.demethodize`](#functionprototypedemethodize)
- [`Function.{ isCallable, isConstructor }`](#function-iscallable-isconstructor-)
Expand Down Expand Up @@ -2759,6 +2759,7 @@ Symbol.isRegisteredSymbol(Symbol('key')); // => false
Symbol.isWellKnownSymbol(Symbol.iterator); // => true
Symbol.isWellKnownSymbol(Symbol('key')); // => false
```

##### [`Uint8Array` to / from base64 and hex](https://github.com/tc39/proposal-arraybuffer-base64)[⬆](#index)
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).
```js
Expand Down Expand Up @@ -3083,17 +3084,18 @@ for (let { codePoint, position } of 'qwe'.codePoints()) {
console.log(position); // => 0, 1, 2
}
```
##### [`Symbol.matcher` for pattern matching](https://github.com/tc39/proposal-pattern-matching)[⬆](#index)
Module [`esnext.symbol.matcher`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.matcher.js).

##### [`Symbol.customMatcher` for pattern matching](https://github.com/tc39/proposal-pattern-matching)[⬆](#index)
Module [`esnext.symbol.custom-matcher`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.custom-matcher.js).
```js
class Symbol {
static matcher: @@matcher;
static customMatcher: @@customMatcher;
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/pattern-matching
core-js(-pure)/full/symbol/matcher
core-js/proposals/pattern-matching-v2
core-js(-pure)/full/symbol/custom-matcher
```

#### Stage 0 proposals[⬆](#index)
Expand Down
3 changes: 3 additions & 0 deletions packages/core-js-compat/src/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,8 @@ export const data = {
// https://github.com/nodejs/node/issues/48699
node: '20.5.0',
},
'esnext.symbol.custom-matcher': {
},
'esnext.symbol.dispose': {
bun: '1.0.23',
deno: '1.38',
Expand All @@ -2427,6 +2429,7 @@ export const data = {
// TODO: Remove from `core-js@4`
'esnext.symbol.is-well-known': {
},
// TODO: Remove from `core-js@4`
'esnext.symbol.matcher': {
},
'esnext.symbol.metadata': {
Expand Down
1 change: 1 addition & 0 deletions packages/core-js-compat/src/modules-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default {
'es.set.symmetric-difference.v2',
'es.set.union.v2',
'esnext.math.sum-precise',
'esnext.symbol.custom-matcher',
'web.url.parse',
],
};
5 changes: 5 additions & 0 deletions packages/core-js/full/symbol/custom-matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
require('../../modules/esnext.symbol.custom-matcher');
var WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');

module.exports = WrappedWellKnownSymbolModule.f('customMatcher');
3 changes: 2 additions & 1 deletion packages/core-js/full/symbol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
var parent = require('../../actual/symbol');
require('../../modules/esnext.symbol.is-registered-symbol');
require('../../modules/esnext.symbol.is-well-known-symbol');
require('../../modules/esnext.symbol.matcher');
require('../../modules/esnext.symbol.custom-matcher');
require('../../modules/esnext.symbol.observable');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.symbol.is-registered');
require('../../modules/esnext.symbol.is-well-known');
require('../../modules/esnext.symbol.matcher');
require('../../modules/esnext.symbol.metadata-key');
require('../../modules/esnext.symbol.pattern-match');
require('../../modules/esnext.symbol.replace-all');
Expand Down
6 changes: 6 additions & 0 deletions packages/core-js/modules/esnext.symbol.custom-matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
var defineWellKnownSymbol = require('../internals/well-known-symbol-define');

// `Symbol.customMatcher` well-known symbol
// https://github.com/tc39/proposal-pattern-matching
defineWellKnownSymbol('customMatcher');
3 changes: 3 additions & 0 deletions packages/core-js/proposals/pattern-matching-v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
// https://github.com/tc39/proposal-pattern-matching
require('../modules/esnext.symbol.custom-matcher');
3 changes: 2 additions & 1 deletion packages/core-js/stage/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ require('../proposals/math-signbit');
require('../proposals/number-from-string');
require('../proposals/object-iteration');
require('../proposals/observable');
require('../proposals/pattern-matching');
require('../proposals/pattern-matching-v2');
require('../proposals/seeded-random');
require('../proposals/string-code-points');
require('../proposals/string-cooked');
// TODO: Obsolete versions, remove from `core-js@4`:
require('../proposals/array-from-async');
require('../proposals/map-upsert');
require('../proposals/number-range');
require('../proposals/pattern-matching');
require('../proposals/string-replace-all');

module.exports = parent;
1 change: 1 addition & 0 deletions tests/compat-data/tests-coverage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const ignore = new Set([
'esnext.string.at',
'esnext.symbol.is-registered',
'esnext.symbol.is-well-known',
'esnext.symbol.matcher',
'esnext.symbol.metadata-key',
'esnext.symbol.pattern-match',
'esnext.symbol.replace-all',
Expand Down
6 changes: 3 additions & 3 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,9 @@ GLOBAL.tests = {
var descriptor = Object.getOwnPropertyDescriptor(Symbol, 'asyncDispose');
return descriptor.value && !descriptor.enumerable && !descriptor.configurable && !descriptor.writable;
},
'esnext.symbol.custom-matcher': function () {
return Symbol.customMatcher;
},
'esnext.symbol.dispose': function () {
var descriptor = Object.getOwnPropertyDescriptor(Symbol, 'dispose');
return descriptor.value && !descriptor.enumerable && !descriptor.configurable && !descriptor.writable;
Expand All @@ -1832,9 +1835,6 @@ GLOBAL.tests = {
'esnext.symbol.is-well-known-symbol': function () {
return Symbol.isWellKnownSymbol;
},
'esnext.symbol.matcher': function () {
return Symbol.matcher;
},
'esnext.symbol.metadata': function () {
return Symbol.metadata;
},
Expand Down
2 changes: 2 additions & 0 deletions tests/entries/unit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
` === 'a1b');
ok('next' in load(NS, 'string/code-points')('a'));
ok('next' in load(NS, 'string/virtual/code-points').call('a'));
ok(load(NS, 'symbol/custom-matcher'));
ok(load(NS, 'symbol/is-registered-symbol')(1) === false);
ok(load(NS, 'symbol/is-well-known-symbol')(1) === false);
ok(load(NS, 'symbol/is-registered')(1) === false);
Expand Down Expand Up @@ -948,6 +949,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
load('proposals/object-values-entries');
load('proposals/observable');
load('proposals/pattern-matching');
load('proposals/pattern-matching-v2');
load('proposals/promise-all-settled');
load('proposals/promise-any');
load('proposals/promise-finally');
Expand Down
13 changes: 13 additions & 0 deletions tests/unit-global/esnext.symbol.custom-matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DESCRIPTORS } from '../helpers/constants.js';

QUnit.test('Symbol.customMatcher', assert => {
assert.true('customMatcher' in Symbol, 'Symbol.customMatcher available');
assert.nonEnumerable(Symbol, 'customMatcher');
assert.true(Object(Symbol.customMatcher) instanceof Symbol, 'Symbol.customMatcher is symbol');
if (DESCRIPTORS) {
const descriptor = Object.getOwnPropertyDescriptor(Symbol, 'customMatcher');
assert.false(descriptor.enumerable, 'non-enumerable');
assert.false(descriptor.writable, 'non-writable');
assert.false(descriptor.configurable, 'non-configurable');
}
});
6 changes: 6 additions & 0 deletions tests/unit-pure/esnext.symbol.custom-matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Symbol from 'core-js-pure/full/symbol';

QUnit.test('Symbol.customMatcher', assert => {
assert.true('customMatcher' in Symbol, 'Symbol.customMatcher available');
assert.true(Object(Symbol.customMatcher) instanceof Symbol, 'Symbol.customMatcher is symbol');
});

0 comments on commit 8957db1

Please sign in to comment.