esnext.reflect.delete-metadata.js 963 B

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