From 0a0ac752b9bd07d4e3868a135d79ce88bc009cde Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 3 Aug 2017 22:34:02 +0300 Subject: [PATCH] aliases seem to be done... Signed-off-by: Alex A. Naanou --- actions.js | 44 +++++++++++++++++++++++++++++++++++++------- package.json | 2 +- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/actions.js b/actions.js index d51ce39..ca3a6a8 100755 --- a/actions.js +++ b/actions.js @@ -315,6 +315,8 @@ function(txt){ doc: doc, no_default: no_default, stop_propagation: false, + + code: txt, } } @@ -632,25 +634,41 @@ Action.prototype.chainCall = function(context, inner){ // XXX handle alias args and pass them to the target... // XXX who's parsing and what syntax??? // - args syntax??? +// XXX make this signature compatible with Action... (except for the last arg) var Alias = module.Alias = -function Alias(alias, target){ +function Alias(alias, doc, ldoc, attrs, target){ // we got called without a 'new'... if(this == null || this.constructor !== Alias){ // XXX using something like .apply(.., arguemnts) would be more // generel but have no time to figure out how to pass it // to new without the later complaining... - return new Alias(alias, target) + return new Alias(alias, doc, ldoc, attrs, target) } + // precess args... + var args = doc instanceof Array ? + doc + : [].slice.call(arguments) + .filter(function(e){ return e !== undefined }) + .slice(1) + target = args.pop() + last = args[args.length-1] + attrs = last != null && typeof(last) != typeof('str') ? args.pop() : {} + doc = typeof(args[0]) == typeof('str') ? args.shift() : null + ldoc = typeof(args[0]) == typeof('str') ? args.shift() : null + + attrs.alias = target + var parsed = typeof(target) == typeof('str') ? null : target - var doc = parsed ? parsed.doc : null + + doc = (!doc && parsed) ? parsed.doc : doc // XXX would be good to pre-parse the target... var meth = Action(alias, - // XXX pre-parse the doc if possible... - doc, null, - { alias: target }, + doc, + null, + attrs, function(){ // parse the target... // XXX should we cache here??? @@ -665,6 +683,8 @@ function Alias(alias, target){ }) meth.__proto__ = this.__proto__ + meth.func.alias = target + return meth } // inherit from Action... @@ -997,6 +1017,9 @@ module.MetaActions = { // // .pre or .post, this does not mean that one can // // not define both, just that they are stored separately // pre|post: , + // + // // XXX + // alias: , // }, // ... // ] @@ -1579,7 +1602,14 @@ module.MetaActions = { + (cur.pre.source_tag ? normalizeTabs('// Source tag: ' + cur.pre.source_tag) + p : '') // code... - + normalizeTabs(cur.pre.toString()).replace(/\n/g, p) + //+ normalizeTabs(cur.pre.toString()).replace(/\n/g, p) + + normalizeTabs( + !cur.pre.alias ? + cur.pre.toString() + : typeof(cur.pre.alias) == typeof('str') ? + cur.pre.alias + : cur.pre.alias.code + ).replace(/\n/g, p) + p } diff --git a/package.json b/package.json index 14b6778..eb26681 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-actions", - "version": "3.3.4", + "version": "3.4.0", "description": "", "main": "actions.js", "scripts": {