Path: blob/master/node_modules/@babel/runtime/helpers/esm/applyDecs2203.js
1126 views
import _typeof from "./typeof.js";12function createAddInitializerMethod(initializers, decoratorFinishedRef) {3return function (initializer) {4assertNotFinished(decoratorFinishedRef, "addInitializer"), assertCallable(initializer, "An initializer"), initializers.push(initializer);5};6}78function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, value) {9var kindStr;1011switch (kind) {12case 1:13kindStr = "accessor";14break;1516case 2:17kindStr = "method";18break;1920case 3:21kindStr = "getter";22break;2324case 4:25kindStr = "setter";26break;2728default:29kindStr = "field";30}3132var get,33set,34ctx = {35kind: kindStr,36name: isPrivate ? "#" + name : name,37"static": isStatic,38"private": isPrivate39},40decoratorFinishedRef = {41v: !142};430 !== kind && (ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef)), 0 === kind ? isPrivate ? (get = desc.get, set = desc.set) : (get = function get() {44return this[name];45}, set = function set(v) {46this[name] = v;47}) : 2 === kind ? get = function get() {48return desc.value;49} : (1 !== kind && 3 !== kind || (get = function get() {50return desc.get.call(this);51}), 1 !== kind && 4 !== kind || (set = function set(v) {52desc.set.call(this, v);53})), ctx.access = get && set ? {54get: get,55set: set56} : get ? {57get: get58} : {59set: set60};6162try {63return dec(value, ctx);64} finally {65decoratorFinishedRef.v = !0;66}67}6869function assertNotFinished(decoratorFinishedRef, fnName) {70if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");71}7273function assertCallable(fn, hint) {74if ("function" != typeof fn) throw new TypeError(hint + " must be a function");75}7677function assertValidReturnValue(kind, value) {78var type = _typeof(value);7980if (1 === kind) {81if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");82void 0 !== value.get && assertCallable(value.get, "accessor.get"), void 0 !== value.set && assertCallable(value.set, "accessor.set"), void 0 !== value.init && assertCallable(value.init, "accessor.init");83} else if ("function" !== type) {84var hint;85throw hint = 0 === kind ? "field" : 10 === kind ? "class" : "method", new TypeError(hint + " decorators must return a function or void 0");86}87}8889function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers) {90var desc,91init,92value,93newValue,94get,95set,96decs = decInfo[0];97if (isPrivate ? desc = 0 === kind || 1 === kind ? {98get: decInfo[3],99set: decInfo[4]100} : 3 === kind ? {101get: decInfo[3]102} : 4 === kind ? {103set: decInfo[3]104} : {105value: decInfo[3]106} : 0 !== kind && (desc = Object.getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {107get: desc.get,108set: desc.set109} : 2 === kind ? value = desc.value : 3 === kind ? value = desc.get : 4 === kind && (value = desc.set), "function" == typeof decs) void 0 !== (newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, value)) && (assertValidReturnValue(kind, newValue), 0 === kind ? init = newValue : 1 === kind ? (init = newValue.init, get = newValue.get || value.get, set = newValue.set || value.set, value = {110get: get,111set: set112}) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {113var newInit;114if (void 0 !== (newValue = memberDec(decs[i], name, desc, initializers, kind, isStatic, isPrivate, value))) assertValidReturnValue(kind, newValue), 0 === kind ? newInit = newValue : 1 === kind ? (newInit = newValue.init, get = newValue.get || value.get, set = newValue.set || value.set, value = {115get: get,116set: set117}) : value = newValue, void 0 !== newInit && (void 0 === init ? init = newInit : "function" == typeof init ? init = [init, newInit] : init.push(newInit));118}119120if (0 === kind || 1 === kind) {121if (void 0 === init) init = function init(instance, _init) {122return _init;123};else if ("function" != typeof init) {124var ownInitializers = init;125126init = function init(instance, _init2) {127for (var value = _init2, i = 0; i < ownInitializers.length; i++) {128value = ownInitializers[i].call(instance, value);129}130131return value;132};133} else {134var originalInitializer = init;135136init = function init(instance, _init3) {137return originalInitializer.call(instance, _init3);138};139}140ret.push(init);141}1421430 !== 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) {144return value.get.call(instance, args);145}), ret.push(function (instance, args) {146return value.set.call(instance, args);147})) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {148return value.call(instance, args);149}) : Object.defineProperty(base, name, desc));150}151152function applyMemberDecs(ret, Class, decInfos) {153for (var protoInitializers, staticInitializers, existingProtoNonFields = new Map(), existingStaticNonFields = new Map(), i = 0; i < decInfos.length; i++) {154var decInfo = decInfos[i];155156if (Array.isArray(decInfo)) {157var base,158initializers,159kind = decInfo[1],160name = decInfo[2],161isPrivate = decInfo.length > 3,162isStatic = kind >= 5;163164if (isStatic ? (base = Class, 0 !== (kind -= 5) && (initializers = staticInitializers = staticInitializers || [])) : (base = Class.prototype, 0 !== kind && (initializers = protoInitializers = protoInitializers || [])), 0 !== kind && !isPrivate) {165var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,166existingKind = existingNonFields.get(name) || 0;167if (!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);168!existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);169}170171applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers);172}173}174175pushInitializers(ret, protoInitializers), pushInitializers(ret, staticInitializers);176}177178function pushInitializers(ret, initializers) {179initializers && ret.push(function (instance) {180for (var i = 0; i < initializers.length; i++) {181initializers[i].call(instance);182}183184return instance;185});186}187188function applyClassDecs(ret, targetClass, classDecs) {189if (classDecs.length > 0) {190for (var initializers = [], newClass = targetClass, name = targetClass.name, i = classDecs.length - 1; i >= 0; i--) {191var decoratorFinishedRef = {192v: !1193};194195try {196var nextNewClass = classDecs[i](newClass, {197kind: "class",198name: name,199addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef)200});201} finally {202decoratorFinishedRef.v = !0;203}204205void 0 !== nextNewClass && (assertValidReturnValue(10, nextNewClass), newClass = nextNewClass);206}207208ret.push(newClass, function () {209for (var i = 0; i < initializers.length; i++) {210initializers[i].call(newClass);211}212});213}214}215216export default function applyDecs2203(targetClass, memberDecs, classDecs) {217var ret = [];218return applyMemberDecs(ret, targetClass, memberDecs), applyClassDecs(ret, targetClass, classDecs), ret;219}220221