esnext.reflect.delete-metadata.js 977 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var ReflectMetadataModule = require('../internals/reflect-metadata');
  4. var anObject = require('../internals/an-object');
  5. var toMetadataKey = ReflectMetadataModule.toKey;
  6. var getOrCreateMetadataMap = ReflectMetadataModule.getMap;
  7. var store = ReflectMetadataModule.store;
  8. // `Reflect.deleteMetadata` method
  9. // https://github.com/rbuckton/reflect-metadata
  10. $({ target: 'Reflect', stat: true }, {
  11. deleteMetadata: function deleteMetadata(metadataKey, target /* , targetKey */) {
  12. var targetKey = arguments.length < 3 ? undefined : toMetadataKey(arguments[2]);
  13. var metadataMap = getOrCreateMetadataMap(anObject(target), targetKey, false);
  14. if (metadataMap === undefined || !metadataMap['delete'](metadataKey)) return false;
  15. if (metadataMap.size) return true;
  16. var targetMetadata = store.get(target);
  17. targetMetadata['delete'](targetKey);
  18. return !!targetMetadata.size || store['delete'](target);
  19. }
  20. });