isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
28 lines (27 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EXPORTED_METHOD_NAMES_KEY = void 0;
exports.Exported = Exported;
const tstlClass_1 = require("./functions/tstlClass");
exports.EXPORTED_METHOD_NAMES_KEY = "__exportedMethodNames";
/**
* A decorator function that signifies that the decorated class method should be added to the
* `ModUpgraded` object.
*
* This is only meant to be used internally.
*/
function Exported(target, propertyKey) {
// Since the decorator runs prior to instantiation, we only have access to get and set static
// properties, which are located on the "constructor" table.
const constructor = target.constructor;
if (constructor === undefined) {
const tstlClassName = (0, tstlClass_1.getTSTLClassName)(target) ?? "Unknown";
error(`Failed to get the constructor for class "${tstlClassName}". Did you decorate a static method? You can only decorate non-static class methods.`);
}
let exportedMethodNames = constructor[exports.EXPORTED_METHOD_NAMES_KEY];
if (exportedMethodNames === undefined) {
exportedMethodNames = [];
constructor[exports.EXPORTED_METHOD_NAMES_KEY] = exportedMethodNames;
}
exportedMethodNames.push(propertyKey);
}