Current collected state Current
Observed since 20 Oct, 22:15 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@0ria/constant-folding
Constant Folding javascript code
0ria - alu0101027340
npm install @0ria/constant-folding
Default output:
npx cf inputFile.js
Desired output:
npx xf inputFile.js -o outputFile.js
const constantFolding = require('constant-folding');
const code = "[1, 2, 3].length"
console.log('Code after constant folding' + constantFolding(code));
The documentation of the function.
inputs:
['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']);
["a", "b", "c"].join();
["a", "b", "c"].join('&');
[1, 2, 3].length;
[1, 2, 3][2 - 1];
[1, 2, 3].shift();
[1, 2, 3].slice(0, 1 + 1);
['a', 'b', 'c'].pop();
['a', 'b', 'c'].reverse();
outputs:
a, b, c, d, e, f, g, h;
a, b, c;
a & b & c;
3;
2;
1;
1, 2;
c;
c, b, a;
To run the tests create a directory test with a script containing tests and run npm test
const constantFolding = require('@0ria/constant-folding');
require("chai").should();
const checks = [
{ input: "['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']);", result: "a, b, c, d, e, f, g, h;"},
{ input: '["a", "b", "c"].join();', result: "a, b, c;"},
{ input: '["a", "b", "c"].join("&");', result: "a & b & c;"},
{ input: '[1, 2, 3].length;', result: "3;"},
{ input: '[1, 2, 3][2 - 1]', result: "2;"},
{ input: '[1, 2, 3].shift();', result: "1;"},
{ input: '[1, 2, 3].slice(0, 1 + 1);', result: "1, 2;"},
{ input: '["a", "b", "c"].pop();', result: "c;"},
{ input: '["a", "b", "c"].reverse();', result: "c, b, a;"},
{ input: '[7, 2*3, 9/3].reverse()', result: "3, 6, 7;"},
{ input: 'a = 2*3*4', result: 'a = 24;'}
];
describe("Testing constant folding operations", () => {
for (let c of checks) {
it(`Test ${c.input} = ${c.result}`, () => {
constantFolding(c.input).should.equal(c.result);
})
}
})
Test output:
Testing constant folding operations
✔ Test ['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']); = a, b, c, d, e, f, g, h;
✔ Test ["a", "b", "c"].join(); = a, b, c;
✔ Test ["a", "b", "c"].join("&"); = a & b & c;
✔ Test [1, 2, 3].length; = 3;
✔ Test [1, 2, 3][2 - 1] = 2;
✔ Test [1, 2, 3].shift(); = 1;
✔ Test [1, 2, 3].slice(0, 1 + 1); = 1, 2;
✔ Test ["a", "b", "c"].pop(); = c;
✔ Test ["a", "b", "c"].reverse(); = c, b, a;
✔ Test [7, 2*3, 9/3].reverse() = 3, 6, 7;
✔ Test a = 2*3*4 = a = 24;
11 passing (45ms)
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
commanderEnvironment{
"local_name": "commander",
"alias": false,
"peer_metadata": null
} | ^7.1.0 | runtime |
escodegenEnvironment{
"local_name": "escodegen",
"alias": false,
"peer_metadata": null
} | ^1.14.3 | runtime |
espreeEnvironment{
"local_name": "espree",
"alias": false,
"peer_metadata": null
} | ^9.3.1 | runtime |
chaiEnvironment{
"local_name": "chai",
"alias": false,
"peer_metadata": null
} | latest | development |
jisonEnvironment{
"local_name": "jison",
"alias": false,
"peer_metadata": null
} | latest | development |
mochaEnvironment{
"local_name": "mocha",
"alias": false,
"peer_metadata": null
} | latest | development |
nycEnvironment{
"local_name": "nyc",
"alias": false,
"peer_metadata": null
} | latest | development |
Source distribution
{
"integrity": "sha512-nnOE9IZFnHK8XVHZ5qcUwkL8u0S9I5ET03CcG2A5zlHFZKwqBfgQil2gc/phlhvwdL0bil8klqnO1TwJoKJOpA==",
"shasum": "b53e2e446369e75fa4c5dcf8895ba5b483749aef",
"tarball": "https://registry.npmjs.org/@0ria/constant-folding/-/constant-folding-1.0.0.tgz",
"fileCount": 11,
"unpackedSize": 8178,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiKf7xACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrpEA//bOYEuie/myNSWwoLxLHOWZ/+tInV1mwk55qwyEfNsyBj0EWM\r\nCNLRC4S9U2tKu2hzV2VMy6n9go6B7NtNVsAp266t4t+lSsbUka/b4XslpTeR\r\nhHZGSFJdF47rt6eQjr21A8u7OwL76rKRleSO9dOis2xK/mmo6FifK7azgEge\r\n7oFbz6zYA23ihFGGCpMGFNLd25NN8edeu1kJjBHvgx8fVXEXiqenMB9zV7QQ\r\n1kWexKX6g/zEZjIjyKKlVV0EcBQZ6ItHlHTRV/v5DrQ3POR7eKy683INHbGq\r\nbHkrGIUbUVJaOmr5Uc4Uegtpq62KztEAAhhePLoa4iUl9qw2s8OWiO/EACyP\r\nzE6AEh08sMx8UryXXSjVi2wPWJN0kw+kyJNhq1amz9haTANWKdxoWZ4K3mYI\r\nsiwnBkBw5XjhEmbmddRtkuPSG0Jxh4Z00l5arKv8IlNySqdxs8owSedRUUbb\r\nW6B06osJa+cmLOCYTh22rfvHicuWZSSIPI4OeUMD5Z/+9V870cD9CqQ+KHRU\r\nJVL3kUQUsYBwi5r+rn6jWWj0mB86K1L3pBIW/+aj7ZtjLDz4TcMMGYASe12y\r\nKlSJSo8MOXHOv4vOg6VXkwGUcPHDhJqe9hH0mOyKLkpdQOHuDSHgEKtv8OOX\r\ngfaX681JPMfT04wUnNMfW7rt6QdkR7mwjzY=\r\n=eKOJ\r\n-----END PGP SIGNATURE-----\r\n",
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEQCIEd21jUax4fJVI+dkAGXx74Ge/Pbyk/dM3ZkyYbvr8+YAiBkvgBeOlydZtnJayGVIIRtsumF3iAK1GyKq707b+WfSA=="
}
]
}Shared repository data · GitHub
Shared repository data · GitHub
Observed since 20 Oct, 22:15 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:bfbb91c9b092737ae5c927f91fcb4c3f9a25312b70e9b7e7e81bea154ae2f072