@alu0101325583/constant-folding
v1.1.4
Published
Constant Folding javascript code
Downloads
13
Maintainers
Readme
constant-folding
Installation
npm install @alu0101325583/constant-folding
Usage as executable:
cf input.js output.js
Usage from code:
const constantFolding = require('constant-folding');
//call the function
The documentation of the function.
Examples
let refactored = constantFolding(input);
Author
alu0101325583 Juan García Santos
Tests
npm test
API
Table of Contents
constantFolding
A function that given a certain code, builds its ast tree. Then, traverses through it, applaying constant folding on valid nodes
Parameters
code
string A string that contains the input code generates the ast from the code, applys constant folding then generates code using the ast and escodegen.
Returns string Returns the simplified code
replaceByLiteral
A function that converts a given subtree known to be constant into a simplified literal node
Parameters
n
Node the root node of the subtree evaluates the subtree and transforms it into a simplified literal node.