Skip to content

Commit

Permalink
add Symbol.matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 5, 2021
1 parent 98e421f commit b3afb28
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2400,8 +2400,8 @@ for (let x of Math.seededPRNG({ seed: 42 })) {
if (x > .8) break;
}
```
##### [`Symbol.patternMatch` for pattern matching](https://github.com/tc39/proposal-pattern-matching)[⬆](#index)
Module [`esnext.symbol.pattern-match`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.pattern-match.js).
##### [`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).
```js
class Symbol {
static patternMatch: @@patternMatch;
Expand All @@ -2410,7 +2410,7 @@ class Symbol {
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/pattern-matching
core-js(-pure)/features/symbol/pattern-match
core-js(-pure)/features/symbol/matcher
```
##### [Object iteration](https://github.com/tc39/proposal-object-iteration)[⬆](#index)
Modules [`esnext.object.iterate-keys`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.object.iterate-keys.js), [`esnext.object.iterate-values`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.object.iterate-values.js), [`esnext.object.iterate-entries`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.object.iterate-entries.js).
Expand Down
3 changes: 3 additions & 0 deletions packages/core-js-compat/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,10 +1504,13 @@ const data = {
},
'esnext.symbol.dispose': {
},
'esnext.symbol.matcher': {
},
'esnext.symbol.metadata': {
},
'esnext.symbol.observable': {
},
// TODO: Remove from `core-js@4`
'esnext.symbol.pattern-match': {
},
// TODO: Remove from `core-js@4`
Expand Down
1 change: 1 addition & 0 deletions packages/core-js-compat/src/modules-by-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.exports = {
'esnext.object.has-own',
],
3.12: [
'esnext.symbol.matcher',
'esnext.symbol.metadata',
],
};
2 changes: 2 additions & 0 deletions packages/core-js/features/symbol/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var parent = require('../../es/symbol');
require('../../modules/esnext.symbol.async-dispose');
require('../../modules/esnext.symbol.dispose');
require('../../modules/esnext.symbol.matcher');
require('../../modules/esnext.symbol.metadata');
require('../../modules/esnext.symbol.observable');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.symbol.pattern-match');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.symbol.replace-all');
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/features/symbol/matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/esnext.symbol.matcher');
var WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');

module.exports = WrappedWellKnownSymbolModule.f('matcher');
1 change: 1 addition & 0 deletions packages/core-js/features/symbol/pattern-match.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Remove from `core-js@4`
require('../../modules/esnext.symbol.pattern-match');
var WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');

Expand Down
5 changes: 5 additions & 0 deletions packages/core-js/modules/esnext.symbol.matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var defineWellKnownSymbol = require('../internals/define-well-known-symbol');

// `Symbol.matcher` well-known symbol
// https://github.com/tc39/proposal-pattern-matching
defineWellKnownSymbol('matcher');
1 change: 1 addition & 0 deletions packages/core-js/modules/esnext.symbol.pattern-match.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: remove from `core-js@4`
var defineWellKnownSymbol = require('../internals/define-well-known-symbol');

// `Symbol.patternMatch` well-known symbol
Expand Down
2 changes: 2 additions & 0 deletions packages/core-js/proposals/pattern-matching.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// https://github.com/tc39/proposal-pattern-matching
require('../modules/esnext.symbol.matcher');
// TODO: remove from `core-js@4`
require('../modules/esnext.symbol.pattern-match');
1 change: 1 addition & 0 deletions tests/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(load('features/symbol/is-concat-spreadable'));
ok(load('features/symbol/iterator'));
ok(load('features/symbol/match'));
ok(load('features/symbol/matcher'));
ok(load('features/symbol/match-all'));
ok(load('features/symbol/metadata'));
ok(load('features/symbol/replace'));
Expand Down
4 changes: 4 additions & 0 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1431,12 +1431,16 @@ GLOBAL.tests = {
'esnext.symbol.dispose': function () {
return Symbol.dispose;
},
'esnext.symbol.matcher': function () {
return Symbol.matcher;
},
'esnext.symbol.metadata': function () {
return Symbol.metadata;
},
'esnext.symbol.observable': function () {
return Symbol.observable;
},
// TODO: Remove from `core-js@4`
'esnext.symbol.pattern-match': function () {
return Symbol.patternMatch;
},
Expand Down
6 changes: 6 additions & 0 deletions tests/pure/esnext.symbol.matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Symbol from 'core-js-pure/features/symbol';

QUnit.test('Symbol.matcher', assert => {
assert.ok('matcher' in Symbol, 'Symbol.matcher available');
assert.ok(Object(Symbol.matcher) instanceof Symbol, 'Symbol.matcher is symbol');
});
13 changes: 13 additions & 0 deletions tests/tests/esnext.symbol.matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DESCRIPTORS } from '../helpers/constants';

QUnit.test('Symbol.matcher', assert => {
assert.ok('matcher' in Symbol, 'Symbol.matcher available');
assert.nonEnumerable(Symbol, 'matcher');
assert.ok(Object(Symbol.matcher) instanceof Symbol, 'Symbol.matcher is symbol');
if (DESCRIPTORS) {
const descriptor = Object.getOwnPropertyDescriptor(Symbol, 'matcher');
assert.ok(!descriptor.enumerble, 'non-enumerable');
assert.ok(!descriptor.writable, 'non-writable');
assert.ok(!descriptor.configurable, 'non-configurable');
}
});

0 comments on commit b3afb28

Please sign in to comment.