@alu0101056944/constant-folding
v1.2.2
Published
Constant Folding javascript code
Downloads
3
Maintainers
Readme
constant-folding
Transpile a javascript source code file into a constant folded one. Will transpile the following expressions:
- ["a", "b", "c"].join(); array of only literals (number or string) into "a,b,c";
- [a, b, c].pop(); array of identifiers into c;
- [1, 2, 3].slice(0, 1+1); any array into [1, 2];
Installation
To install execute the following command:
npm i
Usage as executable:
Execute the program with the following command.
npx cf <input.js> -o <output>
where:
- input.js is the path to the original javascript source code to transpile into another source code
- output is the path of the file where save the transpiled source code; the constant folded one.
Usage from code:
const constantFolding = require('constant-folding');
//call the function
The documentation of the function.
Examples
src/examples/input_1.js
[a, b, c].slice(0, 2);
Execute:
npx cf src/input_1.js -o src/output_1.js
Transpiled code:
src/examples/output_1.js
[
a,
b
];
Author
alu0101056944
Marcos Jesús Barrios Lorenzo
Tests
To run the tests execute the following command:
npm test
API
constantFolding(code) ⇒ string
Kind: global function
Returns: string - ouput javascript source code after constant folding.
Brief: Transform code into an AST, apply constant folding and transform it
back into the resultng code.
| Param | Type | Description | | --- | --- | --- | | code | string | input javascript source code. |