Path: blob/master/node_modules/@babel/runtime/helpers/applyDecs.js
1126 views
var _typeof = require("./typeof.js")["default"];12function old_createMetadataMethodsForProperty(metadataMap, kind, property, decoratorFinishedRef) {3return {4getMetadata: function getMetadata(key) {5old_assertNotFinished(decoratorFinishedRef, "getMetadata"), old_assertMetadataKey(key);6var metadataForKey = metadataMap[key];7if (void 0 !== metadataForKey) if (1 === kind) {8var pub = metadataForKey["public"];9if (void 0 !== pub) return pub[property];10} else if (2 === kind) {11var priv = metadataForKey["private"];12if (void 0 !== priv) return priv.get(property);13} else if (Object.hasOwnProperty.call(metadataForKey, "constructor")) return metadataForKey.constructor;14},15setMetadata: function setMetadata(key, value) {16old_assertNotFinished(decoratorFinishedRef, "setMetadata"), old_assertMetadataKey(key);17var metadataForKey = metadataMap[key];1819if (void 0 === metadataForKey && (metadataForKey = metadataMap[key] = {}), 1 === kind) {20var pub = metadataForKey["public"];21void 0 === pub && (pub = metadataForKey["public"] = {}), pub[property] = value;22} else if (2 === kind) {23var priv = metadataForKey.priv;24void 0 === priv && (priv = metadataForKey["private"] = new Map()), priv.set(property, value);25} else metadataForKey.constructor = value;26}27};28}2930function old_convertMetadataMapToFinal(obj, metadataMap) {31var parentMetadataMap = obj[Symbol.metadata || Symbol["for"]("Symbol.metadata")],32metadataKeys = Object.getOwnPropertySymbols(metadataMap);3334if (0 !== metadataKeys.length) {35for (var i = 0; i < metadataKeys.length; i++) {36var key = metadataKeys[i],37metaForKey = metadataMap[key],38parentMetaForKey = parentMetadataMap ? parentMetadataMap[key] : null,39pub = metaForKey["public"],40parentPub = parentMetaForKey ? parentMetaForKey["public"] : null;41pub && parentPub && Object.setPrototypeOf(pub, parentPub);42var priv = metaForKey["private"];4344if (priv) {45var privArr = Array.from(priv.values()),46parentPriv = parentMetaForKey ? parentMetaForKey["private"] : null;47parentPriv && (privArr = privArr.concat(parentPriv)), metaForKey["private"] = privArr;48}4950parentMetaForKey && Object.setPrototypeOf(metaForKey, parentMetaForKey);51}5253parentMetadataMap && Object.setPrototypeOf(metadataMap, parentMetadataMap), obj[Symbol.metadata || Symbol["for"]("Symbol.metadata")] = metadataMap;54}55}5657function old_createAddInitializerMethod(initializers, decoratorFinishedRef) {58return function (initializer) {59old_assertNotFinished(decoratorFinishedRef, "addInitializer"), old_assertCallable(initializer, "An initializer"), initializers.push(initializer);60};61}6263function old_memberDec(dec, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value) {64var kindStr;6566switch (kind) {67case 1:68kindStr = "accessor";69break;7071case 2:72kindStr = "method";73break;7475case 3:76kindStr = "getter";77break;7879case 4:80kindStr = "setter";81break;8283default:84kindStr = "field";85}8687var metadataKind,88metadataName,89ctx = {90kind: kindStr,91name: isPrivate ? "#" + name : name,92isStatic: isStatic,93isPrivate: isPrivate94},95decoratorFinishedRef = {96v: !197};9899if (0 !== kind && (ctx.addInitializer = old_createAddInitializerMethod(initializers, decoratorFinishedRef)), isPrivate) {100metadataKind = 2, metadataName = Symbol(name);101var access = {};1020 === kind ? (access.get = desc.get, access.set = desc.set) : 2 === kind ? access.get = function () {103return desc.value;104} : (1 !== kind && 3 !== kind || (access.get = function () {105return desc.get.call(this);106}), 1 !== kind && 4 !== kind || (access.set = function (v) {107desc.set.call(this, v);108})), ctx.access = access;109} else metadataKind = 1, metadataName = name;110111try {112return dec(value, Object.assign(ctx, old_createMetadataMethodsForProperty(metadataMap, metadataKind, metadataName, decoratorFinishedRef)));113} finally {114decoratorFinishedRef.v = !0;115}116}117118function old_assertNotFinished(decoratorFinishedRef, fnName) {119if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");120}121122function old_assertMetadataKey(key) {123if ("symbol" != _typeof(key)) throw new TypeError("Metadata keys must be symbols, received: " + key);124}125126function old_assertCallable(fn, hint) {127if ("function" != typeof fn) throw new TypeError(hint + " must be a function");128}129130function old_assertValidReturnValue(kind, value) {131var type = _typeof(value);132133if (1 === kind) {134if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");135void 0 !== value.get && old_assertCallable(value.get, "accessor.get"), void 0 !== value.set && old_assertCallable(value.set, "accessor.set"), void 0 !== value.init && old_assertCallable(value.init, "accessor.init"), void 0 !== value.initializer && old_assertCallable(value.initializer, "accessor.initializer");136} else if ("function" !== type) {137var hint;138throw hint = 0 === kind ? "field" : 10 === kind ? "class" : "method", new TypeError(hint + " decorators must return a function or void 0");139}140}141142function old_getInit(desc) {143var initializer;144return null == (initializer = desc.init) && (initializer = desc.initializer) && "undefined" != typeof console && console.warn(".initializer has been renamed to .init as of March 2022"), initializer;145}146147function old_applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers) {148var desc,149initializer,150value,151newValue,152get,153set,154decs = decInfo[0];155if (isPrivate ? desc = 0 === kind || 1 === kind ? {156get: decInfo[3],157set: decInfo[4]158} : 3 === kind ? {159get: decInfo[3]160} : 4 === kind ? {161set: decInfo[3]162} : {163value: decInfo[3]164} : 0 !== kind && (desc = Object.getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {165get: desc.get,166set: desc.set167} : 2 === kind ? value = desc.value : 3 === kind ? value = desc.get : 4 === kind && (value = desc.set), "function" == typeof decs) void 0 !== (newValue = old_memberDec(decs, name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value)) && (old_assertValidReturnValue(kind, newValue), 0 === kind ? initializer = newValue : 1 === kind ? (initializer = old_getInit(newValue), get = newValue.get || value.get, set = newValue.set || value.set, value = {168get: get,169set: set170}) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {171var newInit;172if (void 0 !== (newValue = old_memberDec(decs[i], name, desc, metadataMap, initializers, kind, isStatic, isPrivate, value))) old_assertValidReturnValue(kind, newValue), 0 === kind ? newInit = newValue : 1 === kind ? (newInit = old_getInit(newValue), get = newValue.get || value.get, set = newValue.set || value.set, value = {173get: get,174set: set175}) : value = newValue, void 0 !== newInit && (void 0 === initializer ? initializer = newInit : "function" == typeof initializer ? initializer = [initializer, newInit] : initializer.push(newInit));176}177178if (0 === kind || 1 === kind) {179if (void 0 === initializer) initializer = function initializer(instance, init) {180return init;181};else if ("function" != typeof initializer) {182var ownInitializers = initializer;183184initializer = function initializer(instance, init) {185for (var value = init, i = 0; i < ownInitializers.length; i++) {186value = ownInitializers[i].call(instance, value);187}188189return value;190};191} else {192var originalInitializer = initializer;193194initializer = function initializer(instance, init) {195return originalInitializer.call(instance, init);196};197}198ret.push(initializer);199}2002010 !== kind && (1 === kind ? (desc.get = value.get, desc.set = value.set) : 2 === kind ? desc.value = value : 3 === kind ? desc.get = value : 4 === kind && (desc.set = value), isPrivate ? 1 === kind ? (ret.push(function (instance, args) {202return value.get.call(instance, args);203}), ret.push(function (instance, args) {204return value.set.call(instance, args);205})) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {206return value.call(instance, args);207}) : Object.defineProperty(base, name, desc));208}209210function old_applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInfos) {211for (var protoInitializers, staticInitializers, existingProtoNonFields = new Map(), existingStaticNonFields = new Map(), i = 0; i < decInfos.length; i++) {212var decInfo = decInfos[i];213214if (Array.isArray(decInfo)) {215var base,216metadataMap,217initializers,218kind = decInfo[1],219name = decInfo[2],220isPrivate = decInfo.length > 3,221isStatic = kind >= 5;222223if (isStatic ? (base = Class, metadataMap = staticMetadataMap, 0 !== (kind -= 5) && (initializers = staticInitializers = staticInitializers || [])) : (base = Class.prototype, metadataMap = protoMetadataMap, 0 !== kind && (initializers = protoInitializers = protoInitializers || [])), 0 !== kind && !isPrivate) {224var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,225existingKind = existingNonFields.get(name) || 0;226if (!0 === existingKind || 3 === existingKind && 4 !== kind || 4 === existingKind && 3 !== kind) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);227!existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);228}229230old_applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers);231}232}233234old_pushInitializers(ret, protoInitializers), old_pushInitializers(ret, staticInitializers);235}236237function old_pushInitializers(ret, initializers) {238initializers && ret.push(function (instance) {239for (var i = 0; i < initializers.length; i++) {240initializers[i].call(instance);241}242243return instance;244});245}246247function old_applyClassDecs(ret, targetClass, metadataMap, classDecs) {248if (classDecs.length > 0) {249for (var initializers = [], newClass = targetClass, name = targetClass.name, i = classDecs.length - 1; i >= 0; i--) {250var decoratorFinishedRef = {251v: !1252};253254try {255var ctx = Object.assign({256kind: "class",257name: name,258addInitializer: old_createAddInitializerMethod(initializers, decoratorFinishedRef)259}, old_createMetadataMethodsForProperty(metadataMap, 0, name, decoratorFinishedRef)),260nextNewClass = classDecs[i](newClass, ctx);261} finally {262decoratorFinishedRef.v = !0;263}264265void 0 !== nextNewClass && (old_assertValidReturnValue(10, nextNewClass), newClass = nextNewClass);266}267268ret.push(newClass, function () {269for (var i = 0; i < initializers.length; i++) {270initializers[i].call(newClass);271}272});273}274}275276function applyDecs(targetClass, memberDecs, classDecs) {277var ret = [],278staticMetadataMap = {},279protoMetadataMap = {};280return old_applyMemberDecs(ret, targetClass, protoMetadataMap, staticMetadataMap, memberDecs), old_convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap), old_applyClassDecs(ret, targetClass, staticMetadataMap, classDecs), old_convertMetadataMapToFinal(targetClass, staticMetadataMap), ret;281}282283module.exports = applyDecs, module.exports.__esModule = true, module.exports["default"] = module.exports;284285