From 8957db17d8cd9244bf8932c357195bda535b1364 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Sun, 31 Mar 2024 01:41:56 +0700 Subject: [PATCH 1/2] update pattern matching proposal --- CHANGELOG.md | 5 +++++ README.md | 14 ++++++++------ packages/core-js-compat/src/data.mjs | 3 +++ .../core-js-compat/src/modules-by-versions.mjs | 1 + packages/core-js/full/symbol/custom-matcher.js | 5 +++++ packages/core-js/full/symbol/index.js | 3 ++- .../modules/esnext.symbol.custom-matcher.js | 6 ++++++ packages/core-js/proposals/pattern-matching-v2.js | 3 +++ packages/core-js/stage/1.js | 3 ++- tests/compat-data/tests-coverage.mjs | 1 + tests/compat/tests.js | 6 +++--- tests/entries/unit.mjs | 2 ++ tests/unit-global/esnext.symbol.custom-matcher.js | 13 +++++++++++++ tests/unit-pure/esnext.symbol.custom-matcher.js | 6 ++++++ 14 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 packages/core-js/full/symbol/custom-matcher.js create mode 100644 packages/core-js/modules/esnext.symbol.custom-matcher.js create mode 100644 packages/core-js/proposals/pattern-matching-v2.js create mode 100644 tests/unit-global/esnext.symbol.custom-matcher.js create mode 100644 tests/unit-pure/esnext.symbol.custom-matcher.js 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'); +}); From c978c8f700a8dbfb2cd746306289117eec05ec79 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Tue, 16 Apr 2024 23:36:35 +0700 Subject: [PATCH 2/2] add an entry for exactors proposal --- CHANGELOG.md | 6 +++++- README.md | 14 ++++++++++++++ packages/core-js/proposals/extractors.js | 3 +++ packages/core-js/stage/1.js | 1 + tests/entries/unit.mjs | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/core-js/proposals/extractors.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f73fdd783d45..796474d57a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,11 +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 proposal](https://github.com/tc39/proposal-pattern-matching): +- [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) diff --git a/README.md b/README.md index 665a78657e89..cce0b880279b 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,7 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3]) - [`String.cooked`](#stringcooked) - [`String.prototype.codePoints`](#stringprototypecodepoints) - [`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-) @@ -3098,6 +3099,19 @@ 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 customMatcher: @@customMatcher; +} +``` +[*CommonJS entry points:*](#commonjs-api) +```js +core-js/proposals/pattern-extractors +core-js(-pure)/full/symbol/custom-matcher +``` + #### Stage 0 proposals[⬆](#index) [*CommonJS entry points:*](#commonjs-api) ```js diff --git a/packages/core-js/proposals/extractors.js b/packages/core-js/proposals/extractors.js new file mode 100644 index 000000000000..abda3a8c6ab7 --- /dev/null +++ b/packages/core-js/proposals/extractors.js @@ -0,0 +1,3 @@ +'use strict'; +// https://github.com/tc39/proposal-extractors +require('../modules/esnext.symbol.custom-matcher'); diff --git a/packages/core-js/stage/1.js b/packages/core-js/stage/1.js index d359930b40b1..4f59dad3533f 100644 --- a/packages/core-js/stage/1.js +++ b/packages/core-js/stage/1.js @@ -7,6 +7,7 @@ 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'); diff --git a/tests/entries/unit.mjs b/tests/entries/unit.mjs index 62564f30d054..27a9ae0f39f9 100644 --- a/tests/entries/unit.mjs +++ b/tests/entries/unit.mjs @@ -924,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');