UNPKG

@adrianepi/constant-folding

Version:
122 lines (71 loc) 2.38 kB
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> ### Table of Contents * [constantFolding][1] * [Parameters][2] * [replaceByLiteral][3] * [Parameters][4] * [replaceByMemberExpression][5] * [Parameters][6] * [replaceByCallExpression][7] * [Parameters][8] * [generateArray][9] * [Parameters][10] * [showProps][11] * [Parameters][12] * [generateOutput][13] * [Parameters][14] ## constantFolding A function that creates the AST of the given code and modifies it for allowing the use of array and strings methods. ### Parameters * `code` **[string][15]** A string with the js program code. * `pattern` **[string][15]** The pattern (other parameters). Returns **[string][15]** Returns a string with the output in AST format or JS format. ## replaceByLiteral Modifies the literal node for computing the operations and apply constant folding. ### Parameters * `node` ## replaceByMemberExpression Modifies the member expression node for allowing use for array and strings methods. ### Parameters * `node` **[Node][16]** The node. ## replaceByCallExpression Modifies the call expression node for allowing use for array and strings methods. ### Parameters * `node` **[Node][16]** The node. ## generateArray Receives a node and generates an array from the elements of that node. ### Parameters * `node` **[Node][16]** The node. Returns **[Array][17]** Array with the elements of the node. ## showProps Shows the properties of the given object. ### Parameters * `obj` * `objName` ## generateOutput Modifies the JS output for printing it in one line and without many spaces. ### Parameters * `code` **[string][15]** The code Returns **[string][15]** The output with better format. [1]: #constantfolding [2]: #parameters [3]: #replacebyliteral [4]: #parameters-1 [5]: #replacebymemberexpression [6]: #parameters-2 [7]: #replacebycallexpression [8]: #parameters-3 [9]: #generatearray [10]: #parameters-4 [11]: #showprops [12]: #parameters-5 [13]: #generateoutput [14]: #parameters-6 [15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [16]: https://developer.mozilla.org/docs/Web/API/Node/nextSibling [17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array