UNPKG

@alu0101051420/constant-folding

Version:
108 lines (70 loc) 4.06 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Home</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Home</h1> <h3> </h3> <section> <article><p><a href="https://badge.fury.io/js/@alu0101051420%2Fconstant-folding"><img src="https://badge.fury.io/js/@alu0101051420%2Fconstant-folding.svg" alt="npm version"></a> <a href="https://github.com/ULL-ESIT-PL-2122/constant-folding-module-nicolas-cabrera-dominguez-alu0101051420/actions/workflows/nodejs.yml"><img src="https://github.com/ULL-ESIT-PL-2122/constant-folding-module-nicolas-cabrera-dominguez-alu0101051420/actions/workflows/nodejs.yml/badge.svg" alt="CI for constant-folding"></a></p> <h2>constant-folding</h2> <p>Small utility, applies constant-folding in source (javascript) code, using AST modification.</p> <h2>Installation</h2> <pre class="prettyprint source"><code>npm install @alu0101051420/constant-folding </code></pre> <h2>Usage from code:</h2> <pre class="prettyprint source lang-javascript"><code>const constantFolding = require('constant-folding'); const example_code = &quot;a = 3+2;&quot; console.log(&quot;Original Code: \n&quot;, example_code); console.log(&quot;Code with constant folding: \n&quot;, constantFolding(example_code)); </code></pre> <p><a href="https://ull-esit-pl-2122.github.io/constant-folding-module-nicolas-cabrera-dominguez-alu0101051420/">The documentation of the function</a>.</p> <h2>Usage as executable:</h2> <p>An input file must be specified. You also may or may not specify an output file. If not given, it will default to &quot;output.js&quot;.</p> <pre class="prettyprint source"><code>npx cf input_file --o output_file </code></pre> <h2>Examples</h2> <pre class="prettyprint source lang-js"><code>constantFolding(`['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']); `); // ['a','b','c','d','e','f','g','h'] constantFolding(`[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;].join(); `); // a,b,c constantFolding(`[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;].join('&'); `); // a&b&c constantFolding(`[1, 2, 3].length; `); // 3 constantFolding(`[1, 2, 3][2 - 1]; `); // 2 constantFolding(`[1, 2, 3].shift(); `); // 1 constantFolding(`[1, 2, 3].slice(0, 1 + 1); `); // [1, 2] constantFolding(`['a', 'b', 'c'].pop(); `); // c constantFolding(`['a', 'b', 'c'].reverse(); `); // ['c','b','a'] </code></pre> <h2>Author</h2> <p>alu0101051420 (Nicolás Cabrera) - <a href="https://github.com/jncabdom">GitHub Profile</a></p> <h2>Tests</h2> <pre class="prettyprint source"><code>npm run test </code></pre> <h2>Version History</h2> <p>1.0.0 Initial Release</p> <p>1.1.0 Added npx executable</p> <p>1.1.1 Minor documentation fixes</p> <p>1.2.0 Added constant folding for array functions</p></article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#arrayConstantFolding">arrayConstantFolding</a></li><li><a href="global.html#binaryConstantFolding">binaryConstantFolding</a></li><li><a href="global.html#constantFolding">constantFolding</a></li><li><a href="global.html#getValue">getValue</a></li><li><a href="global.html#isConstant">isConstant</a></li><li><a href="global.html#newArrayNode">newArrayNode</a></li><li><a href="global.html#newNode">newNode</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Thu Mar 10 2022 14:45:42 GMT+0000 (Western European Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>