From d1f7db8cadcd02e61392dbd634b0840337045c8a Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sun, 25 Sep 2022 15:00:10 +0200 Subject: [PATCH] feat(core): Pass shorthand to macros --- packages/core/src/part.mjs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/src/part.mjs b/packages/core/src/part.mjs index e273b4f7a32..bd07037515c 100644 --- a/packages/core/src/part.mjs +++ b/packages/core/src/part.mjs @@ -128,7 +128,6 @@ Part.prototype.shorthand = function () { getId: this.getId, hide: this.hide, log: this.context.store.log, - macro: this.__macroClosure(), paperless, part: this, sa, @@ -209,6 +208,9 @@ Part.prototype.shorthand = function () { set: (absoluteOptions, name, value) => (self.context.settings.absoluteOptions[name] = value), }) + // Macro closure at the end as it includes the shorthand object + shorthand.macro = this.__macroClosure(shorthand) + return shorthand } @@ -332,11 +334,11 @@ Part.prototype.__inject = function (orig) { * @private * @return {function} method - The closured macro method */ -Part.prototype.__macroClosure = function () { - let self = this - let method = function (key, args) { - let macro = utils.__macroName(key) - if (typeof self[macro] === 'function') self[macro](args) +Part.prototype.__macroClosure = function (props) { + const self = this + const method = function (key, args) { + const macro = utils.__macroName(key) + if (typeof self[macro] === 'function') self[macro](args, props) } return method