Skip to content

Commit

Permalink
Merge pull request #1343 from zloirock/update-pattern-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock authored Apr 16, 2024
2 parents be019f9 + c978c8f commit a7f8abf
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
- [`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 stage 1 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
- [Extractors stage 1 proposal](https://github.com/tc39/proposal-extractors):
- Built-ins:
- `Symbol.customMatcher`
- Since the `Symbol.customMatcher` well-known symbol from the pattern matching proposal is also used in the exactors proposal, added an entry also for this proposal
- 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
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ 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)
- [`Symbol.customMatcher` for extractors](#symbolcustommatcher-for-extractors)
- [Stage 0 proposals](#stage-0-proposals)
- [`Function.prototype.demethodize`](#functionprototypedemethodize)
- [`Function.{ isCallable, isConstructor }`](#function-iscallable-isconstructor-)
Expand Down Expand Up @@ -2759,6 +2760,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 +3085,31 @@ 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 customMatcher: @@customMatcher;
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/pattern-matching-v2
core-js(-pure)/full/symbol/custom-matcher
```

##### [`Symbol.customMatcher` for extractors](https://github.com/tc39/proposal-extractors)[⬆](#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-extractors
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/extractors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
// https://github.com/tc39/proposal-extractors
require('../modules/esnext.symbol.custom-matcher');
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');
4 changes: 3 additions & 1 deletion packages/core-js/stage/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ require('../proposals/array-unique');
require('../proposals/collection-methods');
require('../proposals/collection-of-from');
require('../proposals/data-view-get-set-uint8-clamped');
require('../proposals/extractors');
require('../proposals/keys-composition');
require('../proposals/math-extensions');
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
3 changes: 3 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 @@ -923,6 +924,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
load('proposals/efficient-64-bit-arithmetic');
load('proposals/error-cause');
load('proposals/explicit-resource-management');
load('proposals/extractors');
load('proposals/float16');
load('proposals/function-demethodize');
load('proposals/function-is-callable-is-constructor');
Expand All @@ -948,6 +950,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 a7f8abf

Please sign in to comment.