jseval
Compile time function evaluator for javascript and AST
Examples
Basic Usage
Simple usage for jseval
const evalFunctions = $ { return 'my_id_'+id; } $ { return ; };const src = ` var x = 10; var y = $my_fn(30); var z = $inline(function() { var ary = []; for ( var i = 0; i < 100; ++i ) ary.push( i ); return ary; });`; ;
Async
Async evaluation
const evalFunctions = $ { return Promise
Eval Functions
An eval function is a function to be compiled by jsval. It allows the return of promises to defer its evaluation.
const evalFunctions = $ { return /* some promise that reads the file */; }
Methods
jseval( src, evalFunctions, options )
Source to source evaluation
- src {String}: The string to be evaluated
- evalFunctions {object}: A map of functions to be runned when encountered
- options {object}:
- options.source {string}: If passed, the string will be used as a source filename for sourcemap generation
- options.Promise {object}: The Promise library to be used (must have at least Promise.all, Promise.resolve)
Returns {Promise} A promise with the output string if no source-map is requested. Otherwise an object with code and map properties.
jseval.evalAST( ast, evalFunctions, options )
AST to AST evaluation
- ast {object}: The AST to be evaluated