Skip to content

Commit

Permalink
add Symbol.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 5, 2021
1 parent f498ee5 commit 98e421f
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,18 @@ Object.hasOwn({ foo: 42 }, 'foo'); // => true
Object.hasOwn({ foo: 42 }, 'bar'); // => false
Object.hasOwn({}, 'toString'); // => false
````
##### [`Symbol.metadata` for decorators proposal](https://github.com/tc39/proposal-decorators)[⬆](#index)
Module [`esnext.symbol.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.metadata.js).
```js
class Symbol {
static metadata: @@metadata;
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/decorators
core-js(-pure)/features/symbol/metadata
```
#### Stage 1 proposals[⬆](#index)
[*CommonJS entry points:*](#commonjs-api)
Expand Down
2 changes: 2 additions & 0 deletions packages/core-js-compat/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ const data = {
},
'esnext.symbol.dispose': {
},
'esnext.symbol.metadata': {
},
'esnext.symbol.observable': {
},
'esnext.symbol.pattern-match': {
Expand Down
3 changes: 3 additions & 0 deletions packages/core-js-compat/src/modules-by-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ module.exports = {
3.11: [
'esnext.object.has-own',
],
3.12: [
'esnext.symbol.metadata',
],
};
1 change: 1 addition & 0 deletions packages/core-js/features/symbol/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var parent = require('../../es/symbol');
require('../../modules/esnext.symbol.async-dispose');
require('../../modules/esnext.symbol.dispose');
require('../../modules/esnext.symbol.metadata');
require('../../modules/esnext.symbol.observable');
require('../../modules/esnext.symbol.pattern-match');
// TODO: Remove from `core-js@4`
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/features/symbol/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/esnext.symbol.metadata');
var WrappedWellKnownSymbolModule = require('../../internals/well-known-symbol-wrapped');

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

// `Symbol.metadata` well-known symbol
// https://github.com/tc39/proposal-decorators
defineWellKnownSymbol('metadata');
2 changes: 2 additions & 0 deletions packages/core-js/proposals/decorators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// https://github.com/tc39/proposal-decorators
require('../modules/esnext.symbol.metadata');
1 change: 1 addition & 0 deletions packages/core-js/proposals/pattern-matching.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// https://github.com/tc39/proposal-pattern-matching
require('../modules/esnext.symbol.pattern-match');
1 change: 1 addition & 0 deletions packages/core-js/stage/2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('../proposals/accessible-object-hasownproperty');
require('../proposals/array-find-from-last');
require('../proposals/array-is-template-object');
require('../proposals/decorators');
require('../proposals/iterator-helpers');
require('../proposals/map-upsert');
require('../proposals/set-methods');
Expand Down
3 changes: 2 additions & 1 deletion tests/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ for (PATH of ['core-js-pure', 'core-js']) {
}, 1, 2)(3) === 6);
load('features/function/name');
load('features/function/has-instance');
ok(Function[load('features/symbol/has-instance')](it => it));
ok('bind' in load('features/function'));
ok(load('features/array/is-array')([]));
ok(typeof load('features/array/is-template-object') === 'function');
Expand Down Expand Up @@ -299,6 +298,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(load('features/symbol/iterator'));
ok(load('features/symbol/match'));
ok(load('features/symbol/match-all'));
ok(load('features/symbol/metadata'));
ok(load('features/symbol/replace'));
ok(load('features/symbol/search'));
ok(load('features/symbol/species'));
Expand Down Expand Up @@ -972,6 +972,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
load('proposals/array-unique');
load('proposals/collection-methods');
load('proposals/collection-of-from');
load('proposals/decorators');
load('proposals/efficient-64-bit-arithmetic');
load('proposals/global-this');
load('proposals/iterator-helpers');
Expand Down
3 changes: 3 additions & 0 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,9 @@ GLOBAL.tests = {
'esnext.symbol.dispose': function () {
return Symbol.dispose;
},
'esnext.symbol.metadata': function () {
return Symbol.metadata;
},
'esnext.symbol.observable': function () {
return Symbol.observable;
},
Expand Down
6 changes: 6 additions & 0 deletions tests/pure/esnext.symbol.metadata.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.metadata', assert => {
assert.ok('metadata' in Symbol, 'Symbol.metadata available');
assert.ok(Object(Symbol.metadata) instanceof Symbol, 'Symbol.metadata is symbol');
});
13 changes: 13 additions & 0 deletions tests/tests/esnext.symbol.metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DESCRIPTORS } from '../helpers/constants';

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

0 comments on commit 98e421f

Please sign in to comment.