diff --git a/CHANGELOG.md b/CHANGELOG.md index 647f2a76034e..f73fdd783d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 8f047dcf86e2..665a78657e89 100644 --- a/README.md +++ b/README.md @@ -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-) @@ -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 @@ -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) diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index 53f77d807b78..bc87b428284e 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -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', @@ -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': { diff --git a/packages/core-js-compat/src/modules-by-versions.mjs b/packages/core-js-compat/src/modules-by-versions.mjs index 5bd745ac0e2d..32ea3bdaf558 100644 --- a/packages/core-js-compat/src/modules-by-versions.mjs +++ b/packages/core-js-compat/src/modules-by-versions.mjs @@ -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', ], }; diff --git a/packages/core-js/full/symbol/custom-matcher.js b/packages/core-js/full/symbol/custom-matcher.js new file mode 100644 index 000000000000..7b6dad3683a5 --- /dev/null +++ b/packages/core-js/full/symbol/custom-matcher.js @@ -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'); diff --git a/packages/core-js/full/symbol/index.js b/packages/core-js/full/symbol/index.js index 35d498cbbd00..83668137a498 100644 --- a/packages/core-js/full/symbol/index.js +++ b/packages/core-js/full/symbol/index.js @@ -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'); diff --git a/packages/core-js/modules/esnext.symbol.custom-matcher.js b/packages/core-js/modules/esnext.symbol.custom-matcher.js new file mode 100644 index 000000000000..0950470bffc0 --- /dev/null +++ b/packages/core-js/modules/esnext.symbol.custom-matcher.js @@ -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'); diff --git a/packages/core-js/proposals/pattern-matching-v2.js b/packages/core-js/proposals/pattern-matching-v2.js new file mode 100644 index 000000000000..726cd2150d9b --- /dev/null +++ b/packages/core-js/proposals/pattern-matching-v2.js @@ -0,0 +1,3 @@ +'use strict'; +// https://github.com/tc39/proposal-pattern-matching +require('../modules/esnext.symbol.custom-matcher'); diff --git a/packages/core-js/stage/1.js b/packages/core-js/stage/1.js index eb2371ea872b..d359930b40b1 100644 --- a/packages/core-js/stage/1.js +++ b/packages/core-js/stage/1.js @@ -13,7 +13,7 @@ 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'); @@ -21,6 +21,7 @@ require('../proposals/string-cooked'); 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; diff --git a/tests/compat-data/tests-coverage.mjs b/tests/compat-data/tests-coverage.mjs index 5c5faeed52cb..d7d839b65d0d 100644 --- a/tests/compat-data/tests-coverage.mjs +++ b/tests/compat-data/tests-coverage.mjs @@ -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', diff --git a/tests/compat/tests.js b/tests/compat/tests.js index 22892c9a77c7..366bff9b2301 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -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; @@ -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; }, diff --git a/tests/entries/unit.mjs b/tests/entries/unit.mjs index 5c42ae13da0b..62564f30d054 100644 --- a/tests/entries/unit.mjs +++ b/tests/entries/unit.mjs @@ -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); @@ -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'); diff --git a/tests/unit-global/esnext.symbol.custom-matcher.js b/tests/unit-global/esnext.symbol.custom-matcher.js new file mode 100644 index 000000000000..eaa753a63125 --- /dev/null +++ b/tests/unit-global/esnext.symbol.custom-matcher.js @@ -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'); + } +}); diff --git a/tests/unit-pure/esnext.symbol.custom-matcher.js b/tests/unit-pure/esnext.symbol.custom-matcher.js new file mode 100644 index 000000000000..68ce86f85c8a --- /dev/null +++ b/tests/unit-pure/esnext.symbol.custom-matcher.js @@ -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'); +});