@alu0101353647/constant-folding
Version:
Constant Folding javascript code
47 lines (28 loc) • 1.91 kB
Markdown
[](https://classroom.github.com/a/fzrjycLm)
[](https://classroom.github.com/open-in-codespaces?assignment_repo_id=10589390)
## constant-folding
This is a small library made to fold the constants and similar expressions that
can be folded before runtime. The bulk of the functionalities are bunched up within one function, `constantFolding`, which receives as parameter the code whose constants to fold.
This code goes the extra length with some of the functionalities, despite the author not having time to make the extras in the rubric.
Published in [npm](https://www.npmjs.com/package/@alu0101353647/constant-folding)!
## Installation
```bash
npm install @alu0101353647/constant-folding
```
## Usage as executable:
Within `input.txt` we have lines of code whose constants to fold. The code will dump the better code at `output.txt`.
```bash
cf input.txt output.txt
```
## Usage from code:
```javascript
const constantFolding = require('constant-folding');
console.log(constantFolding(`a=[2*2].concat(3, [5,6], [[4]]);`));
```
[The documentation of the function](https://ull-esit-pl-2021.github.io/constant-folding-module-alu0101353647/).
## Examples
See the tests attached in the [repository](https://github.com/ULL-ESIT-PL-2223/constant-folding-juan_guillermo-zafra-alu0101353647/blob/main/test/test.js)
## Author
alu0101353647, the one and only. Also known as Guillermo Zafra.
## Tests
Every test already within the rubric has been added. Additionally, tests with other binary expressions have been added, as well as a complex test.