Thursday, 29 August 2019

Use webpack or node.js compiler to wrap all functions and methods

The technology for this must be available I'm just not sure how to hook it up. This is not intended to use in production, so I understand the effect it will have on performance, this mostly just an idea about debugging I'm working through. This would be for all or some files in a project, not just a single file.

I want to:

  1. Use a precompiler, like webpack or grunt, I don't want it in the actual files.
  2. Locate all functions/methods. (Prototypes methods would be nice as well)
  3. Wrap these functions with a simple function.

A simple example would be:

INPUT:

const obj = {
    func: function(){return 'obj.Func'}
};

function B(a,b,c){
    const innerFunc = (e,f,g)=>{
        return 'innerFunc'
    };
    return
}

---- Runs through complier ---

OUTPUT:

    const wrapper = (arguments,cb)=>{
        // Spread arguments etc.
        // this is pseudo code but you get the idea
        console.log('Hey this function ran!')
        return cb(arguments[0],arguments[1],arguments[2]);
    }

    const obj = {
        func: function(){return wrapper(arguments,()=>{ return 'obj.Func'})}
    };

    function B(a,b,c){
        return wrapper(arguments,(a,b,c)=>{
            const innerFunc = (e,f,g)=>{
                return wrapper(arguments,(e,f,g)=>{
                    return 'innerFunc
                });
            };
        });
    }

I'm just not quite sure where to look to try to do this. I guessing that Babel already identifies everything like this, as well as eslint etc.



from Use webpack or node.js compiler to wrap all functions and methods

No comments:

Post a Comment