addLogging

the function will take a text buffer given by parameter, and generate an Abstract Syntaxt Tree(AST), that will be parsed to find function type nodes('FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression'). After match and after the transformation with addBeforeCode, returns the generated code.

addLogging(code: string, pattern: string): string
Parameters
code (string) The input code to be parsed.
pattern (string = '') Pattern to match the functions name, empty if no pattern was entered(by default).
Returns
string: The return value is the AST transformed into text with the logs already written. The transformation is made in the return line with a function of module 'escodegen': escodegen.generate(ast).

addBeforeCode

Adds right after a function declaration(in a given AST node) a console.log() with the type of function(and name and parameters, if it had) and the line where the function is located.

addBeforeCode(node: object)
Parameters
node (object) Object that represents the node of an Abstract Syntax Tree, containing the type, name, location... and which will be modified to add the logs.