From 46bb65e441c0673ab50e31d224e1502b74c266f3 Mon Sep 17 00:00:00 2001 From: Ben Baryo <60312583+BenBaryoPX@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:36:14 +0300 Subject: [PATCH] Refactor flAST to ESM, Refactor Tests to Node's Test Runner (#28) - Update dependencies - Refactor code to ESM - Replace custom test runner with Node's builting test runner - Add more tests to increase coverage - Add coverage report using npm run test:coverage - Fix Husky's pre-commit hook --- .eslintignore | 2 - .eslintrc.js | 39 -- .github/workflows/node.js.yml | 4 +- .husky/pre-commit | 4 +- README.md | 10 +- eslint.config.js | 43 +++ package-lock.json | 677 ++++++++++++---------------------- package.json | 14 +- src/arborist.js | 4 +- src/flast.js | 10 +- src/index.js | 10 +- src/types.js | 4 +- src/utils/applyIteratively.js | 10 +- src/utils/index.js | 8 +- src/utils/logger.js | 4 +- src/utils/treeModifier.js | 2 +- tests/aboristTests.js | 155 -------- tests/arborist.test.js | 114 ++++++ tests/functionality.test.js | 118 ++++++ tests/functionalityTests.js | 161 -------- tests/parsing.test.js | 48 +++ tests/parsingTests.js | 68 ---- tests/tester.js | 31 -- tests/utils.test.js | 82 ++++ tests/utilsTests.js | 32 -- 25 files changed, 689 insertions(+), 965 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.js mode change 100755 => 100644 .husky/pre-commit create mode 100644 eslint.config.js delete mode 100644 tests/aboristTests.js create mode 100644 tests/arborist.test.js create mode 100644 tests/functionality.test.js delete mode 100644 tests/functionalityTests.js create mode 100644 tests/parsing.test.js delete mode 100644 tests/parsingTests.js delete mode 100644 tests/tester.js create mode 100644 tests/utils.test.js delete mode 100644 tests/utilsTests.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 48fe356..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -*tmp*/ -*tmp*.* \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 2b0d438..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = { - env: { - browser: true, - node: true, - commonjs: true, - es2021: true, - }, - extends: 'eslint:recommended', - parserOptions: { - ecmaVersion: 'latest', - }, - rules: { - indent: [ - 'error', - 'tab', - { - SwitchCase: 1 - }, - ], - 'linebreak-style': [ - 'error', - 'unix', - ], - quotes: [ - 'error', - 'single', - { - allowTemplateLiterals: true - }, - ], - semi: [ - 'error', - 'always', - ], - 'no-empty': [ - 'off', - ], - }, -}; diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8a1bb63..34140d2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: @@ -27,4 +27,4 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' - run: npm install - - run: npm test + - run: npm run test:coverage diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100755 new mode 100644 index e2b535e..66fdc92 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,2 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - +npm test npx eslint . \ No newline at end of file diff --git a/README.md b/README.md index 3a91391..45fc263 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ npm install flast ``` ### Clone The Repo -Requires Node 16 or newer. +Requires Node 18 or newer. ```bash git clone git@github.com:PerimeterX/flast.git cd flast @@ -165,7 +165,7 @@ const tree = [ ### flAST ```javascript -const {generateFlatAST, generateCode} = require('flast'); +import {generateFlatAST, generateCode} from 'flast'; const ast = generateFlatAST(`console.log('flAST')`); const reconstructedCode = generateCode(ast[0]); // rebuild from root node ``` @@ -197,7 +197,7 @@ const generateCodeDefaultOptions = { ### Arborist ```javascript -const {generateFlatAST, generateCode, Arborist} = require('flast'); +import {generateFlatAST, generateCode, Arborist} from 'flast'; const ast = generateFlatAST(`console.log('Hello' + ' ' + 'there!');`); const replacements = { 'Hello': 'General', @@ -213,8 +213,8 @@ ast.filter(n => n.type === 'Literal' && replacements[n.value]).forEach(n => arbo const numberOfChangesMade = arborist.applyChanges(); console.log(generateCode(arborist.ast[0])); // console.log('General' + ' ' + 'Kenobi'); ``` -The Arborist can be called with an extra argument - logFunc - which can be used to log -inside the arborist. +The Arborist can be called with an extra argument - logFunc - which can be used to override the log +function inside the arborist. ## How to Contribute To contribute to this project see our [contribution guide](CONTRIBUTING.md) \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..39fdd00 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,43 @@ +import globals from "globals"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import js from "@eslint/js"; +import { FlatCompat } from "@eslint/eslintrc"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all +}); + +export default [{ + ignores: ["**/*tmp*/", "**/*tmp*.*", "eslint.config.js", "node_modules/"], +}, ...compat.extends("eslint:recommended"), { + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + ...globals.commonjs, + }, + + ecmaVersion: "latest", + sourceType: "module", + }, + + rules: { + indent: ["error", "tab", { + SwitchCase: 1, + }], + + "linebreak-style": ["error", "unix"], + + quotes: ["error", "single", { + allowTemplateLiterals: true, + }], + + semi: ["error", "always"], + "no-empty": ["off"], + }, +}]; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 315e3b0..172d4c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,22 +10,13 @@ "license": "MIT", "dependencies": { "escodegen": "^2.1.0", - "eslint-scope": "^8.0.1", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "espree": "^10.2.0", "estraverse": "^5.3.0" }, "devDependencies": { - "eslint": "^8.49.0", - "husky": "^8.0.3" - } - }, - "node_modules/@aashutoshrathi/word-wrap": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", - "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", - "dev": true, - "engines": { - "node": ">=0.10.0" + "eslint": "^9.12.0", + "husky": "^9.1.6" } }, "node_modules/@eslint-community/eslint-utils": { @@ -33,6 +24,7 @@ "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", "dev": true, + "license": "MIT", "dependencies": { "eslint-visitor-keys": "^3.3.0" }, @@ -43,26 +35,65 @@ "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/@eslint-community/regexpp": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.8.0.tgz", - "integrity": "sha512-JylOEEzDiOryeUnFbQz+oViCXS0KsvR1mvHkoMiu5+UiBvy+RYX7tzlIIIEstF/gVa2tj9AQXk3dgnxv6KxhFg==", + "version": "4.11.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.1.tgz", + "integrity": "sha512-m4DVN9ZqskZoLU5GlWZadwDnYo3vAEydiUayB9widCl9ffWx2IvPnp6n3on5rJmziJSw9Bv+Z3ChDVdMwXCY8Q==", "dev": true, + "license": "MIT", "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, + "node_modules/@eslint/config-array": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", + "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/object-schema": "^2.1.4", + "debug": "^4.3.1", + "minimatch": "^3.1.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/core": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.6.0.tgz", + "integrity": "sha512-8I2Q8ykA4J0x0o7cg67FPVnehcqWTBehu/lmY+bolPFHGjh49YzGBMXTvpqVgEbBdvNCSxj6iFgiIyHzf03lzg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/eslintrc": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", - "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", + "integrity": "sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==", "dev": true, "license": "MIT", "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.6.0", - "globals": "^13.19.0", + "espree": "^10.0.1", + "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", @@ -70,54 +101,67 @@ "strip-json-comments": "^3.1.1" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" } }, - "node_modules/@eslint/eslintrc/node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "node_modules/@eslint/js": { + "version": "9.12.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.12.0.tgz", + "integrity": "sha512-eohesHH8WFRUprDNyEREgqP6beG6htMeUYeCpkEgBCieCMme5r9zFWjzAJp//9S+Kub4rqE+jXe9Cp1a7IYIIA==", "dev": true, - "license": "BSD-2-Clause", + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", + "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/plugin-kit": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", + "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", + "dev": true, + "license": "Apache-2.0", "dependencies": { - "acorn": "^8.9.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" + "levn": "^0.4.1" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, - "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "node_modules/@humanfs/core": { + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.0.tgz", + "integrity": "sha512-2cbWIHbZVEweE853g8jymffCA+NCMiuqeECeBBLm8dg2oFdjuGJhgN4UAbI+6v0CKbbhvtXA4qV8YR5Ji86nmw==", "dev": true, - "license": "MIT", + "license": "Apache-2.0", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=18.18.0" } }, - "node_modules/@humanwhocodes/config-array": { - "version": "0.11.14", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", - "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", - "deprecated": "Use @eslint/config-array instead", + "node_modules/@humanfs/node": { + "version": "0.16.5", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.5.tgz", + "integrity": "sha512-KSPA4umqSG4LHYRodq31VDwKAvaTF4xmVlzM8Aeh4PlU1JQ3IG0wiA8C25d3RQ9nJyM3mBHyI53K06VVL/oFFg==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@humanwhocodes/object-schema": "^2.0.2", - "debug": "^4.3.1", - "minimatch": "^3.0.5" + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" }, "engines": { - "node": ">=10.10.0" + "node": ">=18.18.0" } }, "node_modules/@humanwhocodes/module-importer": { @@ -125,6 +169,7 @@ "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=12.22" }, @@ -133,55 +178,33 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", - "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", - "deprecated": "Use @eslint/object-schema instead", - "dev": true, - "license": "BSD-3-Clause" - }, - "node_modules/@nodelib/fs.scandir": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", - "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, - "dependencies": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "node_modules/@humanwhocodes/retry": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", + "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", "dev": true, + "license": "Apache-2.0", "engines": { - "node": ">= 8" + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@nodelib/fs.walk": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", - "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "node_modules/@types/estree": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", "dev": true, - "dependencies": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" - }, - "engines": { - "node": ">= 8" - } + "license": "MIT" }, - "node_modules/@ungap/structured-clone": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true, - "license": "ISC" + "license": "MIT" }, "node_modules/acorn": { "version": "8.12.1", @@ -221,20 +244,12 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, + "license": "MIT", "dependencies": { "color-convert": "^2.0.1" }, @@ -285,6 +300,7 @@ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, + "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -301,6 +317,7 @@ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, + "license": "MIT", "dependencies": { "color-name": "~1.1.4" }, @@ -312,7 +329,8 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/concat-map": { "version": "0.0.1", @@ -326,6 +344,7 @@ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, + "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -336,13 +355,13 @@ } }, "node_modules/debug": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", - "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", "dev": true, "license": "MIT", "dependencies": { - "ms": "2.1.2" + "ms": "^2.1.3" }, "engines": { "node": ">=6.0" @@ -357,26 +376,15 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true - }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", "dev": true, - "license": "Apache-2.0", - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } + "license": "MIT" }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -388,6 +396,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.1.0.tgz", "integrity": "sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==", + "license": "BSD-2-Clause", "dependencies": { "esprima": "^4.0.1", "estraverse": "^5.2.0", @@ -405,65 +414,70 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "9.12.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.12.0.tgz", + "integrity": "sha512-UVIOlTEWxwIopRL1wgSQYdnVDcEvs2wyaO6DGo5mXqe3r16IoCNWkR29iHhyaP4cICWjbgbmFUGAhh0GJRuGZw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint-community/regexpp": "^4.11.0", + "@eslint/config-array": "^0.18.0", + "@eslint/core": "^0.6.0", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "9.12.0", + "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@nodelib/fs.walk": "^1.2.8", - "@ungap/structured-clone": "^1.2.0", + "@humanwhocodes/retry": "^0.3.1", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", - "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.2", - "eslint-visitor-keys": "^3.4.3", - "espree": "^9.6.1", - "esquery": "^1.4.2", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", + "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", + "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "globals": "^13.19.0", - "graphemer": "^1.4.0", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", - "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { "eslint": "bin/eslint.js" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { - "url": "https://opencollective.com/eslint" + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } } }, "node_modules/eslint-scope": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.1.tgz", - "integrity": "sha512-pL8XjgP4ZOmmwfFE8mEhSxA7ZY4C+LWyqjQ3o4yWkkmD0qcMT9kkW3zWHOczhWcjTSgqycYAgwSlXvZltv65og==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.1.0.tgz", + "integrity": "sha512-14dSvlhaVhKKsa9Fx1l8A17s7ah7Ef7wCakJ10LYk6+GYmP9yDti2oq2SEwcyndt6knfcZyhyxwY3i9yL78EQw==", "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", @@ -477,61 +491,26 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", - "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint/node_modules/eslint-scope": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", - "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^5.2.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint/node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "acorn": "^8.9.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" - }, + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", + "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", + "license": "Apache-2.0", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/espree": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", - "integrity": "sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.2.0.tgz", + "integrity": "sha512-upbkBJbckcCNBDBDXEbuhjbP68n+scUd3k/U2EkyM9nw+I/jPiL4cLF/Al06CF96wRltFda16sxDFrxsI1v0/g==", "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -540,22 +519,11 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", - "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", - "license": "Apache-2.0", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, "node_modules/esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "license": "BSD-2-Clause", "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" @@ -565,10 +533,11 @@ } }, "node_modules/esquery": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", - "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "estraverse": "^5.1.0" }, @@ -592,6 +561,7 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -600,6 +570,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "license": "BSD-2-Clause", "engines": { "node": ">=0.10.0" } @@ -622,28 +593,20 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", - "dev": true - }, - "node_modules/fastq": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", - "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", "dev": true, - "dependencies": { - "reusify": "^1.0.4" - } + "license": "MIT" }, "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", "dev": true, "license": "MIT", "dependencies": { - "flat-cache": "^3.0.4" + "flat-cache": "^4.0.0" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16.0.0" } }, "node_modules/find-up": { @@ -651,6 +614,7 @@ "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, + "license": "MIT", "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" @@ -663,18 +627,17 @@ } }, "node_modules/flat-cache": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", - "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", "dev": true, "license": "MIT", "dependencies": { "flatted": "^3.2.9", - "keyv": "^4.5.3", - "rimraf": "^3.0.2" + "keyv": "^4.5.4" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16" } }, "node_modules/flatted": { @@ -684,40 +647,12 @@ "dev": true, "license": "ISC" }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true, - "license": "ISC" - }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Glob versions prior to v9 are no longer supported", - "dev": true, - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.3" }, @@ -726,57 +661,48 @@ } }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", "dev": true, "license": "MIT", - "dependencies": { - "type-fest": "^0.20.2" - }, "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/graphemer": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", - "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", - "dev": true, - "license": "MIT" - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } }, "node_modules/husky": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", - "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "version": "9.1.6", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.6.tgz", + "integrity": "sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==", "dev": true, "license": "MIT", "bin": { - "husky": "lib/bin.js" + "husky": "bin.js" }, "engines": { - "node": ">=14" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/typicode" } }, "node_modules/ignore": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", - "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, "license": "MIT", "engines": { @@ -805,34 +731,17 @@ "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.8.19" } }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "dev": true, - "license": "ISC", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true, - "license": "ISC" - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -842,6 +751,7 @@ "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, + "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" }, @@ -849,20 +759,12 @@ "node": ">=0.10.0" } }, - "node_modules/is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/js-yaml": { "version": "4.1.0", @@ -895,7 +797,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/keyv": { "version": "4.5.4", @@ -912,6 +815,7 @@ "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" @@ -925,6 +829,7 @@ "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, + "license": "MIT", "dependencies": { "p-locate": "^5.0.0" }, @@ -939,7 +844,8 @@ "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/minimatch": { "version": "3.1.2", @@ -955,9 +861,9 @@ } }, "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true, "license": "MIT" }, @@ -965,30 +871,22 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", - "dev": true - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dev": true, - "license": "ISC", - "dependencies": { - "wrappy": "1" - } + "license": "MIT" }, "node_modules/optionator": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", - "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, + "license": "MIT", "dependencies": { - "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", - "type-check": "^0.4.0" + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" }, "engines": { "node": ">= 0.8.0" @@ -999,6 +897,7 @@ "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, + "license": "MIT", "dependencies": { "yocto-queue": "^0.1.0" }, @@ -1014,6 +913,7 @@ "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, + "license": "MIT", "dependencies": { "p-limit": "^3.0.2" }, @@ -1042,18 +942,9 @@ "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, "license": "MIT", "engines": { - "node": ">=0.10.0" + "node": ">=8" } }, "node_modules/path-key": { @@ -1061,6 +952,7 @@ "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -1070,6 +962,7 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.8.0" } @@ -1084,26 +977,6 @@ "node": ">=6" } }, - "node_modules/queue-microtask": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", @@ -1114,61 +987,12 @@ "node": ">=4" } }, - "node_modules/reusify": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", - "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true, - "engines": { - "iojs": ">=1.0.0", - "node": ">=0.10.0" - } - }, - "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "deprecated": "Rimraf versions prior to v4 are no longer supported", - "dev": true, - "license": "ISC", - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/run-parallel": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", - "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "queue-microtask": "^1.2.2" - } - }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "dev": true, + "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" }, @@ -1181,6 +1005,7 @@ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -1189,23 +1014,12 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "license": "BSD-3-Clause", "optional": true, "engines": { "node": ">=0.10.0" } }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -1224,6 +1038,7 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, + "license": "MIT", "dependencies": { "has-flag": "^4.0.0" }, @@ -1235,13 +1050,15 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1" }, @@ -1249,19 +1066,6 @@ "node": ">= 0.8.0" } }, - "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -1277,6 +1081,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, + "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, @@ -1287,18 +1092,22 @@ "node": ">= 8" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, - "license": "ISC" + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, diff --git a/package.json b/package.json index 4aa18d4..7eeb823 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,12 @@ "version": "1.7.1", "description": "Flatten JS AST", "main": "src/index.js", + "type": "module", "scripts": { "lint": "eslint .", - "prepare": "husky install", - "test": "node tests/tester.js" + "prepare": "husky", + "test": "node --test", + "test:coverage": "node --test --experimental-test-coverage" }, "repository": { "type": "git", @@ -25,12 +27,12 @@ "homepage": "https://github.com/PerimeterX/flast#readme", "dependencies": { "escodegen": "^2.1.0", - "espree": "^10.1.0", - "eslint-scope": "^8.0.1", + "eslint-scope": "^8.1.0", + "espree": "^10.2.0", "estraverse": "^5.3.0" }, "devDependencies": { - "eslint": "^8.49.0", - "husky": "^8.0.3" + "eslint": "^9.12.0", + "husky": "^9.1.6" } } diff --git a/src/arborist.js b/src/arborist.js index ff0e808..ef07b3d 100644 --- a/src/arborist.js +++ b/src/arborist.js @@ -1,4 +1,4 @@ -const {generateCode, generateFlatAST,} = require('./flast'); +import {generateCode, generateFlatAST} from './flast.js'; const Arborist = class { /** @@ -169,6 +169,6 @@ const Arborist = class { } }; -module.exports = { +export { Arborist, }; \ No newline at end of file diff --git a/src/flast.js b/src/flast.js index c6ccc05..bd43896 100644 --- a/src/flast.js +++ b/src/flast.js @@ -1,7 +1,7 @@ -const {parse} = require('espree'); -const {generate, attachComments} = require('escodegen'); -const estraverse = require('estraverse'); -const {analyze} = require('eslint-scope'); +import {parse} from 'espree'; +import {generate, attachComments} from 'escodegen'; +import estraverse from 'estraverse'; +import {analyze} from 'eslint-scope'; const ecmaVersion = 'latest'; const sourceType = 'module'; @@ -288,7 +288,7 @@ async function generateFlatASTAsync(inputCode, opts = {}) { return Promise.all(promises).then(() => tree); } -module.exports = { +export { estraverse, extractNodesFromRoot, generateCode, diff --git a/src/index.js b/src/index.js index f9f17c5..160d602 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,4 @@ -module.exports = { - ...require('./flast'), - ...require('./arborist'), - ...require('./types'), - utils: require('./utils'), -}; \ No newline at end of file +export * from './flast.js'; +export * from './arborist.js'; +export * from './types.js'; +export * from './utils/index.js'; \ No newline at end of file diff --git a/src/types.js b/src/types.js index d1b3fa8..7836095 100644 --- a/src/types.js +++ b/src/types.js @@ -1,4 +1,4 @@ -const {Scope} = require('eslint-scope'); +import {Scope} from 'eslint-scope'; /** * @typedef ASTNode @@ -88,7 +88,7 @@ class ASTNode {} */ class ASTScope extends Scope {} -module.exports = { +export { ASTNode, ASTScope, }; \ No newline at end of file diff --git a/src/utils/applyIteratively.js b/src/utils/applyIteratively.js index e8ae15e..e6e16bb 100644 --- a/src/utils/applyIteratively.js +++ b/src/utils/applyIteratively.js @@ -1,6 +1,6 @@ -const {Arborist} = require('../arborist'); -const logger = require('./logger'); -const {createHash} = require('node:crypto'); +import {Arborist} from '../arborist.js'; +import {logger} from './logger.js'; +import {createHash} from 'node:crypto'; const generateHash = str => createHash('sha256').update(str).digest('hex'); @@ -12,7 +12,7 @@ const generateHash = str => createHash('sha256').update(str).digest('hex'); * @param {number?} maxIterations (optional) Stop the loop after this many iterations at most. * @return {string} The possibly modified script. */ -function runLoop(script, funcs, maxIterations = 500) { +function applyIteratively(script, funcs, maxIterations = 500) { let scriptSnapshot = ''; let currentIteration = 0; let changesCounter = 0; @@ -62,4 +62,4 @@ function runLoop(script, funcs, maxIterations = 500) { return script; } -module.exports = runLoop; \ No newline at end of file +export {applyIteratively}; \ No newline at end of file diff --git a/src/utils/index.js b/src/utils/index.js index 7b85392..737a7da 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,5 @@ -module.exports = { - applyIteratively: require('./applyIteratively'), - logger: require('./logger'), - treeModifier: require('./treeModifier'), +export const utils = { + applyIteratively: (await import('./applyIteratively.js')).applyIteratively, + logger: (await import('./logger.js')).logger, + treeModifier: (await import('./treeModifier.js')).treeModifier, }; \ No newline at end of file diff --git a/src/utils/logger.js b/src/utils/logger.js index d76f894..4e9a995 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -35,10 +35,10 @@ const logger = { setLogLevelDebug() {this.setLogLevel(this.logLevels.DEBUG);}, setLogLevelLog() {this.setLogLevel(this.logLevels.LOG);}, setLogLevelError() {this.setLogLevel(this.logLevels.ERROR);}, - + setLogFunc(newLogfunc) { this.logFunc = newLogfunc; }, }; -module.exports = logger; \ No newline at end of file +export {logger}; \ No newline at end of file diff --git a/src/utils/treeModifier.js b/src/utils/treeModifier.js index 4a6cc94..c8271fe 100644 --- a/src/utils/treeModifier.js +++ b/src/utils/treeModifier.js @@ -20,4 +20,4 @@ function treeModifier(filterFunc, modFunc, funcName) { return func; } -module.exports = treeModifier; \ No newline at end of file +export {treeModifier}; \ No newline at end of file diff --git a/tests/aboristTests.js b/tests/aboristTests.js deleted file mode 100644 index a5de576..0000000 --- a/tests/aboristTests.js +++ /dev/null @@ -1,155 +0,0 @@ -const assert = require('node:assert'); -const {Arborist, generateFlatAST} = require(__dirname + '/../src/index'); -module.exports = [ - { - enabled: true, - name: 'Node replacement', - description: 'Verify node replacement works as expected.', - run() { - const code = `console.log('Hello' + ' ' + 'there!');`; - const expectedOutput = `console.log('General' + ' ' + 'Kenobi');`; - const replacements = { - 'Hello': 'General', - 'there!': 'Kenobi', - }; - const arborist = new Arborist(code); - arborist.ast.filter(n => n.type === 'Literal' && replacements[n.value]) - .forEach(n => arborist.markNode(n, { - type: 'Literal', - value: replacements[n.value], - raw: `'${replacements[n.value]}'`, - })); - const numberOfChangesMade = arborist.applyChanges(); - const result = arborist.script; - - assert.equal(result, expectedOutput, - `Result does not match expected output.`); - assert.equal(numberOfChangesMade, Object.keys(replacements).length, - `The number of actual replacements does not match expectations.`); - return true; - }, - }, - { - enabled: true, - name: 'Root node replacement', - description: 'Verify the root node replacement works as expected.', - run() { - const code = `a;`; - const expectedOutput = `b`; - const arborist = new Arborist(code); - arborist.markNode(arborist.ast[0], { - type: 'Identifier', - name: 'b', - }); - arborist.applyChanges(); - const result = arborist.script; - - assert.equal(result, expectedOutput, - `Result does not match expected output.`); - return true; - }, - }, - { - enabled: true, - name: 'Root node replacement - TN', - description: 'Verify only the root node is replaced .', - run() { - const code = `a;b;`; - const expectedOutput = `c`; - const arborist = new Arborist(code); - arborist.markNode(arborist.ast[4], { - type: 'Identifier', - name: 'v', - }); - arborist.markNode(arborist.ast[0], { - type: 'Identifier', - name: 'c', - }); - arborist.applyChanges(); - const result = arborist.script; - - assert.equal(result, expectedOutput, - `Result does not match expected output.`); - return true; - }, - }, - { - enabled: true, - name: 'Node deletion', - description: 'Verify node deletion works as expected.', - run() { - const code = `const a = ['There', 'can', 'be', 'only', 'one'];`; - const expectedOutput = `const a = ['one'];`; - const literalToSave = 'one'; - const arborist = new Arborist(code); - arborist.ast.filter(n => n.type === 'Literal' && n.value !== literalToSave).forEach(n => arborist.markNode(n)); - const numberOfChangesMade = arborist.applyChanges(); - const expectedNumberOfChanges = 4; - const result = arborist.script; - - assert.equal(result, expectedOutput, - `Result does not match expected output.`); - assert.equal(numberOfChangesMade, expectedNumberOfChanges, - `The number of actual changes does not match expectations.`); - }, - }, - { - enabled: true, - name: 'Arborist accepts a valid script on instantiation', - description: `Verify a valid script can be used to initialize an arborist instance.`, - run() { - const code = `console.log('test');`; - let error = ''; - let arborist; - const expectedArraySize = generateFlatAST(code).length; - try { - arborist = new Arborist(code); - } catch (e) { - error = e.message; - } - assert.ok(arborist?.script, - `Arborist failed to instantiate. ${error ? 'Error: ' + error : ''}`); - assert(!error, - `Arborist instantiated with an error: ${error}`); - assert.equal(arborist.script, code, - `Arborist script did not match initialization argument.`); - assert.equal(arborist.ast.length, expectedArraySize, - `Arborist did not generate a flat AST array.`); - }, - }, - { - enabled: true, - name: 'Arborist accepts a valid flat AST array on instantiation', - description: `Verify a valid AST array can be used to initialize an arborist instance.`, - run() { - const code = `console.log('test');`; - const ast = generateFlatAST(code); - let error = ''; - let arborist; - try { - arborist = new Arborist(ast); - } catch (e) { - error = e.message; - } - assert.ok(arborist?.ast?.length, - `Arborist failed to instantiate. ${error ? 'Error: ' + error : ''}`); - assert.equal(error, '', - `Arborist instantiated with an error: ${error}`); - assert.deepEqual(arborist.ast, ast, - `Arborist ast array did not match initialization argument.`); - }, - }, - { - enabled: true, - name: `Invalid changes are not applied`, - description: `Verify a valid AST array can be used to initialize an arborist instance.`, - run() { - const code = `console.log('test');`; - const arborist = new Arborist(code); - arborist.markNode(arborist.ast.find(n => n.type === 'Literal'), {type: 'EmptyStatement'}); - arborist.markNode(arborist.ast.find(n => n.name === 'log'), {type: 'EmptyStatement'}); - arborist.applyChanges(); - assert.equal(arborist.script, code); - }, - }, -]; \ No newline at end of file diff --git a/tests/arborist.test.js b/tests/arborist.test.js new file mode 100644 index 0000000..75a40a9 --- /dev/null +++ b/tests/arborist.test.js @@ -0,0 +1,114 @@ +import assert from 'node:assert'; +import {describe, it} from 'node:test'; +import {Arborist, generateFlatAST} from '../src/index.js'; + +describe('Arborist tests', () => { + it('Verify node replacement works as expected', () => { + const code = `console.log('Hello' + ' ' + 'there!');`; + const expectedOutput = `console.log('General' + ' ' + 'Kenobi');`; + const replacements = { + 'Hello': 'General', + 'there!': 'Kenobi', + }; + const arborist = new Arborist(code); + arborist.ast.filter(n => n.type === 'Literal' && replacements[n.value]) + .forEach(n => arborist.markNode(n, { + type: 'Literal', + value: replacements[n.value], + raw: `'${replacements[n.value]}'`, + })); + const numberOfChangesMade = arborist.applyChanges(); + const result = arborist.script; + + assert.equal(result, expectedOutput, `Result does not match expected output.`); + assert.equal(numberOfChangesMade, Object.keys(replacements).length, `The number of actual replacements does not match expectations.`); + }); + it('Verify the root node replacement works as expected', () => { + const code = `a;`; + const expectedOutput = `b`; + const arborist = new Arborist(code); + arborist.markNode(arborist.ast[0], { + type: 'Identifier', + name: 'b', + }); + arborist.applyChanges(); + const result = arborist.script; + + assert.equal(result, expectedOutput, `Result does not match expected output.`); + }); + it('Verify only the root node is replaced', () => { + const code = `a;b;`; + const expectedOutput = `c`; + const arborist = new Arborist(code); + arborist.markNode(arborist.ast[4], { + type: 'Identifier', + name: 'v', + }); + arborist.markNode(arborist.ast[0], { + type: 'Identifier', + name: 'c', + }); + arborist.applyChanges(); + const result = arborist.script; + + assert.equal(result, expectedOutput, `Result does not match expected output.`); + }); + it('Verify node deletion works as expected', () => { + const code = `const a = ['There', 'can', 'be', 'only', 'one'];`; + const expectedOutput = `const a = ['one'];`; + const literalToSave = 'one'; + const arborist = new Arborist(code); + arborist.ast.filter(n => n.type === 'Literal' && n.value !== literalToSave).forEach(n => arborist.markNode(n)); + const numberOfChangesMade = arborist.applyChanges(); + const expectedNumberOfChanges = 4; + const result = arborist.script; + + assert.equal(result, expectedOutput, `Result does not match expected output.`); + assert.equal(numberOfChangesMade, expectedNumberOfChanges, `The number of actual changes does not match expectations.`); + }); + it('Verify the correct node is targeted for deletion', () => { + const code = `var a = 1;`; + const expectedResult = ``; + const arborist = new Arborist(code); + arborist.markNode(arborist.ast.find(n => n.type === 'VariableDeclarator')); + arborist.applyChanges(); + assert.equal(arborist.script, expectedResult, 'An incorrect node was targeted for deletion.'); + }); + it('Verify a valid script can be used to initialize an arborist instance', () => { + const code = `console.log('test');`; + let error = ''; + let arborist; + const expectedArraySize = generateFlatAST(code).length; + try { + arborist = new Arborist(code); + } catch (e) { + error = e.message; + } + assert.ok(arborist?.script, `Arborist failed to instantiate. ${error ? 'Error: ' + error : ''}`); + assert.ok(!error, `Arborist instantiated with an error: ${error}`); + assert.equal(arborist.script, code, `Arborist script did not match initialization argument.`); + assert.equal(arborist.ast.length, expectedArraySize, `Arborist did not generate a flat AST array.`); + }); + it('Verify a valid AST array can be used to initialize an arborist instance', () => { + const code = `console.log('test');`; + const ast = generateFlatAST(code); + let error = ''; + let arborist; + try { + arborist = new Arborist(ast); + } catch (e) { + error = e.message; + } + assert.ok(arborist?.ast?.length, `Arborist failed to instantiate. ${error ? 'Error: ' + error : ''}`); + assert.equal(error, '', `Arborist instantiated with an error: ${error}`); + assert.deepEqual(arborist.ast, ast, `Arborist ast array did not match initialization argument.`); + }); + it('Verify invalid changes are not applied', () => { + const code = `console.log('test');`; + const arborist = new Arborist(code); + arborist.markNode(arborist.ast.find(n => n.type === 'Literal'), {type: 'EmptyStatement'}); + arborist.markNode(arborist.ast.find(n => n.name === 'log'), {type: 'EmptyStatement'}); + arborist.applyChanges(); + assert.equal(arborist.script, code, 'Invalid changes were applied.'); + }); +}); \ No newline at end of file diff --git a/tests/functionality.test.js b/tests/functionality.test.js new file mode 100644 index 0000000..2690adf --- /dev/null +++ b/tests/functionality.test.js @@ -0,0 +1,118 @@ +import path from 'node:path'; +import assert from 'node:assert'; +import {describe, it} from 'node:test'; +import {fileURLToPath} from 'node:url'; +import {generateFlatAST, generateCode} from '../src/index.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +describe('Functionality tests', () => { + it('Verify the code breakdown generates the expected nodes by checking the properties of the generated ASTNodes', () => { + const code = `a=3`; + const ast = generateFlatAST(code); + const expectedBreakdown = [ + {nodeId: 0, type: 'Program', start: 0, end: 3, src: 'a=3', parentNode: null, parentKey: ''}, + {nodeId: 1, type: 'ExpressionStatement', start: 0, end: 3, src: 'a=3', parentKey: 'body'}, + {nodeId: 2, type: 'AssignmentExpression', start: 0, end: 3, src: 'a=3', operator: '=', parentKey: 'expression'}, + {nodeId: 3, type: 'Identifier', start: 0, end: 1, src: 'a', parentKey: 'left'}, + {nodeId: 4, type: 'Literal', start: 2, end: 3, src: '3', value: 3, raw: '3', parentKey: 'right'}, + ]; + expectedBreakdown.forEach(node => { + const parsedNode = ast[node.nodeId]; + for (const [k, v] of Object.entries(node)) { + assert.equal(v, parsedNode[k], `Node #${parsedNode[k]} parsed wrong on key '${k}'`); + } + }); + }); + it('Verify the expected functions and classes can be imported', async () => { + const availableImports = [ + 'Arborist', + 'ASTNode', + 'ASTScope', + 'estraverse', + 'generateCode', + 'generateFlatAST', + 'parseCode', + 'utils', + ]; + const flast = await import(path.resolve(__dirname + '/../src/index.js')); + for (const importName of availableImports) { + assert.ok(importName in flast, `Failed to import "${importName}"`); + } + }); + it('Verify the code breakdown generates the expected nodes by checking the number of nodes for each expected type', () => { + const code = `console.log('hello' + ' ' + 'there');`; + const ast = generateFlatAST(code); + const expectedBreakdown = { + Program: 1, + ExpressionStatement: 1, + CallExpression: 1, + MemberExpression: 1, + Identifier: 2, + BinaryExpression: 2, + Literal: 3, + }; + const expectedNumberOfNodes = 11; + assert.equal(ast.length, expectedNumberOfNodes, `Unexpected number of nodes`); + for (const nodeType of Object.keys(expectedBreakdown)) { + const numberOfNodes = ast.filter(n => n.type === nodeType).length; + assert.equal(numberOfNodes, expectedBreakdown[nodeType], `Wrong number of nodes for '${nodeType}' node type`); + } + }); + it('Verify the AST can be parsed and regenerated into the same code', () => { + const code = `console.log('hello' + ' ' + 'there');`; + const ast = generateFlatAST(code); + const regeneratedCode = generateCode(ast[0]); + assert.equal(regeneratedCode, code, `Original code did not regenerate back to the same source.`); + }); + it(`Verify generateFlatAST's detailed option works as expected`, () => { + const code = `var a = [1]; a[0];`; + const noDetailsAst = generateFlatAST(code, {detailed: false}); + const [noDetailsVarDec, noDetailsVarRef] = noDetailsAst.filter(n => n.type === 'Identifier'); + assert.equal(noDetailsVarDec.references || noDetailsVarRef.declNode || noDetailsVarRef.scope, undefined, + `Flat AST generated with details despite 'detailed' option set to false.`); + + const noSrcAst = generateFlatAST(code, {includeSrc: false}); + assert.equal(noSrcAst.find(n => n.src !== undefined), null, `Flat AST generated with src despite 'includeSrc' option set to false.`); + + const detailedAst = generateFlatAST(code, {detailed: true}); + const [detailedVarDec, detailedVarRef] = detailedAst.filter(n => n.type === 'Identifier'); + assert.ok(detailedVarDec.parentNode && detailedVarDec.childNodes && detailedVarDec.references && + detailedVarRef.declNode && detailedVarRef.nodeId && detailedVarRef.scope && detailedVarRef.src, + `Flat AST missing details despite 'detailed' option set to true.`); + + const detailedNoSrcAst = generateFlatAST(code, {detailed: true, includeSrc: false}); + assert.equal(detailedNoSrcAst[0].src, undefined, `Flat AST includes details despite 'detailed' option set to true and 'includeSrc' option set to false.`); + }); + it(`Verify a script is parsed in "sloppy mode" if strict mode is restricting parsing`, () => { + const code = `let a; delete a;`; + let ast = []; + let error = ''; + try { + ast = generateFlatAST(code); + } catch (e) { + error = e.message; + } + assert.ok(ast.length, `Script was not parsed. Got the error "${error}"`); + }); + it(`Verify a script is only parsed in its selected sourceType`, () => { + const code = `let a; delete a;`; + let unparsedAst = []; + let parsedAst = []; + let unparsedError = ''; + let parsedError = ''; + try { + unparsedAst = generateFlatAST(code, {alernateSourceTypeOnFailure: false}); + } catch (e) { + unparsedError = e.message; + } + try { + parsedAst = generateFlatAST(code, {alernateSourceTypeOnFailure: true}); + } catch (e) { + parsedError = e.message; + } + assert.equal(unparsedAst.length, 0, `Script was not parsed.${unparsedError ? 'Error: ' + unparsedError : ''}`); + assert.ok(parsedAst.length, `Script was not parsed.${parsedError ? 'Error: ' + parsedError : ''}`); + }); +}); \ No newline at end of file diff --git a/tests/functionalityTests.js b/tests/functionalityTests.js deleted file mode 100644 index b0014ad..0000000 --- a/tests/functionalityTests.js +++ /dev/null @@ -1,161 +0,0 @@ -const assert = require('node:assert'); -const {generateFlatAST, generateCode} = require(__dirname + '/../src/index'); -module.exports = [ - { - enabled: true, - name: 'ASTNode structure integrity', - description: 'Verify the code breakdown generates the expected nodes by checking the properties of the generated ASTNodes.', - run() { - const code = `a=3`; - const ast = generateFlatAST(code); - const expectedBreakdown = [ - {nodeId: 0, type: 'Program', start: 0, end: 3, src: 'a=3', parentNode: null, parentKey: ''}, - {nodeId: 1, type: 'ExpressionStatement', start: 0, end: 3, src: 'a=3', parentKey: 'body'}, - {nodeId: 2, type: 'AssignmentExpression', start: 0, end: 3, src: 'a=3', operator: '=', parentKey: 'expression'}, - {nodeId: 3, type: 'Identifier', start: 0, end: 1, src: 'a', parentKey: 'left'}, - {nodeId: 4, type: 'Literal', start: 2, end: 3, src: '3', value: 3, raw: '3', parentKey: 'right'}, - ]; - expectedBreakdown.forEach(node => { - const parsedNode = ast[node.nodeId]; - for (const [k, v] of Object.entries(node)) { - assert.equal(v, parsedNode[k], - `Node #${parsedNode[k]} parsed wrong on key '${k}'`); - } - }); - }, - }, - { - enabled: true, - name: 'Verify Available Imports', - description: 'Verify the expected functions and classes can be imported.', - run() { - const {resolve} = require('node:path'); - const availableImports = [ - 'Arborist', - 'ASTNode', - 'ASTScope', - 'estraverse', - 'generateCode', - 'generateFlatAST', - 'parseCode', - 'utils', - ]; - function tryImporting(importName) { - const {[importName]: tempImport} = require(importSource); - return tempImport; - } - const importSource = resolve(__dirname + '/../src/index'); - for (const importName of availableImports) { - assert.ok(tryImporting(importName), `Failed to import "${importName}" from ${importSource}`); - } - }, - }, - { - enabled: true, - name: 'Number of nodes', - description: 'Verify the code breakdown generates the expected nodes by checking the number of nodes for each expected type.', - run() { - const code = `console.log('hello' + ' ' + 'there');`; - const ast = generateFlatAST(code); - const expectedBreakdown = { - Program: 1, - ExpressionStatement: 1, - CallExpression: 1, - MemberExpression: 1, - Identifier: 2, - BinaryExpression: 2, - Literal: 3, - }; - const expectedNumberOfNodes = 11; - assert.equal(ast.length, expectedNumberOfNodes, - `Unexpected number of nodes`); - for (const nodeType of Object.keys(expectedBreakdown)) { - const numberOfNodes = ast.filter(n => n.type === nodeType).length; - assert.equal(numberOfNodes, expectedBreakdown[nodeType], - `Wrong number of nodes for '${nodeType}' node type`); - } - }, - }, - { - enabled: true, - name: 'Parse and generate', - description: 'Verify the AST can be parsed and regenerated into the same code.', - run() { - const code = `console.log('hello' + ' ' + 'there');`; - const ast = generateFlatAST(code); - const regeneratedCode = generateCode(ast[0]); - assert.equal(regeneratedCode, code, - `Original code did not regenerate back to the same source.`); - }, - }, - { - enabled: true, - name: 'Options: detailed', - description: `Verify generateFlatAST's detailed option works as expected.`, - source: `var a = [1]; a[0];`, - run() { - const code = `var a = [1]; a[0];`; - const noDetailsAst = generateFlatAST(code, {detailed: false}); - const [noDetailsVarDec, noDetailsVarRef] = noDetailsAst.filter(n => n.type === 'Identifier'); - assert.equal(noDetailsVarDec.references || noDetailsVarRef.declNode || noDetailsVarRef.scope, undefined, - `Flat AST generated with details despite 'detailed' option set to false.`); - - const noSrcAst = generateFlatAST(code, {includeSrc: false}); - assert.equal(noSrcAst.find(n => n.src !== undefined), null, - `Flat AST generated with src despite 'includeSrc' option set to false.`); - - const detailedAst = generateFlatAST(code, {detailed: true}); - const [detailedVarDec, detailedVarRef] = detailedAst.filter(n => n.type === 'Identifier'); - assert.ok(detailedVarDec.parentNode && detailedVarDec.childNodes && detailedVarDec.references && - detailedVarRef.declNode && detailedVarRef.nodeId && detailedVarRef.scope && detailedVarRef.src, - `Flat AST missing details despite 'detailed' option set to true.`); - - const detailedNoSrcAst = generateFlatAST(code, {detailed: true, includeSrc: false}); - assert.equal(detailedNoSrcAst[0].src, undefined, - `Flat AST includes details despite 'detailed' option set to true and 'includeSrc' option set to false.`); - }, - }, - { - enabled: true, - name: 'Dynamic sourceType switching', - description: `Verify a script is parsed in "sloppy mode" if strict mode is restricting parsing.`, - run() { - const code = `let a; delete a;`; - let ast = []; - let error = ''; - try { - ast = generateFlatAST(code); - } catch (e) { - error = e.message; - } - assert.ok(ast.length, - `Script was not parsed. Got the error "${error}"`); - }, - }, - { - enabled: true, - name: 'Disable dynamic sourceType switching', - description: `Verify a script is only parsed in its selected sourceType.`, - run() { - const code = `let a; delete a;`; - let unparsedAst = []; - let parsedAst = []; - let unparsedError = ''; - let parsedError = ''; - try { - unparsedAst = generateFlatAST(code, {alernateSourceTypeOnFailure: false}); - } catch (e) { - unparsedError = e.message; - } - try { - parsedAst = generateFlatAST(code, {alernateSourceTypeOnFailure: true}); - } catch (e) { - parsedError = e.message; - } - assert.equal(unparsedAst.length, 0, - `Script was not parsed.${unparsedError ? 'Error: ' + unparsedError : ''}`); - assert.ok(parsedAst.length, - `Script was not parsed.${parsedError ? 'Error: ' + parsedError : ''}`); - }, - }, -]; \ No newline at end of file diff --git a/tests/parsing.test.js b/tests/parsing.test.js new file mode 100644 index 0000000..9d696fd --- /dev/null +++ b/tests/parsing.test.js @@ -0,0 +1,48 @@ +import assert from 'node:assert'; +import {describe, it} from 'node:test'; +import {generateFlatAST} from '../src/index.js'; + +describe('Parsing tests', () => { + it('Verify the function-expression-name scope is always replaced with its child scope', () => { + const code = ` +(function test(p) { + let i = 1; + i; +})();`; + const ast = generateFlatAST(code); + const testedScope = ast[0].allScopes[Object.keys(ast[0].allScopes).slice(-1)[0]]; + const expectedParentScopeType = 'function-expression-name'; + const expectedScopeType = 'function'; + // ast.slice(-1)[0].type is the last identifier in the code and should have the expected scope type + assert.equal(ast.slice(-1)[0].scope.type, expectedScopeType, `Unexpected scope`); + assert.equal(testedScope.type, expectedParentScopeType, `Tested scope is not the child of the correct scope`); + }); + it('Verify declNode references the local declaration correctly', () => { + const innerScopeVal = 'inner'; + const outerScopeVal = 'outer'; + const code = `var a = '${outerScopeVal}'; + if (true) { + let a = '${innerScopeVal}'; + console.log(a); + } + console.log(a);`; + const ast = generateFlatAST(code); + const [innerIdentifier, outerIdentifier] = ast.filter(n => n.type === 'Identifier' && n.parentNode.type === 'CallExpression'); + const innerValResult = innerIdentifier.declNode.parentNode.init.value; + const outerValResult = outerIdentifier.declNode.parentNode.init.value; + assert.equal(innerValResult, innerScopeVal, `Declaration node (inner scope) is incorrectly referenced.`); + assert.equal(outerValResult, outerScopeVal, `Declaration node (outer scope) is incorrectly referenced.`); + }); + it(`Verify a function's identifier isn't treated as a reference`, () => { + const code = `function a() { + var a; + }`; + const ast = generateFlatAST(code); + const funcId = ast.find(n => n.name ==='a' && n.parentNode.type === 'FunctionDeclaration'); + const varId = ast.find(n =>n.name ==='a' && n.parentNode.type === 'VariableDeclarator'); + const functionReferencesFound = !!funcId.references?.length; + const variableReferencesFound = !!varId.references?.length; + assert.ok(!functionReferencesFound, `References to a function were incorrectly found`); + assert.ok(!variableReferencesFound, `References to a variable were incorrectly found`); + }); +}); \ No newline at end of file diff --git a/tests/parsingTests.js b/tests/parsingTests.js deleted file mode 100644 index a46e3d6..0000000 --- a/tests/parsingTests.js +++ /dev/null @@ -1,68 +0,0 @@ -const assert = require('node:assert'); -const {generateFlatAST} = require('../src/index'); - -module.exports = [ - { - enabled: true, - name: 'Function expression namespace scope is exchanged for child scope.', - description: 'Verify the function-expression-name scope is always replaced with its child scope.', - run() { - const code = ` -(function test(p) { - let i = 1; - i; -})();`; - const ast = generateFlatAST(code); - const testedScope = ast[0].allScopes[Object.keys(ast[0].allScopes).slice(-1)[0]]; - const expectedParentScopeType = 'function-expression-name'; - const expectedScopeType = 'function'; - // ast.slice(-1)[0].type is the last identifier in the code and should have the expected scope type - assert.equal(ast.slice(-1)[0].scope.type, expectedScopeType, - `Unexpected scope`); - assert.equal(testedScope.type, expectedParentScopeType, - `Tested scope is not the child of the correct scope`); - }, - }, - { - enabled: true, - name: 'Local variable declaration supersedes outer scope declaration', - description: 'Verify declNode references the local declaration correctly.', - run() { - const innerScopeVal = 'inner'; - const outerScopeVal = 'outer'; - const code = `var a = '${outerScopeVal}'; - if (true) { - let a = '${innerScopeVal}'; - console.log(a); - } - console.log(a);`; - const ast = generateFlatAST(code); - const [innerIdentifier, outerIdentifier] = ast.filter(n => n.type === 'Identifier' && n.parentNode.type === 'CallExpression'); - const innerValResult = innerIdentifier.declNode.parentNode.init.value; - const outerValResult = outerIdentifier.declNode.parentNode.init.value; - assert.equal(innerValResult, innerScopeVal, - `Declaration node (inner scope) is incorrectly referenced.`); - assert.equal(outerValResult, outerScopeVal, - `Declaration node (outer scope) is incorrectly referenced.`); - }, - }, - { - enabled: true, - name: 'Variable references are not confused with functions of the same name', - description: `Verify a function's identifier isn't treated as a reference.`, - run() { - const code = `function a() { - var a; - }`; - const ast = generateFlatAST(code); - const funcId = ast.find(n => n.name ==='a' && n.parentNode.type === 'FunctionDeclaration'); - const varId = ast.find(n =>n.name ==='a' && n.parentNode.type === 'VariableDeclarator'); - const functionReferencesFound = !!funcId.references?.length; - const variableReferencesFound = !!varId.references?.length; - assert.ok(!functionReferencesFound, - `References to a function were incorrectly found`); - assert.ok(!variableReferencesFound, - `References to a variable were incorrectly found`); - }, - }, -]; \ No newline at end of file diff --git a/tests/tester.js b/tests/tester.js deleted file mode 100644 index f073246..0000000 --- a/tests/tester.js +++ /dev/null @@ -1,31 +0,0 @@ -const tests = { - Parsing: './parsingTests', - Functionality: './functionalityTests', - Arborist: './aboristTests', - Utils: './utilsTests', -}; - -let allTests = 0; -let skippedTests = 0; -console.time('tests in'); -for (const [moduleName, moduleTests] of Object.entries(tests)) { - const loadedTests = require(moduleTests); - for (const test of loadedTests) { - allTests++; - if (test.enabled) { - process.stdout.write(`[${moduleName}] ${test.name}`.padEnd(90, '.')); - console.time('PASS'); - test.run(); - console.timeEnd('PASS'); - } else { - skippedTests++; - console.log(`Testing [${moduleName}] ${test.name}...`.padEnd(101, '.') + ` SKIPPED: ${test.reason}`); - } - } -} -if (skippedTests > 0) { - process.stdout.write(`Completed ${allTests - skippedTests}/${allTests} (${skippedTests} skipped) `); -} else process.stdout.write(`Completed ${allTests} `); -console.timeEnd('tests in'); - -module.exports = tests; \ No newline at end of file diff --git a/tests/utils.test.js b/tests/utils.test.js new file mode 100644 index 0000000..d251229 --- /dev/null +++ b/tests/utils.test.js @@ -0,0 +1,82 @@ +import assert from 'node:assert'; +import {utils} from '../src/index.js'; +import {describe, it} from 'node:test'; + +describe('Utils tests: treeModifier', () => { + it(`Verify treeModifier sets a generic function name`, () => { + const expectedFuncName = 'func'; + const generatedFunc = utils.treeModifier(() => {}, () => {}); + assert.equal(generatedFunc.name, expectedFuncName, `The default name of the generated function does not match`); + }); + it(`Verify treeModifier sets the function's name properly`, () => { + const expectedFuncName = 'expectedFuncName'; + const generatedFunc = utils.treeModifier(() => {}, () => {}, expectedFuncName); + assert.equal(generatedFunc.name, expectedFuncName, `The name of the generated function does not match`); + }); +}); +describe('Utils tests: applyIteratively', () => { + it('Verify applyIteratively cannot remove the root node without replacing it', () => { + const code = `a`; + const expectedOutput = code; + const f = n => n.type === 'Program'; + const m = (n, arb) => arb.markNode(n); + const generatedFunc = utils.treeModifier(f, m); + const result = utils.applyIteratively(code, [generatedFunc]); + + assert.equal(result, expectedOutput, `Result does not match expected output`); + }); + it('Verify applyIteratively catches a critical exception', () => { + const code = `a`; + // noinspection JSCheckFunctionSignatures + const result = utils.applyIteratively(code, {length: 4}); + assert.equal(result, code, `Result does not match expected output`); + }); + it('Verify applyIteratively works as expected', () => { + const code = `console.log('Hello' + ' ' + 'there');`; + const expectedOutput = `console.log('General' + ' ' + 'Kenobi');`; + const replacements = { + Hello: 'General', + there: 'Kenobi', + }; + let result = code; + const f = n => n.type === 'Literal' && replacements[n.value]; + const m = (n, arb) => arb.markNode(n, { + type: 'Literal', + value: replacements[n.value], + }); + const generatedFunc = utils.treeModifier(f, m); + result = utils.applyIteratively(result, [generatedFunc]); + + assert.equal(result, expectedOutput, `Result does not match expected output`); + }); +}); +describe('Utils tests: logger', () => { + it(`Verify logger sets the log level to DEBUG properly`, () => { + const expectedLogLevel = utils.logger.logLevels.DEBUG; + utils.logger.setLogLevelDebug(); + assert.equal(utils.logger.currentLogLevel, expectedLogLevel, `The log level DEBUG was not set properly`); + }); + it(`Verify logger sets the log level to NONE properly`, () => { + const expectedLogLevel = utils.logger.logLevels.NONE; + utils.logger.setLogLevelNone(); + assert.equal(utils.logger.currentLogLevel, expectedLogLevel, `The log level NONE was not set properly`); + }); + it(`Verify logger sets the log level to LOG properly`, () => { + const expectedLogLevel = utils.logger.logLevels.LOG; + utils.logger.setLogLevelLog(); + assert.equal(utils.logger.currentLogLevel, expectedLogLevel, `The log level LOG was not set properly`); + }); + it(`Verify logger sets the log level to ERROR properly`, () => { + const expectedLogLevel = utils.logger.logLevels.ERROR; + utils.logger.setLogLevelError(); + assert.equal(utils.logger.currentLogLevel, expectedLogLevel, `The log level ERROR was not set properly`); + }); + it(`Verify logger sets the log function properly`, () => { + const expectedLogFunc = () => 'test'; + utils.logger.setLogFunc(expectedLogFunc); + assert.equal(utils.logger.logFunc, expectedLogFunc, `The log function was not set properly`); + }); + it(`Verify logger throws an error when setting an unknown log level`, () => { + assert.throws(() => utils.logger.setLogLevel(0), Error, `An error was not thrown when setting an unknown log level`); + }); +}); \ No newline at end of file diff --git a/tests/utilsTests.js b/tests/utilsTests.js deleted file mode 100644 index d3d5692..0000000 --- a/tests/utilsTests.js +++ /dev/null @@ -1,32 +0,0 @@ -const {utils} = require(__dirname + '/../src/index'); -const assert = require('node:assert'); -module.exports = [ - { - enabled: true, - name: 'treeModifier + applyIteratively', - description: '', - run() { - const code = `console.log('Hello' + ' ' + 'there');`; - const expectedOutput = `console.log('General' + ' ' + 'Kenobi');`; - const expectedFuncName = 'StarWarsDialog'; - const replacements = { - Hello: 'General', - there: 'Kenobi', - }; - let result = code; - const f = n => n.type === 'Literal' && replacements[n.value]; - const m = (n, arb) => arb.markNode(n, { - type: 'Literal', - value: replacements[n.value], - }); - const generatedFunc = utils.treeModifier(f, m, expectedFuncName); - result = utils.applyIteratively(result, [generatedFunc]); - - assert.equal(result, expectedOutput, - `Result does not match expected output.`); - assert.equal(generatedFunc.name, expectedFuncName, - `The name of the generated function does not match.`); - return true; - }, - }, -]; \ No newline at end of file