vue-facing-decorator
Version:
Vue typescript class and decorator based component.
39 lines • 1.5 kB
JavaScript
import { obtainSlot } from '../slot';
export const Compatible = {};
export function compatibleClassDecorator(deco) {
return function (cons, ctx) {
var _a;
if (ctx) { //stage 3 arg is constructor, ctx is ClassDecoratorContext
if (ctx.kind !== 'class') {
throw 'deco stage 3 class';
}
const proto = (_a = Compatible.fakePrototype) !== null && _a !== void 0 ? _a : (Compatible.fakePrototype = {});
const slot = obtainSlot(proto);
delete Compatible.fakePrototype;
obtainSlot(cons.prototype, slot);
const ret = deco(cons);
return ret;
}
else { //stage 2 arg is constructor
return deco(cons);
}
};
}
export function compatibleMemberDecorator(deco) {
return function (protoOrValue, nameOrCtx) {
var _a;
if (typeof nameOrCtx === 'object') { //stage 3 arg is value, ctx is ClassMemberDecoratorContext
const ctx = nameOrCtx;
const value = protoOrValue;
const proto = (_a = Compatible.fakePrototype) !== null && _a !== void 0 ? _a : (Compatible.fakePrototype = {});
proto[ctx.name] = value;
return deco(proto, ctx.name);
}
else { //stage 2 arg is prototype, ctx is name stirng
const name = nameOrCtx;
const proto = protoOrValue;
return deco(proto, name);
}
};
}
//# sourceMappingURL=utils.js.map