{"_id":"@alu0101244488/ast-types","_rev":"3-8442ca5b98d3ff6b9272a6a74fa6c67e","name":"@alu0101244488/ast-types","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@alu0101244488/ast-types","version":"1.0.0","description":"Package for the translation of the spread operator to older ecma standards","main":"index.js","authors":{"name":"Aram Pérez Dios","email":"alu0101244488@ull.edu.es"},"repository":{"type":"git","url":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488.git/@alu0101244488/ast-types"},"scripts":{"test":"mocha","cov":"nyc npm run test","dev":"vuepress dev docs","build":"vuepress build docs","jsdoc":"vuepress-jsdoc src"},"bin":{"cf":"bin/ast-types-cli.js"},"license":"MIT","devDependencies":{"vuepress":"^1.5.3","vuepress-jsdoc":"^4.3.0"},"dependencies":{"chai":"^4.3.6","escodegen":"^2.0.0","espree":"^9.3.1","mocha":"^9.2.2"},"_id":"@alu0101244488/ast-types@1.0.0","_nodeVersion":"17.5.0","_npmVersion":"8.4.1","dist":{"integrity":"sha512-lN8jD10aAiEayixjhU3gzEYj7sMSsdTRyLBqqxVPoDOddlU5oolO0Pmkdc7PreQy3ya6oRJqky0bHSHyJZiIDA==","shasum":"5787a80ee2ae90bc1678c8bd5f144579c4640c57","tarball":"https://registry.npmjs.org/@alu0101244488/ast-types/-/ast-types-1.0.0.tgz","fileCount":21,"unpackedSize":15592,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiNE/4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpR4BAAmft10IwFWhXiohYczZdbY+qykuyw7TYPrj1JbJPQglgWvn6Q\r\nMnqrnWMm2LnkLELX9Xf/C9c2Zs/7jxRCE2sbmlwyJ1pzN4Izt9BqPrbbLd1C\r\nJQVzrmtteZgX3VvBCRarwt+aKoqSdpICeheUE7JF/kc7/+Rl6QgbHc4pd4/e\r\nqAPkggZNAYYFqfsufOLHyxOuJHMPTAVgK7FPG6eCObIAxChTofqRB1Aba5fL\r\nbZdUQ4WTKfAqE8/PmDFIuUrIk6akTy2DCthQGUmq+Jk+K3NbmVAXCAUmArg3\r\neeqtuv5vzMvkcW+1VkPkPckQI6Q/wbBWJYJDWNf7dJGnZYb2bvPMwCaMtAyB\r\n2QPVIEtoOBZkZ/S+//q+rZY1MWo3fymMzTftZj9f4yKlzp4T+s1HjIxTj6+M\r\nU9D+0v0JSjvuXtDaSRzg0xljycXbO3wjYJyeIcEnqkmODQnqwX2kQwsNWJEZ\r\nMcITZ1/EDYM3e3gYPC/LkGZR84M5RFo7vhJO+djWLM15sCEXh+7uDX3jzLRd\r\n2vW5Q7ZrHY1fOrGlBVVHwEmxlwpvc9v6J9swVl0ttYg4/+XryFhOy1fiVa9F\r\nWYHlSvR2VbuDSksbZaLQx+zoDg7u4bBeTtx62sTD67HucrZxz5H9oHwf6xqe\r\nrmdUN2DxxngQQVxc9cj7rsHmDjHKLJtj1qM=\r\n=QhY6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCcj1XKeQrkcFLZZnzC1quQGdrFc5bvNjpr3beHM2aJ1QIgUR5hj9p0BJiCog5qMg8B0SIekKfT1Jh3LDk/AwIee4k="}]},"_npmUser":{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ast-types_1.0.0_1647595512284_0.6249338828826412"},"_hasShrinkwrap":false},"1.1.0":{"name":"@alu0101244488/ast-types","version":"1.1.0","description":"Package for the translation of the spread operator to older ecma standards","main":"index.js","authors":{"name":"Aram Pérez Dios","email":"alu0101244488@ull.edu.es"},"repository":{"type":"git","url":"git+ssh://git@github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488.git"},"scripts":{"test":"mocha","cov":"nyc npm run test","dev":"vuepress dev docs","build":"vuepress build docs","jsdoc":"vuepress-jsdoc src","doc":"npx nyc --reporter=html --reporter=text --report-dir docs mocha"},"bin":{"so":"bin/ast-types-cli.js"},"license":"MIT","devDependencies":{"vuepress":"^1.5.3","vuepress-jsdoc":"^4.3.0"},"dependencies":{"chai":"^4.3.6","commander":"^9.1.0","documentation":"^13.2.5","escodegen":"^2.0.0","espree":"^9.3.1","mocha":"^9.2.2","nyc":"^15.1.0"},"gitHead":"85ca222e1aa7972bebc2fa4090419a3b3915c7e1","bugs":{"url":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488/issues"},"homepage":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488#readme","_id":"@alu0101244488/ast-types@1.1.0","_nodeVersion":"17.5.0","_npmVersion":"8.4.1","dist":{"integrity":"sha512-3wHkmryj7exNmefx7Ab2EqDXSTcMO00Sjqmdx3aBl+RTOKr2+teA8rS/177/JiRp9YTwRcaKg2LLgiyyqZ62+Q==","shasum":"6b67780d9ade359724e9e14e1e67af3a8cc72267","tarball":"https://registry.npmjs.org/@alu0101244488/ast-types/-/ast-types-1.1.0.tgz","fileCount":24,"unpackedSize":19253,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiNF8QACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrWFw/5AeV5Q0u1WyVb4asgOskVUpHqfz2MgDN2aule4bCZ/fKiL49I\r\nKmuaXWjqg/jgMQ/CQ6KGrEE4Hh9c1Ez7QoRelhHusJiBQnPrcsPVRCk7T37H\r\nofH5uI50Fshz5ZySnQI4NWerE3RYUjj8/D2ZR0miK9aRyNEhS8aVloOVN8TB\r\n3kRY2aFHxpmYlA2GbSofYzT3ZrQLZqKwfj3kFU+OcsO2OvzcZPrICFc5UwgD\r\ngUIqitEenXov/6W978WFU3AxAT5g673Sfei45Sp94tg8asrdhCuQpVAtOJQo\r\n43y6KQQcXS3CTOYNm/YtAwkxuGuzkjFoM5Z1WC5LJBzmlxQjipSz5vxrMoVq\r\nrbtZ4WB+PY11lgvs4n5iXAq/GhF064c5qBW0oJrFsZDIYvOQekCfiMRiKfSB\r\n+dGg26KoZZrVszjOmI0yVv86EOtZk6RF1XCZVzshRhScbslhWgauEMDjJyTa\r\nlU9RZtBOgVInIyKYymXk4EVx6r1qg8EJhk4VFLhTeS8cslzvswu3+E/rYevk\r\nsb5w1sDdgTqE8mALvPv93BAKqMEXLAqrA2sf6qwhGIu7x/XcPooPY6bu58Ge\r\nG/c0ACAZAdKUEKs39KHgKtMB2QlQjuqL+9Fw9gf9BA3+5Qglr+67k0sIjZh6\r\nVTAo8SZ98v+hsallBxBOXafwY3z2/cHPkH4=\r\n=AEpD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCScZHPJLNbGWdehZBOXFEKqB1u2nrImNmtLW+/UwYTPAIgCxVQ+eav3DygNV2ghWJ+GnkaSbUCEfatttcRczAWH3I="}]},"_npmUser":{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ast-types_1.1.0_1647599376566_0.6912903620365105"},"_hasShrinkwrap":false},"1.1.1":{"name":"@alu0101244488/ast-types","version":"1.1.1","description":"Package for the translation of the spread operator to older ecma standards","main":"index.js","authors":{"name":"Aram Pérez Dios","email":"alu0101244488@ull.edu.es"},"repository":{"type":"git","url":"git+ssh://git@github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488.git"},"scripts":{"test":"mocha","cov":"nyc npm run test","dev":"vuepress dev docs","build":"vuepress build docs","jsdoc":"vuepress-jsdoc src","doc":"npx nyc --reporter=html --reporter=text --report-dir docs mocha"},"bin":{"so":"bin/ast-types-cli.js"},"license":"MIT","devDependencies":{"vuepress":"^1.5.3","vuepress-jsdoc":"^4.3.0"},"dependencies":{"chai":"^4.3.6","commander":"^9.1.0","documentation":"^13.2.5","escodegen":"^2.0.0","espree":"^9.3.1","mocha":"^9.2.2","nyc":"^15.1.0"},"gitHead":"954a38804ff22a9c1d2b1d7b9cf1f3806d6b52c9","bugs":{"url":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488/issues"},"homepage":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488#readme","_id":"@alu0101244488/ast-types@1.1.1","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-/5CkpXsFl3VB7y5+xZLBw/PUmE2UmTUD9Uu6OK3jioOeYstNvCJ507xoAWycQ1D6Mx7/cHRdLVwoL+bThdar5Q==","shasum":"8a35e4cb263b6ffe6a27f97287bb53a76914fa1f","tarball":"https://registry.npmjs.org/@alu0101244488/ast-types/-/ast-types-1.1.1.tgz","fileCount":59,"unpackedSize":452862,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiNGZ2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrmog/+PS2L1jIl1++eoq8Y8OxFMRo+eR4Ur/KHxRmrP/PKK4nPZ+eJ\r\nALaTHyHL2KTjC9KmiiYAK1HF7BzcDz+rXkPoIGYpYjjK08CbZY7VxQWCs1/M\r\n8K1RXn1AJDAU3ukE3kvAyzPnjnvDNBSBmtfxePES0knFEd6Z+ZUTK4rCVZXJ\r\nyNQbdsZ1PYmX6yaQFvXZE0mNYdXeiy7VX566n3woq206Ht2w1tOnuvjZA/zT\r\nRNTblQGM9CuOwgVXmOjf0VRAkhYNMcm/A21MOrzh5buFDrQdfcL1Ezki5Rud\r\nU/iDCE1Fn9IY93T4wyKUjUC6MGkGxkA6ch95CfgYCNTwBvuYt4WGYfbFodiA\r\nBXLH3BRZFUlCt3IuhiisV693ClubUTyGop2jh2k/e9aXFRC//a0kUSbbcG3F\r\niSXx1M3QVW8Om2MbOafgMS3VCpdVTMi5kEAQLkFNHiYodSpWfvXkxn3BXbRd\r\naENV5lAugkbH+eP7NdtUApE9Al1pHuoB8xJRODmKf/m9/DffUfFYpKy71EBY\r\n6iU1gYhVbPaRm6crMAQM7jZwlOhxtzSp+/cTi6sk+KfoDeIFFAwAdnULH0ki\r\njoP3zcPzXyAJjSxdDj7wpVuNxGjtl8VNkQInT+na5P+HztwK3ZMppLZhLO1K\r\nNkOfVVhtv8Zj02k9/bq9C9dL0p9Ber8mbw4=\r\n=vob/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBeuKzjkYYWyDscF97JMNKLZ5Xi0+RY2008KKp7reYnhAiEA5MVqjR4ArWCsESgtzTm2IDIsaQMvRVt14YEmb4SBQz4="}]},"_npmUser":{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"},"directories":{},"maintainers":[{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ast-types_1.1.1_1647601270553_0.3018966345515266"},"_hasShrinkwrap":false}},"time":{"created":"2022-03-18T09:25:12.231Z","1.0.0":"2022-03-18T09:25:12.452Z","modified":"2022-04-04T13:41:10.505Z","1.1.0":"2022-03-18T10:29:36.684Z","1.1.1":"2022-03-18T11:01:10.680Z"},"maintainers":[{"name":"alu0101244488","email":"alu0101244488@ull.edu.es"}],"description":"Package for the translation of the spread operator to older ecma standards","repository":{"type":"git","url":"git+ssh://git@github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488.git"},"license":"MIT","readme":"# AST-Types\n\n## Installation\n\nFor installation it is only required to use the next command:\n\n```\nnpm install @alu0101244488/ast-types\n```\n\nYou can see the npm package on the following link:\n\n[https://www.npmjs.com/package/@alu0101244488/ast-types](https://www.npmjs.com/package/@alu0101244488/ast-types)\n\n\n## Usage as executable:\n\nTo execute you can use the following command where `[inputFile]` is the file with the javasctipt code to compute and `[outputFile]` is the file to print the corresponding code with the transformations applied. Note is that the `-o [outputFile]` or `--output [outputFile]` is optional and the resulting code will be displayed on terminal in any case (a test file is given to try).\n\n```\ncf [inputFile] -o [outputFile]\n```\n\nOther options suported are `-h` or `--help`, and `-V` or `--version` which shows all the corresponding information or the version of the package correspondingly.\n\nExample of the execution. You can see more details about the result of the execution in the **Examples** section.\n\n\n## Usage from code:\n\nThe source file containis a function `spreadOperatorTranspile()` which is exported. This function needs a string o code as a parameter. This string should contain a javascript code and depending if its a **restElement** or a **spreadElement** it acts accordingly.\n\n### Functions implemented to to apply the constant folding:\n\n* **constaSpreadOperatorTranspile()**\n\n```js\n/**\n * @desc Function that translates the spread operator from\n * \t\t\t the ecma6 standard to older standards by removing it\n * \t\t\t and changing it with its correspondenting expression.\n * @param {string} code input code\n * @returns {string} resulting code\n */\nfunction spreadOperatorTranspile (code) {\n  ...\n}\n\n```\n\n* **replaceRestElement**\n\n```js\n/**\n * @desc Auxiliary function to the sreadOperator function that \n * \t\t\t in the case of an restElement node, remplaces it with \n * \t\t\t its correspondenting code\n * @param {node o path} node AST node of the ast to be modified\n * @param {nodeo path} parent AST parent node needed to modify\n */\nfunction replaceRestElement(node, parent) {\n  ...\n}\n```\n\n* **replaceSpreadElement**\n\n```js\n/**\n * @desc Auxiliary function to the sreadOperator function that \n * \t\t\t in the case of an spreadElement node, remplaces it with \n * \t\t\t its correspondenting code\n * @param {node o path} node AST node of the ast to be modified\n * @param {nodeo path} parent AST parent node needed to modify\n */\nfunction replaceSpreadElement(node, parent) {\n  ...\n}\n```\n\n## Deprecated verisions\n\nTwo versions were tried before. Both using the **ast-types** package. But it was easier to do this work using the **estraverse** package.\n\n* **deprecated version 1**\n\nThis first version using the library can only translate the rest element from a function with two parameters, one of which is the rest element.\nIt cannot read multiple sentences. It only reads function declarations statemets.\n\n```js\nimport { parse } from \"espree\";\nimport { NodePath } from \"ast-types\";\nimport { namedTypes as n, builders as b, visit } from \"ast-types\";\nimport recast from \"recast\";\nimport * as espree from  \"espree\";\n\n'use strict';\n\nfunction spreadOperator(code) {\n\n\tlet programPath = new NodePath(parse(code, { ecmaVersion: 6, loc: false }));\n\tlet functionDeclaration = programPath.get(\"body\", 0);\n\n\tlet paramsLength = functionDeclaration.value.params.length;\n\tlet varId = functionDeclaration.value.params[paramsLength - 1].argument.name;\n\tlet lineToAdd = `let ${varId} = Array.prototype.slice.call(arguments, 1);`;\n\tlet newNode = espree.parse(lineToAdd, {ecmaVersion: 6, loc: false}).body[0];\n\tdelete(functionDeclaration.value.params[paramsLength - 1]);\n\tfunctionDeclaration.value.params = [functionDeclaration.value.params[0]];\n\t\n\tfunctionDeclaration.value.body.body.unshift(newNode)\n\t\n\tconst resultCode = recast.print(programPath).code;\n\n\treturn resultCode;\n\n}\n```\n\n* **deprecated version 2**\n\nThis second version as the irst one, can only translate rest elements.But in this case it visits all the nodes in the AST so it accepts multiple sentences and other things like nested functions declarations.\n\n```js\nimport { parse } from \"espree\";\nimport { NodePath } from \"ast-types\";\nimport { namedTypes as n, builders as b, visit } from \"ast-types\";\nimport recast from \"recast\";\nimport * as espree from  \"espree\";\n\n'use strict';\n\nfunction spreadOperator(code) {\n  let ast = espree.parse(code, {ecmaVersion: 7, loc: false});\n\n\n  let sliceExpr = b.memberExpression(\n    b.memberExpression(            \n      b.memberExpression(        \n        b.identifier(\"Array\"),    \n        b.identifier(\"prototype\"), \n        false\n      ),\n      b.identifier(\"slice\"),       \n      false\n    ),\n    b.identifier(\"call\"),     \n    false\n  );\n\n  visit(ast, {\n    visitFunction(path) {\n      const node = path.node;\n      this.traverse(path);\n\n      let lastArg = node.params.pop(); // Remove the 'rest' parameter\n      if (lastArg.type !== \"RestElement\") return;\n      \n      // For the purposes of this example, we won't worry about functions\n      // with Expression bodies.\n      n.BlockStatement.assert(node.body);\n\n      //   var rest = Array.prototype.slice.call(arguments, n);\n      const restVarDecl = b.variableDeclaration(\"var\", [\n        b.variableDeclarator(\n          lastArg.argument,\n          b.callExpression(sliceExpr, [\n            b.identifier(\"arguments\"),\n            b.literal(node.params.length)\n          ])\n        )\n      ]);\n    \n      // Insert the statement 'var rest = Array.prototype.slice.call(arguments, n);' \n      // at the beginning of the body\n      path.get(\"body\", \"body\").unshift(restVarDecl);\n      \n    }\n  });\n\n  return recast.print(ast).code;\n}\n```\n\n\n## Examples\n\nHere is an example of the execution of a very simple code where we to translate first a rest element from a function and then another exmple with the translation of an spread element in an array. These are the cases that this code can translate.\n\n* Example for rest element:\n\nInput file:\n```js\nvar y = 1;\nfunction sum(x, y, z, ...rest) {\n  let b = x + y + z + rest[0];\n  return b * rest[1];\n}\n```\n\nOutput:\n```js\nvar y = 1;\nfunction sum(x, y, z) {\n    var rest = Array.prototype.slice.call(arguments, 3);\n    let b = x + y + z + rest[0];\n    return b * rest[1];\n}\n```\n\n* Example for spread element:\n\nInput file:\n```js\nlet parts = ['shoulders', 'knees'];\nlet lyrics = ['head', ...parts, 'and', 'toes'];\n```\n\nOutput:\n```js\nlet parts = [\n    'shoulders',\n    'knees'\n];\nlet lyrics = [].concat(['head'], parts, ['and'], ['toes']);\n```\n\n## Author\n\nAram Pérez Dios alu0101244488\n","readmeFilename":"README.md","homepage":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488#readme","bugs":{"url":"https://github.com/ULL-ESIT-PL-2122/ast-types-aram-perez-dios-alu0101244488/issues"}}