From 326ddfb4e0412d13dc7b74e1637b375cfb6a14e1 Mon Sep 17 00:00:00 2001 From: Klaus Hott Vidal Date: Tue, 22 Aug 2023 11:39:51 +1200 Subject: [PATCH] Migrating to ECMAScript modules (#894) * ESM configs * binary operators printers to ESM * nodes to ESM * common utilities to ESM * comments to ESM * main files to ESM * test configuration to ESM * format tests to new config * unit tests to ESM * prettier 2.8.8 is incompatible with ESM so only running standalone tests * cleanup: dir-to-object doesn't work with ESM * updating dependencies compatible with ESM * fixing lint * testing prettier-version on cjs and esm * adding conditional exports for environments using cjs or prettier v2 * using cache strategy to load solc and improving testing times * updating `parse` signature for standalone tests * Include the whole dist/ directory when publishing * since we are publishing the whole `dist` folder, we make sure to clean it before building --------- Co-authored-by: Franco Victorio --- .c8rc | 2 +- .eslintignore | 2 +- .eslintrc | 8 + .github/workflows/CI.yml | 4 +- .npmignore | 1 - jest.config.js | 4 +- package-lock.json | 732 ++++++++++-------- package.json | 45 +- scripts/generateIndexes.js | 16 - scripts/makeData.js | 23 - src/binary-operator-printers/arithmetic.js | 26 +- src/binary-operator-printers/assignment.js | 10 +- src/binary-operator-printers/bit.js | 4 +- src/binary-operator-printers/comparison.js | 24 +- .../exponentiation.js | 10 +- src/binary-operator-printers/index.js | 20 +- src/binary-operator-printers/logical.js | 26 +- src/binary-operator-printers/shift.js | 4 +- src/clean.js | 2 +- src/comments/handler.js | 22 +- .../handleContractDefinitionComments.js | 10 +- .../handleModifierInvocationComments.js | 10 +- src/comments/handlers/index.js | 8 +- src/comments/ignore.js | 2 +- src/comments/index.js | 6 +- src/comments/printer.js | 15 +- src/common/printer-helpers.js | 35 +- src/common/util.js | 28 +- src/index.js | 26 +- src/loc.js | 2 +- src/nodes/ArrayTypeName.js | 4 +- src/nodes/AssemblyAssignment.js | 12 +- src/nodes/AssemblyBlock.js | 17 +- src/nodes/AssemblyCall.js | 6 +- src/nodes/AssemblyCase.js | 4 +- src/nodes/AssemblyFor.js | 12 +- src/nodes/AssemblyFunctionDefinition.js | 17 +- src/nodes/AssemblyIf.js | 4 +- src/nodes/AssemblyLocalDefinition.js | 13 +- src/nodes/AssemblyMemberAccess.js | 4 +- src/nodes/AssemblyStackAssignment.js | 4 +- src/nodes/AssemblySwitch.js | 12 +- src/nodes/BinaryOperation.js | 7 +- src/nodes/Block.js | 17 +- src/nodes/BooleanLiteral.js | 4 +- src/nodes/Break.js | 4 +- src/nodes/BreakStatement.js | 4 +- src/nodes/CatchClause.js | 6 +- src/nodes/Conditional.js | 12 +- src/nodes/Continue.js | 4 +- src/nodes/ContinueStatement.js | 4 +- src/nodes/ContractDefinition.js | 17 +- src/nodes/CustomErrorDefinition.js | 6 +- src/nodes/DecimalNumber.js | 4 +- src/nodes/DoWhileStatement.js | 13 +- src/nodes/ElementaryTypeName.js | 4 +- src/nodes/EmitStatement.js | 4 +- src/nodes/EnumDefinition.js | 13 +- src/nodes/EnumValue.js | 4 +- src/nodes/EventDefinition.js | 6 +- src/nodes/ExpressionStatement.js | 13 +- src/nodes/FileLevelConstant.js | 4 +- src/nodes/ForStatement.js | 13 +- src/nodes/FunctionCall.js | 13 +- src/nodes/FunctionDefinition.js | 19 +- src/nodes/FunctionTypeName.js | 13 +- src/nodes/HexLiteral.js | 13 +- src/nodes/HexNumber.js | 4 +- src/nodes/Identifier.js | 4 +- src/nodes/IfStatement.js | 17 +- src/nodes/ImportDirective.js | 29 +- src/nodes/IndexAccess.js | 12 +- src/nodes/IndexRangeAccess.js | 4 +- src/nodes/InheritanceSpecifier.js | 6 +- src/nodes/InlineAssemblyStatement.js | 7 +- src/nodes/LabelDefinition.js | 12 +- src/nodes/Mapping.js | 4 +- src/nodes/MemberAccess.js | 16 +- src/nodes/ModifierDefinition.js | 13 +- src/nodes/ModifierInvocation.js | 8 +- src/nodes/NameValueExpression.js | 4 +- src/nodes/NameValueList.js | 13 +- src/nodes/NewExpression.js | 4 +- src/nodes/NumberLiteral.js | 4 +- src/nodes/PragmaDirective.js | 4 +- src/nodes/ReturnStatement.js | 12 +- src/nodes/RevertStatement.js | 4 +- src/nodes/SourceUnit.js | 13 +- src/nodes/StateVariableDeclaration.js | 12 +- src/nodes/StringLiteral.js | 14 +- src/nodes/StructDefinition.js | 13 +- src/nodes/ThrowStatement.js | 4 +- src/nodes/TryStatement.js | 17 +- src/nodes/TupleExpression.js | 13 +- src/nodes/TypeDefinition.js | 4 +- src/nodes/UnaryOperation.js | 4 +- src/nodes/UncheckedStatement.js | 12 +- src/nodes/UserDefinedTypeName.js | 4 +- src/nodes/UsingForDeclaration.js | 13 +- src/nodes/VariableDeclaration.js | 13 +- src/nodes/VariableDeclarationStatement.js | 17 +- src/nodes/WhileStatement.js | 13 +- src/nodes/index.js | 150 ++-- src/options.js | 2 +- src/parser.js | 10 +- src/prettier-comments/index.js | 3 - src/prettier-comments/language-js/comments.js | 35 +- src/printer.js | 10 +- tests/config/format-test.js | 62 +- tests/config/get-prettier.js | 16 + ...quire-prettier.js => require-prettier.cjs} | 0 ...e-standalone.js => require-standalone.cjs} | 20 +- tests/config/setup.js | 8 +- tests/config/utils/compile-contract.js | 16 +- tests/config/utils/consistent-end-of-line.js | 8 +- .../{create-sandbox.js => create-sandbox.cjs} | 0 tests/config/utils/create-snapshot.js | 15 +- .../utils/stringify-options-for-title.js | 4 +- tests/config/utils/visualize-end-of-line.js | 4 +- tests/config/utils/visualize-range.js | 8 +- tests/format/AddressPayable/jsfmt.spec.js | 2 +- .../format/AllSolidityFeatures/jsfmt.spec.js | 2 +- tests/format/Arrays/jsfmt.spec.js | 2 +- tests/format/Assembly/jsfmt.spec.js | 2 +- tests/format/BasicIterator/jsfmt.spec.js | 2 +- tests/format/BinaryOperators/jsfmt.spec.js | 2 +- .../BreakingChangesV0.7.4/jsfmt.spec.js | 12 +- .../BreakingChangesV0.8.0/jsfmt.spec.js | 6 +- tests/format/Comments/jsfmt.spec.js | 2 +- tests/format/Conditional/jsfmt.spec.js | 2 +- tests/format/Constructors/jsfmt.spec.js | 2 +- .../format/ContractDefinitions/jsfmt.spec.js | 2 +- tests/format/CustomErrors/jsfmt.spec.js | 2 +- tests/format/EnumDefinitions/jsfmt.spec.js | 4 +- tests/format/Etc/jsfmt.spec.js | 2 +- tests/format/ForStatements/jsfmt.spec.js | 2 +- tests/format/FunctionCalls/jsfmt.spec.js | 4 +- .../format/FunctionDefinitions/jsfmt.spec.js | 2 +- tests/format/HexLiteral/jsfmt.spec.js | 4 +- tests/format/IfStatements/jsfmt.spec.js | 2 +- tests/format/Immutable/jsfmt.spec.js | 2 +- tests/format/ImportDirective/jsfmt.spec.js | 4 +- tests/format/Inbox/jsfmt.spec.js | 2 +- tests/format/IndexOf/jsfmt.spec.js | 2 +- tests/format/IndexRangeAccess/jsfmt.spec.js | 2 +- .../format/InheritanceSpecifier/jsfmt.spec.js | 2 +- tests/format/Issues/jsfmt.spec.js | 2 +- tests/format/Libraries/jsfmt.spec.js | 4 +- tests/format/Markdown/jsfmt.spec.js | 2 +- tests/format/MemberAccess/jsfmt.spec.js | 2 +- .../format/ModifierDefinitions/jsfmt.spec.js | 2 +- .../format/ModifierInvocations/jsfmt.spec.js | 2 +- tests/format/MultipartStrings/jsfmt.spec.js | 2 +- .../format/NameValueExpression/jsfmt.spec.js | 4 +- tests/format/Ownable/jsfmt.spec.js | 2 +- tests/format/Parentheses/jsfmt.spec.js | 2 +- tests/format/Pragma/jsfmt.spec.js | 2 +- tests/format/PrettierIgnore/jsfmt.spec.js | 2 +- tests/format/Proxy/jsfmt.spec.js | 2 +- .../RespectDefaultOptions/jsfmt.spec.js | 2 +- tests/format/SampleCrowdsale/jsfmt.spec.js | 2 +- tests/format/SimpleAuction/jsfmt.spec.js | 2 +- tests/format/SimpleStorage/jsfmt.spec.js | 2 +- .../format/SplittableCommodity/jsfmt.spec.js | 2 +- .../StateVariableDeclarations/jsfmt.spec.js | 2 +- tests/format/StringLiteral/jsfmt.spec.js | 2 +- tests/format/StyleGuide/jsfmt.spec.js | 2 +- tests/format/TryCatch/jsfmt.spec.js | 2 +- tests/format/Tupples/jsfmt.spec.js | 2 +- tests/format/TypeDefinition/jsfmt.spec.js | 2 +- tests/format/WhileStatements/jsfmt.spec.js | 2 +- tests/format/WrongCompiler/jsfmt.spec.js | 6 +- tests/format/quotes/jsfmt.spec.js | 4 +- tests/format/strings/jsfmt.spec.js | 2 +- tests/unit/binary-operation.test.js | 2 +- .../binary-operator-printers/index.test.js | 2 +- tests/unit/comments/printer.test.js | 2 +- tests/unit/prettier-version.test.js | 31 - tests/unit/prettier-version/esmock-plugin.js | 18 + tests/unit/prettier-version/index.test.js | 20 + .../prettier-version/proxyquire-plugin.cjs | 14 + tests/unit/printer.test.js | 2 +- webpack.config.js | 14 +- 183 files changed, 1086 insertions(+), 1334 deletions(-) delete mode 100644 scripts/generateIndexes.js delete mode 100644 scripts/makeData.js delete mode 100644 src/prettier-comments/index.js create mode 100644 tests/config/get-prettier.js rename tests/config/{require-prettier.js => require-prettier.cjs} (100%) rename tests/config/{require-standalone.js => require-standalone.cjs} (70%) rename tests/config/utils/{create-sandbox.js => create-sandbox.cjs} (100%) delete mode 100644 tests/unit/prettier-version.test.js create mode 100644 tests/unit/prettier-version/esmock-plugin.js create mode 100644 tests/unit/prettier-version/index.test.js create mode 100644 tests/unit/prettier-version/proxyquire-plugin.cjs diff --git a/.c8rc b/.c8rc index 4951cfd9a..9db154913 100644 --- a/.c8rc +++ b/.c8rc @@ -4,7 +4,7 @@ "lines": 100, "functions": 100, "statements": 100, - "exclude": ["/node_modules/", "/scripts/", "/src/prettier-comments/"], + "exclude": ["/node_modules/", "/src/prettier-comments/"], "include": ["src/**/*.js", "!src/prettier-comments/**/*.js"], "reporter": ["lcov", "text"], "temp-dir": "./coverage/" diff --git a/.eslintignore b/.eslintignore index 1ba15282d..77cd3b23c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,5 +3,5 @@ dist/**/*.js tests/format/**/*.sol tests/format/Markdown/Markdown.md tests/format/RespectDefaultOptions/respect-default-options.js -tests/config/**/*.js +tests/config/**/*.*js src/prettier-comments/**/*.js diff --git a/.eslintrc b/.eslintrc index 8e658f2f6..eb3058129 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,5 +5,13 @@ "extends": ["airbnb-base", "prettier"], "globals": { "run_spec": false + }, + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "import/extensions": "off", + "import/prefer-default-export": "off" } } diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7d7ec0e3b..e591eb090 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -54,10 +54,8 @@ jobs: run: npm run build - name: Downgrade Prettier to V2 run: npm install prettier@2.8.8 - - name: Run tests - run: npm run test:all - name: Run standalone tests - run: npm run test:standalone + run: npm run test:standalone tests/format tests/unit/prettier-version test_linux: name: Test on Linux with Node ${{ matrix.node }} diff --git a/.npmignore b/.npmignore index a9cc408fa..bc48f1617 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,6 @@ # -*- mode: gitignore; -*- .github/ tests/ -scripts/ assets/ *.md/ !README.md diff --git a/jest.config.js b/jest.config.js index 8b92e8ad3..646bbdc5f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,6 @@ const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE); -module.exports = { +export default { runner: 'jest-light-runner', setupFiles: ['/tests/config/setup.js'], snapshotSerializers: [ @@ -19,7 +19,7 @@ module.exports = { : [], testMatch: [ '/tests/format/**/jsfmt.spec.js', - '/tests/unit/**/*.js' + '/tests/unit/**/*.test.js' ], transform: {}, watchPlugins: [ diff --git a/package-lock.json b/package-lock.json index 338e39014..291fe3c9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,30 +9,31 @@ "version": "1.1.3", "license": "MIT", "dependencies": { - "@solidity-parser/parser": "^0.16.0", + "@solidity-parser/parser": "^0.16.1", "semver": "^7.5.4", "solidity-comments-extractor": "^0.0.7" }, "devDependencies": { - "@babel/code-frame": "^7.22.5", - "c8": "^8.0.0", + "@babel/code-frame": "^7.22.10", + "c8": "^8.0.1", "cross-env": "^7.0.3", - "dir-to-object": "^2.0.0", - "eslint": "^8.44.0", + "eslint": "^8.47.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.27.5", + "eslint-plugin-import": "^2.28.1", + "esm-utils": "^4.1.2", + "esmock": "^2.3.8", "exports-loader": "^4.0.0", - "jest": "^29.6.1", + "jest": "^29.6.3", "jest-light-runner": "^0.5.0", "jest-snapshot-serializer-ansi": "^2.1.0", - "jest-snapshot-serializer-raw": "^1.2.0", + "jest-snapshot-serializer-raw": "^2.0.0", "jest-watch-typeahead": "^2.2.2", "lines-and-columns": "^2.0.3", - "prettier": "^3.0.0", + "prettier": "^3.0.2", "proxyquire": "^2.1.3", - "solc": "^0.8.20", - "webpack": "^5.88.1", + "solc": "^0.8.21", + "webpack": "^5.88.2", "webpack-cli": "^5.1.4" }, "engines": { @@ -906,16 +907,16 @@ } }, "node_modules/@jest/console": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/console/-/console-29.6.2.tgz", - "integrity": "sha512-0N0yZof5hi44HAR2pPS+ikJ3nzKNoZdVu8FffRf3wy47I7Dm7etk/3KetMdRUqzVd16V4O2m2ISpNTbnIuqy1w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/console/-/console-29.6.3.tgz", + "integrity": "sha512-ukZbHAdDH4ktZIOKvWs1juAXhiVAdvCyM8zv4S/7Ii3vJSDvMW5k+wOVGMQmHLHUFw3Ko63ZQNy7NI6PSlsD5w==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", - "jest-message-util": "^29.6.2", - "jest-util": "^29.6.2", + "jest-message-util": "^29.6.3", + "jest-util": "^29.6.3", "slash": "^3.0.0" }, "engines": { @@ -923,37 +924,37 @@ } }, "node_modules/@jest/core": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/core/-/core-29.6.2.tgz", - "integrity": "sha512-Oj+5B+sDMiMWLhPFF+4/DvHOf+U10rgvCLGPHP8Xlsy/7QxS51aU/eBngudHlJXnaWD5EohAgJ4js+T6pa+zOg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/core/-/core-29.6.3.tgz", + "integrity": "sha512-skV1XrfNxfagmjRUrk2FyN5/2YwIzdWVVBa/orUfbLvQUANXxERq2pTvY0I+FinWHjDKB2HRmpveUiph4X0TJw==", "dev": true, "dependencies": { - "@jest/console": "^29.6.2", - "@jest/reporters": "^29.6.2", - "@jest/test-result": "^29.6.2", - "@jest/transform": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/console": "^29.6.3", + "@jest/reporters": "^29.6.3", + "@jest/test-result": "^29.6.3", + "@jest/transform": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", "ansi-escapes": "^4.2.1", "chalk": "^4.0.0", "ci-info": "^3.2.0", "exit": "^0.1.2", "graceful-fs": "^4.2.9", - "jest-changed-files": "^29.5.0", - "jest-config": "^29.6.2", - "jest-haste-map": "^29.6.2", - "jest-message-util": "^29.6.2", - "jest-regex-util": "^29.4.3", - "jest-resolve": "^29.6.2", - "jest-resolve-dependencies": "^29.6.2", - "jest-runner": "^29.6.2", - "jest-runtime": "^29.6.2", - "jest-snapshot": "^29.6.2", - "jest-util": "^29.6.2", - "jest-validate": "^29.6.2", - "jest-watcher": "^29.6.2", + "jest-changed-files": "^29.6.3", + "jest-config": "^29.6.3", + "jest-haste-map": "^29.6.3", + "jest-message-util": "^29.6.3", + "jest-regex-util": "^29.6.3", + "jest-resolve": "^29.6.3", + "jest-resolve-dependencies": "^29.6.3", + "jest-runner": "^29.6.3", + "jest-runtime": "^29.6.3", + "jest-snapshot": "^29.6.3", + "jest-util": "^29.6.3", + "jest-validate": "^29.6.3", + "jest-watcher": "^29.6.3", "micromatch": "^4.0.4", - "pretty-format": "^29.6.2", + "pretty-format": "^29.6.3", "slash": "^3.0.0", "strip-ansi": "^6.0.0" }, @@ -970,88 +971,88 @@ } }, "node_modules/@jest/environment": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.6.2.tgz", - "integrity": "sha512-AEcW43C7huGd/vogTddNNTDRpO6vQ2zaQNrttvWV18ArBx9Z56h7BIsXkNFJVOO4/kblWEQz30ckw0+L3izc+Q==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.6.3.tgz", + "integrity": "sha512-u/u3cCztYCfgBiGHsamqP5x+XvucftOGPbf5RJQxfpeC1y4AL8pCjKvPDA3oCmdhZYPgk5AE0VOD/flweR69WA==", "dev": true, "dependencies": { - "@jest/fake-timers": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/fake-timers": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-mock": "^29.6.2" + "jest-mock": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/expect": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.6.2.tgz", - "integrity": "sha512-m6DrEJxVKjkELTVAztTLyS/7C92Y2b0VYqmDROYKLLALHn8T/04yPs70NADUYPrV3ruI+H3J0iUIuhkjp7vkfg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.6.3.tgz", + "integrity": "sha512-Ic08XbI2jlg6rECy+CGwk/8NDa6VE7UmIG6++9OTPAMnQmNGY28hu69Nf629CWv6T7YMODLbONxDFKdmQeI9FA==", "dev": true, "dependencies": { - "expect": "^29.6.2", - "jest-snapshot": "^29.6.2" + "expect": "^29.6.3", + "jest-snapshot": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/expect-utils": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.6.2.tgz", - "integrity": "sha512-6zIhM8go3RV2IG4aIZaZbxwpOzz3ZiM23oxAlkquOIole+G6TrbeXnykxWYlqF7kz2HlBjdKtca20x9atkEQYg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.6.3.tgz", + "integrity": "sha512-nvOEW4YoqRKD9HBJ9OJ6przvIvP9qilp5nAn1462P5ZlL/MM9SgPEZFyjTGPfs7QkocdUsJa6KjHhyRn4ueItA==", "dev": true, "dependencies": { - "jest-get-type": "^29.4.3" + "jest-get-type": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/fake-timers": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.6.2.tgz", - "integrity": "sha512-euZDmIlWjm1Z0lJ1D0f7a0/y5Kh/koLFMUBE5SUYWrmy8oNhJpbTBDAP6CxKnadcMLDoDf4waRYCe35cH6G6PA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.6.3.tgz", + "integrity": "sha512-pa1wmqvbj6eX0nMvOM2VDAWvJOI5A/Mk3l8O7n7EsAh71sMZblaKO9iT4GjIj0LwwK3CP/Jp1ypEV0x3m89RvA==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@sinonjs/fake-timers": "^10.0.2", "@types/node": "*", - "jest-message-util": "^29.6.2", - "jest-mock": "^29.6.2", - "jest-util": "^29.6.2" + "jest-message-util": "^29.6.3", + "jest-mock": "^29.6.3", + "jest-util": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/globals": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.6.2.tgz", - "integrity": "sha512-cjuJmNDjs6aMijCmSa1g2TNG4Lby/AeU7/02VtpW+SLcZXzOLK2GpN2nLqcFjmhy3B3AoPeQVx7BnyOf681bAw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.6.3.tgz", + "integrity": "sha512-RB+uI+CZMHntzlnOPlll5x/jgRff3LEPl/td/jzMXiIgR0iIhKq9qm1HLU+EC52NuoVy/1swit/sDGjVn4bc6A==", "dev": true, "dependencies": { - "@jest/environment": "^29.6.2", - "@jest/expect": "^29.6.2", - "@jest/types": "^29.6.1", - "jest-mock": "^29.6.2" + "@jest/environment": "^29.6.3", + "@jest/expect": "^29.6.3", + "@jest/types": "^29.6.3", + "jest-mock": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/reporters": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-29.6.2.tgz", - "integrity": "sha512-sWtijrvIav8LgfJZlrGCdN0nP2EWbakglJY49J1Y5QihcQLfy7ovyxxjJBRXMNltgt4uPtEcFmIMbVshEDfFWw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-29.6.3.tgz", + "integrity": "sha512-kGz59zMi0GkVjD2CJeYWG9k6cvj7eBqt9aDAqo2rcCLRTYlvQ62Gu/n+tOmJMBHGjzeijjuCENjzTyYBgrtLUw==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", - "@jest/console": "^29.6.2", - "@jest/test-result": "^29.6.2", - "@jest/transform": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/console": "^29.6.3", + "@jest/test-result": "^29.6.3", + "@jest/transform": "^29.6.3", + "@jest/types": "^29.6.3", "@jridgewell/trace-mapping": "^0.3.18", "@types/node": "*", "chalk": "^4.0.0", @@ -1060,13 +1061,13 @@ "glob": "^7.1.3", "graceful-fs": "^4.2.9", "istanbul-lib-coverage": "^3.0.0", - "istanbul-lib-instrument": "^5.1.0", + "istanbul-lib-instrument": "^6.0.0", "istanbul-lib-report": "^3.0.0", "istanbul-lib-source-maps": "^4.0.0", "istanbul-reports": "^3.1.3", - "jest-message-util": "^29.6.2", - "jest-util": "^29.6.2", - "jest-worker": "^29.6.2", + "jest-message-util": "^29.6.3", + "jest-util": "^29.6.3", + "jest-worker": "^29.6.3", "slash": "^3.0.0", "string-length": "^4.0.1", "strip-ansi": "^6.0.0", @@ -1084,10 +1085,26 @@ } } }, + "node_modules/@jest/reporters/node_modules/istanbul-lib-instrument": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-6.0.0.tgz", + "integrity": "sha512-x58orMzEVfzPUKqlbLd1hXCnySCxKdDKa6Rjg97CwuLLRI4g3FHTdnExu1OqffVFay6zeMW+T6/DowFLndWnIw==", + "dev": true, + "dependencies": { + "@babel/core": "^7.12.3", + "@babel/parser": "^7.14.7", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-coverage": "^3.2.0", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@jest/schemas": { - "version": "29.6.0", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.0.tgz", - "integrity": "sha512-rxLjXyJBTL4LQeJW3aKo0M/+GkCOXsO+8i9Iu7eDb6KwtP65ayoDsitrdPBtujxQ88k4wI2FNYfa6TOGwSn6cQ==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", "dev": true, "dependencies": { "@sinclair/typebox": "^0.27.8" @@ -1097,9 +1114,9 @@ } }, "node_modules/@jest/source-map": { - "version": "29.6.0", - "resolved": "https://registry.npmjs.org/@jest/source-map/-/source-map-29.6.0.tgz", - "integrity": "sha512-oA+I2SHHQGxDCZpbrsCQSoMLb3Bz547JnM+jUr9qEbuw0vQlWZfpPS7CO9J7XiwKicEz9OFn/IYoLkkiUD7bzA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/source-map/-/source-map-29.6.3.tgz", + "integrity": "sha512-MHjT95QuipcPrpLM+8JMSzFx6eHp5Bm+4XeFDJlwsvVBjmKNiIAvasGK2fxz2WbGRlnvqehFbh07MMa7n3YJnw==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.18", @@ -1111,13 +1128,13 @@ } }, "node_modules/@jest/test-result": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-29.6.2.tgz", - "integrity": "sha512-3VKFXzcV42EYhMCsJQURptSqnyjqCGbtLuX5Xxb6Pm6gUf1wIRIl+mandIRGJyWKgNKYF9cnstti6Ls5ekduqw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-29.6.3.tgz", + "integrity": "sha512-k7ZZaNvOSMBHPZYiy0kuiaFoyansR5QnTwDux1EjK3kD5iWpRVyJIJ0RAIV39SThafchuW59vra7F8mdy5Hfgw==", "dev": true, "dependencies": { - "@jest/console": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/console": "^29.6.3", + "@jest/types": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "collect-v8-coverage": "^1.0.0" }, @@ -1126,14 +1143,14 @@ } }, "node_modules/@jest/test-sequencer": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-29.6.2.tgz", - "integrity": "sha512-GVYi6PfPwVejO7slw6IDO0qKVum5jtrJ3KoLGbgBWyr2qr4GaxFV6su+ZAjdTX75Sr1DkMFRk09r2ZVa+wtCGw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-29.6.3.tgz", + "integrity": "sha512-/SmijaAU2TY9ComFGIYa6Z+fmKqQMnqs2Nmwb0P/Z/tROdZ7M0iruES1EaaU9PBf8o9uED5xzaJ3YPFEIcDgAg==", "dev": true, "dependencies": { - "@jest/test-result": "^29.6.2", + "@jest/test-result": "^29.6.3", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.6.2", + "jest-haste-map": "^29.6.3", "slash": "^3.0.0" }, "engines": { @@ -1141,22 +1158,22 @@ } }, "node_modules/@jest/transform": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.6.2.tgz", - "integrity": "sha512-ZqCqEISr58Ce3U+buNFJYUktLJZOggfyvR+bZMaiV1e8B1SIvJbwZMrYz3gx/KAPn9EXmOmN+uB08yLCjWkQQg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.6.3.tgz", + "integrity": "sha512-dPIc3DsvMZ/S8ut4L2ViCj265mKO0owB0wfzBv2oGzL9pQ+iRvJewHqLBmsGb7XFb5UotWIEtvY5A/lnylaIoQ==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@jridgewell/trace-mapping": "^0.3.18", "babel-plugin-istanbul": "^6.1.1", "chalk": "^4.0.0", "convert-source-map": "^2.0.0", "fast-json-stable-stringify": "^2.1.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.6.2", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.6.2", + "jest-haste-map": "^29.6.3", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.6.3", "micromatch": "^4.0.4", "pirates": "^4.0.4", "slash": "^3.0.0", @@ -1173,12 +1190,12 @@ "dev": true }, "node_modules/@jest/types": { - "version": "29.6.1", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.1.tgz", - "integrity": "sha512-tPKQNMPuXgvdOn2/Lg9HNfUvjYVGolt04Hp03f5hAk878uwOLikN+JzeLY0HcVgKgFl9Hs3EIqpu3WX27XNhnw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", "dev": true, "dependencies": { - "@jest/schemas": "^29.6.0", + "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", @@ -1298,27 +1315,27 @@ "dev": true }, "node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", + "integrity": "sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==", "dev": true, "dependencies": { "type-detect": "4.0.8" } }, "node_modules/@sinonjs/fake-timers": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.0.2.tgz", - "integrity": "sha512-SwUDyjWnah1AaNl7kxsa7cfLhlTYoiyhDAIgyh+El30YvXs/o7OLXpYH88Zdhyx9JExKrmHDJ+10bwIcY80Jmw==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", "dev": true, "dependencies": { - "@sinonjs/commons": "^2.0.0" + "@sinonjs/commons": "^3.0.0" } }, "node_modules/@solidity-parser/parser": { - "version": "0.16.0", - "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.16.0.tgz", - "integrity": "sha512-ESipEcHyRHg4Np4SqBCfcXwyxxna1DgFVz69bgpLV8vzl/NP1DtcKsJ4dJZXWQhY/Z4J2LeKBiOkOVZn9ct33Q==", + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.16.1.tgz", + "integrity": "sha512-PdhRFNhbTtu3x8Axm0uYpqOy/lODYQK+MlYSgqIsq2L8SFYEHJPHNUiOTAJbDGzNjjr1/n9AcIayxafR/fWmYw==", "dependencies": { "antlr4ts": "^0.5.0-alpha.4" } @@ -1935,15 +1952,15 @@ } }, "node_modules/babel-jest": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.6.2.tgz", - "integrity": "sha512-BYCzImLos6J3BH/+HvUCHG1dTf2MzmAB4jaVxHV+29RZLjR29XuYTmsf2sdDwkrb+FczkGo3kOhE7ga6sI0P4A==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.6.3.tgz", + "integrity": "sha512-1Ne93zZZEy5XmTa4Q+W5+zxBrDpExX8E3iy+xJJ+24ewlfo/T3qHfQJCzi/MMVFmBQDNxtRR/Gfd2dwb/0yrQw==", "dev": true, "dependencies": { - "@jest/transform": "^29.6.2", + "@jest/transform": "^29.6.3", "@types/babel__core": "^7.1.14", "babel-plugin-istanbul": "^6.1.1", - "babel-preset-jest": "^29.5.0", + "babel-preset-jest": "^29.6.3", "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "slash": "^3.0.0" @@ -1972,9 +1989,9 @@ } }, "node_modules/babel-plugin-jest-hoist": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-29.5.0.tgz", - "integrity": "sha512-zSuuuAlTMT4mzLj2nPnUm6fsE6270vdOfnpbJ+RmruU75UhLFvL0N2NgI7xpeS7NaB6hGqmd5pVpGTDYvi4Q3w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-29.6.3.tgz", + "integrity": "sha512-ESAc/RJvGTFEzRwOTT4+lNDk/GNHMkKbNzsvT0qKRfDyyYTskxB5rnU2njIDYVxXCBHHEI1c0YwHob3WaYujOg==", "dev": true, "dependencies": { "@babel/template": "^7.3.3", @@ -2010,12 +2027,12 @@ } }, "node_modules/babel-preset-jest": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-29.5.0.tgz", - "integrity": "sha512-JOMloxOqdiBSxMAzjRaH023/vvcaSaec49zvg+2LmNsktC7ei39LTJGw02J+9uUtTZUq6xbLyJ4dxe9sSmIuAg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-29.6.3.tgz", + "integrity": "sha512-0B3bhxR6snWXJZtR/RliHTDPRgn1sNHOR0yVtq/IiQFyuOVjFS+wuio/R4gSNkyYmKmJB4wGZv2NZanmKmTnNA==", "dev": true, "dependencies": { - "babel-plugin-jest-hoist": "^29.5.0", + "babel-plugin-jest-hoist": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0" }, "engines": { @@ -2448,20 +2465,14 @@ } }, "node_modules/diff-sequences": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.4.3.tgz", - "integrity": "sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/dir-to-object": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dir-to-object/-/dir-to-object-2.0.0.tgz", - "integrity": "sha512-sXs0JKIhymON7T1UZuO2Ud6VTNAx/VTBXIl4+3mjb2RgfOpt+hectX0x04YqPOPdkeOAKoJuKqwqnXXURNPNEA==", - "dev": true - }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -2875,6 +2886,28 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/esm-utils": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/esm-utils/-/esm-utils-4.1.2.tgz", + "integrity": "sha512-hYKPzOCkAU11rMIiH6gvvReARaSLiRhJkGWPcwJB/S4zg7em//YKAcRxwZYw4sW5mRmI6lhV59wWWTdWKwOXvQ==", + "dev": true, + "dependencies": { + "import-meta-resolve": "2.2.2", + "url-or-path": "2.1.0" + }, + "funding": { + "url": "https://github.com/fisker/esm-utils?sponsor=1" + } + }, + "node_modules/esmock": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/esmock/-/esmock-2.3.8.tgz", + "integrity": "sha512-gZWoIwwo4Aa/kGgzqel7O1v4mlDiHS5fLdi4n26nOmizRUHDSbj1U5JF+XLHgYJvIUbJMZLVKIAqL3paBc16hQ==", + "dev": true, + "engines": { + "node": ">=14.16.0" + } + }, "node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", @@ -2995,17 +3028,16 @@ } }, "node_modules/expect": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/expect/-/expect-29.6.2.tgz", - "integrity": "sha512-iAErsLxJ8C+S02QbLAwgSGSezLQK+XXRDt8IuFXFpwCNw2ECmzZSmjKcCaFVp5VRMk+WAvz6h6jokzEzBFZEuA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/expect/-/expect-29.6.3.tgz", + "integrity": "sha512-x1vY4LlEMWUYVZQrFi4ZANXFwqYbJ/JNQspLVvzhW2BNY28aNcXMQH6imBbt+RBf5sVRTodYHXtSP/TLEU0Dxw==", "dev": true, "dependencies": { - "@jest/expect-utils": "^29.6.2", - "@types/node": "*", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.6.2", - "jest-message-util": "^29.6.2", - "jest-util": "^29.6.2" + "@jest/expect-utils": "^29.6.3", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.6.3", + "jest-message-util": "^29.6.3", + "jest-util": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -3576,6 +3608,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/import-meta-resolve": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-2.2.2.tgz", + "integrity": "sha512-f8KcQ1D80V7RnqVm+/lirO9zkOxjGxhaTC1IPrBGd3MEfNgmNG67tSUO9gTi2F3Blr2Az6g1vocaxzkVnWl9MA==", + "dev": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -4010,15 +4052,15 @@ } }, "node_modules/jest": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest/-/jest-29.6.2.tgz", - "integrity": "sha512-8eQg2mqFbaP7CwfsTpCxQ+sHzw1WuNWL5UUvjnWP4hx2riGz9fPSzYOaU5q8/GqWn1TfgZIVTqYJygbGbWAANg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest/-/jest-29.6.3.tgz", + "integrity": "sha512-alueLuoPCDNHFcFGmgETR4KpQ+0ff3qVaiJwxQM4B5sC0CvXcgg4PEi7xrDkxuItDmdz/FVc7SSit4KEu8GRvw==", "dev": true, "dependencies": { - "@jest/core": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/core": "^29.6.3", + "@jest/types": "^29.6.3", "import-local": "^3.0.2", - "jest-cli": "^29.6.2" + "jest-cli": "^29.6.3" }, "bin": { "jest": "bin/jest.js" @@ -4036,12 +4078,13 @@ } }, "node_modules/jest-changed-files": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-29.5.0.tgz", - "integrity": "sha512-IFG34IUMUaNBIxjQXF/iu7g6EcdMrGRRxaUSw92I/2g2YC6vCdTltl4nHvt7Ci5nSJwXIkCu8Ka1DKF+X7Z1Ag==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-29.6.3.tgz", + "integrity": "sha512-G5wDnElqLa4/c66ma5PG9eRjE342lIbF6SUnTJi26C3J28Fv2TVY2rOyKB9YGbSA5ogwevgmxc4j4aVjrEK6Yg==", "dev": true, "dependencies": { "execa": "^5.0.0", + "jest-util": "^29.6.3", "p-limit": "^3.1.0" }, "engines": { @@ -4049,28 +4092,28 @@ } }, "node_modules/jest-circus": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-29.6.2.tgz", - "integrity": "sha512-G9mN+KOYIUe2sB9kpJkO9Bk18J4dTDArNFPwoZ7WKHKel55eKIS/u2bLthxgojwlf9NLCVQfgzM/WsOVvoC6Fw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-29.6.3.tgz", + "integrity": "sha512-p0R5YqZEMnOpHqHLWRSjm2z/0p6RNsrNE/GRRT3eli8QGOAozj6Ys/3Tv+Ej+IfltJoSPwcQ6/hOCRkNlxLLCw==", "dev": true, "dependencies": { - "@jest/environment": "^29.6.2", - "@jest/expect": "^29.6.2", - "@jest/test-result": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/environment": "^29.6.3", + "@jest/expect": "^29.6.3", + "@jest/test-result": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "co": "^4.6.0", "dedent": "^1.0.0", "is-generator-fn": "^2.0.0", - "jest-each": "^29.6.2", - "jest-matcher-utils": "^29.6.2", - "jest-message-util": "^29.6.2", - "jest-runtime": "^29.6.2", - "jest-snapshot": "^29.6.2", - "jest-util": "^29.6.2", + "jest-each": "^29.6.3", + "jest-matcher-utils": "^29.6.3", + "jest-message-util": "^29.6.3", + "jest-runtime": "^29.6.3", + "jest-snapshot": "^29.6.3", + "jest-util": "^29.6.3", "p-limit": "^3.1.0", - "pretty-format": "^29.6.2", + "pretty-format": "^29.6.3", "pure-rand": "^6.0.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" @@ -4080,21 +4123,21 @@ } }, "node_modules/jest-cli": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.6.2.tgz", - "integrity": "sha512-TT6O247v6dCEX2UGHGyflMpxhnrL0DNqP2fRTKYm3nJJpCTfXX3GCMQPGFjXDoj0i5/Blp3jriKXFgdfmbYB6Q==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.6.3.tgz", + "integrity": "sha512-KuPdXUPXQIf0t6DvmG8MV4QyhcjR1a6ruKl3YL7aGn/AQ8JkROwFkWzEpDIpt11Qy188dHbRm8WjwMsV/4nmnQ==", "dev": true, "dependencies": { - "@jest/core": "^29.6.2", - "@jest/test-result": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/core": "^29.6.3", + "@jest/test-result": "^29.6.3", + "@jest/types": "^29.6.3", "chalk": "^4.0.0", "exit": "^0.1.2", "graceful-fs": "^4.2.9", "import-local": "^3.0.2", - "jest-config": "^29.6.2", - "jest-util": "^29.6.2", - "jest-validate": "^29.6.2", + "jest-config": "^29.6.3", + "jest-util": "^29.6.3", + "jest-validate": "^29.6.3", "prompts": "^2.0.1", "yargs": "^17.3.1" }, @@ -4114,31 +4157,31 @@ } }, "node_modules/jest-config": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-29.6.2.tgz", - "integrity": "sha512-VxwFOC8gkiJbuodG9CPtMRjBUNZEHxwfQXmIudSTzFWxaci3Qub1ddTRbFNQlD/zUeaifLndh/eDccFX4wCMQw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-29.6.3.tgz", + "integrity": "sha512-nb9bOq2aEqogbyL4F9mLkAeQGAgNt7Uz6U59YtQDIxFPiL7Ejgq0YIrp78oyEHD6H4CIV/k7mFrK7eFDzUJ69w==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", - "@jest/test-sequencer": "^29.6.2", - "@jest/types": "^29.6.1", - "babel-jest": "^29.6.2", + "@jest/test-sequencer": "^29.6.3", + "@jest/types": "^29.6.3", + "babel-jest": "^29.6.3", "chalk": "^4.0.0", "ci-info": "^3.2.0", "deepmerge": "^4.2.2", "glob": "^7.1.3", "graceful-fs": "^4.2.9", - "jest-circus": "^29.6.2", - "jest-environment-node": "^29.6.2", - "jest-get-type": "^29.4.3", - "jest-regex-util": "^29.4.3", - "jest-resolve": "^29.6.2", - "jest-runner": "^29.6.2", - "jest-util": "^29.6.2", - "jest-validate": "^29.6.2", + "jest-circus": "^29.6.3", + "jest-environment-node": "^29.6.3", + "jest-get-type": "^29.6.3", + "jest-regex-util": "^29.6.3", + "jest-resolve": "^29.6.3", + "jest-runner": "^29.6.3", + "jest-util": "^29.6.3", + "jest-validate": "^29.6.3", "micromatch": "^4.0.4", "parse-json": "^5.2.0", - "pretty-format": "^29.6.2", + "pretty-format": "^29.6.3", "slash": "^3.0.0", "strip-json-comments": "^3.1.1" }, @@ -4159,24 +4202,24 @@ } }, "node_modules/jest-diff": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.6.2.tgz", - "integrity": "sha512-t+ST7CB9GX5F2xKwhwCf0TAR17uNDiaPTZnVymP9lw0lssa9vG+AFyDZoeIHStU3WowFFwT+ky+er0WVl2yGhA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.6.3.tgz", + "integrity": "sha512-3sw+AdWnwH9sSNohMRKA7JiYUJSRr/WS6+sEFfBuhxU5V5GlEVKfvUn8JuMHE0wqKowemR1C2aHy8VtXbaV8dQ==", "dev": true, "dependencies": { "chalk": "^4.0.0", - "diff-sequences": "^29.4.3", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.6.2" + "diff-sequences": "^29.6.3", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-docblock": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-29.4.3.tgz", - "integrity": "sha512-fzdTftThczeSD9nZ3fzA/4KkHtnmllawWrXO69vtI+L9WjEIuXWs4AmyME7lN5hU7dB0sHhuPfcKofRsUb/2Fg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-29.6.3.tgz", + "integrity": "sha512-2+H+GOTQBEm2+qFSQ7Ma+BvyV+waiIFxmZF5LdpBsAEjWX8QYjSCa4FrkIYtbfXUJJJnFCYrOtt6TZ+IAiTjBQ==", "dev": true, "dependencies": { "detect-newline": "^3.0.0" @@ -4186,62 +4229,62 @@ } }, "node_modules/jest-each": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-29.6.2.tgz", - "integrity": "sha512-MsrsqA0Ia99cIpABBc3izS1ZYoYfhIy0NNWqPSE0YXbQjwchyt6B1HD2khzyPe1WiJA7hbxXy77ZoUQxn8UlSw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-29.6.3.tgz", + "integrity": "sha512-KoXfJ42k8cqbkfshW7sSHcdfnv5agDdHCPA87ZBdmHP+zJstTJc0ttQaJ/x7zK6noAL76hOuTIJ6ZkQRS5dcyg==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "chalk": "^4.0.0", - "jest-get-type": "^29.4.3", - "jest-util": "^29.6.2", - "pretty-format": "^29.6.2" + "jest-get-type": "^29.6.3", + "jest-util": "^29.6.3", + "pretty-format": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-environment-node": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.6.2.tgz", - "integrity": "sha512-YGdFeZ3T9a+/612c5mTQIllvWkddPbYcN2v95ZH24oWMbGA4GGS2XdIF92QMhUhvrjjuQWYgUGW2zawOyH63MQ==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.6.3.tgz", + "integrity": "sha512-PKl7upfPJXMYbWpD+60o4HP86KvFO2c9dZ+Zr6wUzsG5xcPx/65o3ArNgHW5M0RFvLYdW4/aieR4JSooD0a2ew==", "dev": true, "dependencies": { - "@jest/environment": "^29.6.2", - "@jest/fake-timers": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/environment": "^29.6.3", + "@jest/fake-timers": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-mock": "^29.6.2", - "jest-util": "^29.6.2" + "jest-mock": "^29.6.3", + "jest-util": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-get-type": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz", - "integrity": "sha512-J5Xez4nRRMjk8emnTpWrlkyb9pfRQQanDrvWHhsR1+VUfbwxi30eVcZFlcdGInRibU4G5LwHXpI7IRHU0CY+gg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", + "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", "dev": true, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-haste-map": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.6.2.tgz", - "integrity": "sha512-+51XleTDAAysvU8rT6AnS1ZJ+WHVNqhj1k6nTvN2PYP+HjU3kqlaKQ1Lnw3NYW3bm2r8vq82X0Z1nDDHZMzHVA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.6.3.tgz", + "integrity": "sha512-GecR5YavfjkhOytEFHAeI6aWWG3f/cOKNB1YJvj/B76xAmeVjy4zJUYobGF030cRmKaO1FBw3V8CZZ6KVh9ZSw==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@types/graceful-fs": "^4.1.3", "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", "graceful-fs": "^4.2.9", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.6.2", - "jest-worker": "^29.6.2", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.6.3", + "jest-worker": "^29.6.3", "micromatch": "^4.0.4", "walker": "^1.0.8" }, @@ -4253,13 +4296,13 @@ } }, "node_modules/jest-leak-detector": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.6.2.tgz", - "integrity": "sha512-aNqYhfp5uYEO3tdWMb2bfWv6f0b4I0LOxVRpnRLAeque2uqOVVMLh6khnTcE2qJ5wAKop0HcreM1btoysD6bPQ==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.6.3.tgz", + "integrity": "sha512-0kfbESIHXYdhAdpLsW7xdwmYhLf1BRu4AA118/OxFm0Ho1b2RcTmO4oF6aAMaxpxdxnJ3zve2rgwzNBD4Zbm7Q==", "dev": true, "dependencies": { - "jest-get-type": "^29.4.3", - "pretty-format": "^29.6.2" + "jest-get-type": "^29.6.3", + "pretty-format": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -4300,33 +4343,33 @@ } }, "node_modules/jest-matcher-utils": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.6.2.tgz", - "integrity": "sha512-4LiAk3hSSobtomeIAzFTe+N8kL6z0JtF3n6I4fg29iIW7tt99R7ZcIFW34QkX+DuVrf+CUe6wuVOpm7ZKFJzZQ==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.6.3.tgz", + "integrity": "sha512-6ZrMYINZdwduSt5Xu18/n49O1IgXdjsfG7NEZaQws9k69eTKWKcVbJBw/MZsjOZe2sSyJFmuzh8042XWwl54Zg==", "dev": true, "dependencies": { "chalk": "^4.0.0", - "jest-diff": "^29.6.2", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.6.2" + "jest-diff": "^29.6.3", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-message-util": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.6.2.tgz", - "integrity": "sha512-vnIGYEjoPSuRqV8W9t+Wow95SDp6KPX2Uf7EoeG9G99J2OVh7OSwpS4B6J0NfpEIpfkBNHlBZpA2rblEuEFhZQ==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.6.3.tgz", + "integrity": "sha512-FtzaEEHzjDpQp51HX4UMkPZjy46ati4T5pEMyM6Ik48ztu4T9LQplZ6OsimHx7EuM9dfEh5HJa6D3trEftu3dA==", "dev": true, "dependencies": { "@babel/code-frame": "^7.12.13", - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@types/stack-utils": "^2.0.0", "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "micromatch": "^4.0.4", - "pretty-format": "^29.6.2", + "pretty-format": "^29.6.3", "slash": "^3.0.0", "stack-utils": "^2.0.3" }, @@ -4335,14 +4378,14 @@ } }, "node_modules/jest-mock": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.6.2.tgz", - "integrity": "sha512-hoSv3lb3byzdKfwqCuT6uTscan471GUECqgNYykg6ob0yiAw3zYc7OrPnI9Qv8Wwoa4lC7AZ9hyS4AiIx5U2zg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.6.3.tgz", + "integrity": "sha512-Z7Gs/mOyTSR4yPsaZ72a/MtuK6RnC3JYqWONe48oLaoEcYwEDxqvbXz85G4SJrm2Z5Ar9zp6MiHF4AlFlRM4Pg==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-util": "^29.6.2" + "jest-util": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -4366,26 +4409,26 @@ } }, "node_modules/jest-regex-util": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.4.3.tgz", - "integrity": "sha512-O4FglZaMmWXbGHSQInfXewIsd1LMn9p3ZXB/6r4FOkyhX2/iP/soMG98jGvk/A3HAN78+5VWcBGO0BJAPRh4kg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz", + "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==", "dev": true, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-resolve": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-29.6.2.tgz", - "integrity": "sha512-G/iQUvZWI5e3SMFssc4ug4dH0aZiZpsDq9o1PtXTV1210Ztyb2+w+ZgQkB3iOiC5SmAEzJBOHWz6Hvrd+QnNPw==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-29.6.3.tgz", + "integrity": "sha512-WMXwxhvzDeA/J+9jz1i8ZKGmbw/n+s988EiUvRI4egM+eTn31Hb5v10Re3slG3/qxntkBt2/6GkQVDGu6Bwyhw==", "dev": true, "dependencies": { "chalk": "^4.0.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.6.2", + "jest-haste-map": "^29.6.3", "jest-pnp-resolver": "^1.2.2", - "jest-util": "^29.6.2", - "jest-validate": "^29.6.2", + "jest-util": "^29.6.3", + "jest-validate": "^29.6.3", "resolve": "^1.20.0", "resolve.exports": "^2.0.0", "slash": "^3.0.0" @@ -4395,43 +4438,43 @@ } }, "node_modules/jest-resolve-dependencies": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-29.6.2.tgz", - "integrity": "sha512-LGqjDWxg2fuQQm7ypDxduLu/m4+4Lb4gczc13v51VMZbVP5tSBILqVx8qfWcsdP8f0G7aIqByIALDB0R93yL+w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-29.6.3.tgz", + "integrity": "sha512-iah5nhSPTwtUV7yzpTc9xGg8gP3Ch2VNsuFMsKoCkNCrQSbFtx5KRPemmPJ32AUhTSDqJXB6djPN6zAaUGV53g==", "dev": true, "dependencies": { - "jest-regex-util": "^29.4.3", - "jest-snapshot": "^29.6.2" + "jest-regex-util": "^29.6.3", + "jest-snapshot": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-runner": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-29.6.2.tgz", - "integrity": "sha512-wXOT/a0EspYgfMiYHxwGLPCZfC0c38MivAlb2lMEAlwHINKemrttu1uSbcGbfDV31sFaPWnWJPmb2qXM8pqZ4w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-29.6.3.tgz", + "integrity": "sha512-E4zsMhQnjhirFPhDTJgoLMWUrVCDij/KGzWlbslDHGuO8Hl2pVUfOiygMzVZtZq+BzmlqwEr7LYmW+WFLlmX8w==", "dev": true, "dependencies": { - "@jest/console": "^29.6.2", - "@jest/environment": "^29.6.2", - "@jest/test-result": "^29.6.2", - "@jest/transform": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/console": "^29.6.3", + "@jest/environment": "^29.6.3", + "@jest/test-result": "^29.6.3", + "@jest/transform": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "emittery": "^0.13.1", "graceful-fs": "^4.2.9", - "jest-docblock": "^29.4.3", - "jest-environment-node": "^29.6.2", - "jest-haste-map": "^29.6.2", - "jest-leak-detector": "^29.6.2", - "jest-message-util": "^29.6.2", - "jest-resolve": "^29.6.2", - "jest-runtime": "^29.6.2", - "jest-util": "^29.6.2", - "jest-watcher": "^29.6.2", - "jest-worker": "^29.6.2", + "jest-docblock": "^29.6.3", + "jest-environment-node": "^29.6.3", + "jest-haste-map": "^29.6.3", + "jest-leak-detector": "^29.6.3", + "jest-message-util": "^29.6.3", + "jest-resolve": "^29.6.3", + "jest-runtime": "^29.6.3", + "jest-util": "^29.6.3", + "jest-watcher": "^29.6.3", + "jest-worker": "^29.6.3", "p-limit": "^3.1.0", "source-map-support": "0.5.13" }, @@ -4450,31 +4493,31 @@ } }, "node_modules/jest-runtime": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.6.2.tgz", - "integrity": "sha512-2X9dqK768KufGJyIeLmIzToDmsN0m7Iek8QNxRSI/2+iPFYHF0jTwlO3ftn7gdKd98G/VQw9XJCk77rbTGZnJg==", - "dev": true, - "dependencies": { - "@jest/environment": "^29.6.2", - "@jest/fake-timers": "^29.6.2", - "@jest/globals": "^29.6.2", - "@jest/source-map": "^29.6.0", - "@jest/test-result": "^29.6.2", - "@jest/transform": "^29.6.2", - "@jest/types": "^29.6.1", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.6.3.tgz", + "integrity": "sha512-VM0Z3a9xaqizGpEKwCOIhImkrINYzxgwk8oQAvrmAiXX8LNrJrRjyva30RkuRY0ETAotHLlUcd2moviCA1hgsQ==", + "dev": true, + "dependencies": { + "@jest/environment": "^29.6.3", + "@jest/fake-timers": "^29.6.3", + "@jest/globals": "^29.6.3", + "@jest/source-map": "^29.6.3", + "@jest/test-result": "^29.6.3", + "@jest/transform": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "cjs-module-lexer": "^1.0.0", "collect-v8-coverage": "^1.0.0", "glob": "^7.1.3", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.6.2", - "jest-message-util": "^29.6.2", - "jest-mock": "^29.6.2", - "jest-regex-util": "^29.4.3", - "jest-resolve": "^29.6.2", - "jest-snapshot": "^29.6.2", - "jest-util": "^29.6.2", + "jest-haste-map": "^29.6.3", + "jest-message-util": "^29.6.3", + "jest-mock": "^29.6.3", + "jest-regex-util": "^29.6.3", + "jest-resolve": "^29.6.3", + "jest-snapshot": "^29.6.3", + "jest-util": "^29.6.3", "slash": "^3.0.0", "strip-bom": "^4.0.0" }, @@ -4492,9 +4535,9 @@ } }, "node_modules/jest-snapshot": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.6.2.tgz", - "integrity": "sha512-1OdjqvqmRdGNvWXr/YZHuyhh5DeaLp1p/F8Tht/MrMw4Kr1Uu/j4lRG+iKl1DAqUJDWxtQBMk41Lnf/JETYBRA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.6.3.tgz", + "integrity": "sha512-66Iu7H1ojiveQMGFnKecHIZPPPBjZwfQEnF6wxqpxGf57sV3YSUtAb5/sTKM5TPa3OndyxZp1wxHFbmgVhc53w==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", @@ -4502,20 +4545,20 @@ "@babel/plugin-syntax-jsx": "^7.7.2", "@babel/plugin-syntax-typescript": "^7.7.2", "@babel/types": "^7.3.3", - "@jest/expect-utils": "^29.6.2", - "@jest/transform": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/expect-utils": "^29.6.3", + "@jest/transform": "^29.6.3", + "@jest/types": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0", "chalk": "^4.0.0", - "expect": "^29.6.2", + "expect": "^29.6.3", "graceful-fs": "^4.2.9", - "jest-diff": "^29.6.2", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.6.2", - "jest-message-util": "^29.6.2", - "jest-util": "^29.6.2", + "jest-diff": "^29.6.3", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.6.3", + "jest-message-util": "^29.6.3", + "jest-util": "^29.6.3", "natural-compare": "^1.4.0", - "pretty-format": "^29.6.2", + "pretty-format": "^29.6.3", "semver": "^7.5.3" }, "engines": { @@ -4551,21 +4594,21 @@ } }, "node_modules/jest-snapshot-serializer-raw": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/jest-snapshot-serializer-raw/-/jest-snapshot-serializer-raw-1.2.0.tgz", - "integrity": "sha512-Cnp2u7GkaXBVOOelhU94x6Kb/10WJjQtgKDvqynnYGNGQlKBj06x8QZmRkL8XWWVLQ5DKA2fT5rY9kRd512JcA==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jest-snapshot-serializer-raw/-/jest-snapshot-serializer-raw-2.0.0.tgz", + "integrity": "sha512-E/gWFBAltOPQVAvafH/zYkob3G/TqL/DFG3fHurinwLcFRkz6kASjuihyJJ6zoizlLUNaiOdS3v5ZflTvifpBA==", "dev": true, "engines": { - "node": ">= 4" + "node": ">=16" } }, "node_modules/jest-util": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.6.2.tgz", - "integrity": "sha512-3eX1qb6L88lJNCFlEADKOkjpXJQyZRiavX1INZ4tRnrBVr2COd3RgcTLyUiEXMNBlDU/cgYq6taUS0fExrWW4w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.6.3.tgz", + "integrity": "sha512-QUjna/xSy4B32fzcKTSz1w7YYzgiHrjjJjevdRf61HYk998R5vVMMNmrHESYZVDS5DSWs+1srPLPKxXPkeSDOA==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "ci-info": "^3.2.0", @@ -4577,17 +4620,17 @@ } }, "node_modules/jest-validate": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.6.2.tgz", - "integrity": "sha512-vGz0yMN5fUFRRbpJDPwxMpgSXW1LDKROHfBopAvDcmD6s+B/s8WJrwi+4bfH4SdInBA5C3P3BI19dBtKzx1Arg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.6.3.tgz", + "integrity": "sha512-e7KWZcAIX+2W1o3cHfnqpGajdCs1jSM3DkXjGeLSNmCazv1EeI1ggTeK5wdZhF+7N+g44JI2Od3veojoaumlfg==", "dev": true, "dependencies": { - "@jest/types": "^29.6.1", + "@jest/types": "^29.6.3", "camelcase": "^6.2.0", "chalk": "^4.0.0", - "jest-get-type": "^29.4.3", + "jest-get-type": "^29.6.3", "leven": "^3.1.0", - "pretty-format": "^29.6.2" + "pretty-format": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -4718,18 +4761,18 @@ } }, "node_modules/jest-watcher": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-29.6.2.tgz", - "integrity": "sha512-GZitlqkMkhkefjfN/p3SJjrDaxPflqxEAv3/ik10OirZqJGYH5rPiIsgVcfof0Tdqg3shQGdEIxDBx+B4tuLzA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-29.6.3.tgz", + "integrity": "sha512-NgpFjZ2U2MKusjidbi4Oiu7tfs+nrgdIxIEVROvH1cFmOei9Uj25lwkMsakqLnH/s0nEcvxO1ck77FiRlcnpZg==", "dev": true, "dependencies": { - "@jest/test-result": "^29.6.2", - "@jest/types": "^29.6.1", + "@jest/test-result": "^29.6.3", + "@jest/types": "^29.6.3", "@types/node": "*", "ansi-escapes": "^4.2.1", "chalk": "^4.0.0", "emittery": "^0.13.1", - "jest-util": "^29.6.2", + "jest-util": "^29.6.3", "string-length": "^4.0.1" }, "engines": { @@ -4737,13 +4780,13 @@ } }, "node_modules/jest-worker": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.6.2.tgz", - "integrity": "sha512-l3ccBOabTdkng8I/ORCkADz4eSMKejTYv1vB/Z83UiubqhC1oQ5Li6dWCyqOIvSifGjUBxuvxvlm6KGK2DtuAQ==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.6.3.tgz", + "integrity": "sha512-wacANXecZ/GbQakpf2CClrqrlwsYYDSXFd4fIGdL+dXpM2GWoJ+6bhQ7vR3TKi3+gkSfBkjy1/khH/WrYS4Q6g==", "dev": true, "dependencies": { "@types/node": "*", - "jest-util": "^29.6.2", + "jest-util": "^29.6.3", "merge-stream": "^2.0.0", "supports-color": "^8.0.0" }, @@ -5516,12 +5559,12 @@ } }, "node_modules/pretty-format": { - "version": "29.6.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.6.2.tgz", - "integrity": "sha512-1q0oC8eRveTg5nnBEWMXAU2qpv65Gnuf2eCQzSjxpWFkPaPARwqZZDGuNE0zPAZfTCHzIk3A8dIjwlQKKLphyg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.6.3.tgz", + "integrity": "sha512-ZsBgjVhFAj5KeK+nHfF1305/By3lechHQSMWCTl8iHSbfOm2TN5nHEtFc/+W7fAyUeCs2n5iow72gld4gW0xDw==", "dev": true, "dependencies": { - "@jest/schemas": "^29.6.0", + "@jest/schemas": "^29.6.3", "ansi-styles": "^5.0.0", "react-is": "^18.0.0" }, @@ -6492,6 +6535,15 @@ "punycode": "^2.1.0" } }, + "node_modules/url-or-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/url-or-path/-/url-or-path-2.1.0.tgz", + "integrity": "sha512-dsBD6GbytSMj9YDb3jVzSRENwFh50oUORnWBeSHfo0Lnwv2KMm/J4npyGy1P9rivUPsUGLjTA53XqAFqpe0nww==", + "dev": true, + "funding": { + "url": "https://github.com/fisker/url-or-path?sponsor=1" + } + }, "node_modules/v8-to-istanbul": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz", diff --git a/package.json b/package.json index ce7bf3fc3..9e4136768 100644 --- a/package.json +++ b/package.json @@ -2,27 +2,29 @@ "name": "prettier-plugin-solidity", "version": "1.1.3", "description": "A Prettier Plugin for automatically formatting your Solidity code.", + "type": "module", "main": "./src/index.js", - "browser": "./dist/standalone.js", - "unpkg": "./dist/standalone.js", + "browser": "./dist/standalone.cjs", + "unpkg": "./dist/standalone.cjs", + "exports": { + "import": "./src/index.js", + "require": "./dist/standalone.cjs" + }, "scripts": { "build": "webpack --env production", "build:dev": "webpack --env development", - "eslint": "eslint 'scripts/**' 'src/**' 'tests/**'", - "generateindexes": "cross-env SCRIPT=true node scripts/generateIndexes.js", + "eslint": "eslint 'src/**' 'tests/**'", "lint": "npm run eslint && npm run prettier -- --list-different", "lint:fix": "npm run eslint -- --fix && npm run prettier -- --write", "prepublishOnly": "npm run build", - "prettier": "prettier './*.{js,json,md,yml}' '{scripts,src,tests}/**/*.js'", - "test": "jest", - "test:all": "cross-env FULL_TEST=1 c8 jest", + "prettier": "prettier './*.{js,json,md,yml}' '{src,tests}/**/*.js'", + "test": "NODE_OPTIONS=--loader=esmock jest", + "test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=--loader=esmock c8 jest", "test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest" }, "files": [ "src", - "dist/standalone.js", - "dist/standalone.js.LICENSE.txt", - "dist/standalone.js.map", + "dist/**/*", "LICENSE", "README.md" ], @@ -79,29 +81,30 @@ "node": ">=16" }, "devDependencies": { - "@babel/code-frame": "^7.22.5", - "c8": "^8.0.0", + "@babel/code-frame": "^7.22.10", + "c8": "^8.0.1", "cross-env": "^7.0.3", - "dir-to-object": "^2.0.0", - "eslint": "^8.44.0", + "eslint": "^8.47.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.27.5", + "eslint-plugin-import": "^2.28.1", + "esm-utils": "^4.1.2", + "esmock": "^2.3.8", "exports-loader": "^4.0.0", - "jest": "^29.6.1", + "jest": "^29.6.3", "jest-light-runner": "^0.5.0", "jest-snapshot-serializer-ansi": "^2.1.0", - "jest-snapshot-serializer-raw": "^1.2.0", + "jest-snapshot-serializer-raw": "^2.0.0", "jest-watch-typeahead": "^2.2.2", "lines-and-columns": "^2.0.3", - "prettier": "^3.0.0", + "prettier": "^3.0.2", "proxyquire": "^2.1.3", - "solc": "^0.8.20", - "webpack": "^5.88.1", + "solc": "^0.8.21", + "webpack": "^5.88.2", "webpack-cli": "^5.1.4" }, "dependencies": { - "@solidity-parser/parser": "^0.16.0", + "@solidity-parser/parser": "^0.16.1", "semver": "^7.5.4", "solidity-comments-extractor": "^0.0.7" }, diff --git a/scripts/generateIndexes.js b/scripts/generateIndexes.js deleted file mode 100644 index e42952b4d..000000000 --- a/scripts/generateIndexes.js +++ /dev/null @@ -1,16 +0,0 @@ -const fs = require('fs'); -const prettier = require('prettier'); -const makeData = require('./makeData'); - -if (process.env.SCRIPT === 'true') { - prettier.resolveConfig(`${__dirname}../.prettierrc`).then((options) => { - // eslint-disable-next-line no-param-reassign - options.parser = 'babel'; - ['../src/nodes', '../src/binary-operator-printers'].forEach((dir) => { - fs.writeFileSync( - `${__dirname}/${dir}/index.js`, - prettier.format(makeData(dir), options) - ); - }); - }); -} diff --git a/scripts/makeData.js b/scripts/makeData.js deleted file mode 100644 index e9ba9934f..000000000 --- a/scripts/makeData.js +++ /dev/null @@ -1,23 +0,0 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -const dirToObject = require('dir-to-object'); - -function makeData(dir) { - const nodes = Object.keys( - dirToObject(`${__dirname}/${dir}`, { canAdd: (data) => data.print }) - ).reduce((accumulator, current) => { - accumulator[current] = `require('./${current}')`; - return accumulator; - }, {}); - - const data = `/* This file was automatically generated on ${ - Date.now() / 1000 - } */ - - /* eslint-disable global-require */ - - module.exports = ${JSON.stringify(nodes)};`; - - return data.replace(/["]+/g, ''); -} - -module.exports = makeData; diff --git a/src/binary-operator-printers/arithmetic.js b/src/binary-operator-printers/arithmetic.js index 4a2ec2eb6..b7b4b1240 100644 --- a/src/binary-operator-printers/arithmetic.js +++ b/src/binary-operator-printers/arithmetic.js @@ -1,38 +1,36 @@ -const { - doc: { - builders: { group, line, indent } - } -} = require('prettier'); -const comparison = require('./comparison'); +import { doc } from 'prettier'; +import { comparison } from './comparison.js'; + +const { group, line, indent } = doc.builders; -const groupIfNecessaryBuilder = (path) => (doc) => { +const groupIfNecessaryBuilder = (path) => (document) => { const parentNode = path.getParentNode(); if ( parentNode.type === 'BinaryOperation' && !comparison.match(parentNode.operator) ) { - return doc; + return document; } - return group(doc); + return group(document); }; -const indentIfNecessaryBuilder = (path) => (doc) => { +const indentIfNecessaryBuilder = (path) => (document) => { let node = path.getNode(); for (let i = 0; ; i += 1) { const parentNode = path.getParentNode(i); - if (parentNode.type === 'ReturnStatement') return doc; + if (parentNode.type === 'ReturnStatement') return document; if ( parentNode.type !== 'BinaryOperation' || comparison.match(parentNode.operator) ) { - return indent(doc); + return indent(document); } - if (node === parentNode.right) return doc; + if (node === parentNode.right) return document; node = parentNode; } }; -module.exports = { +export const arithmetic = { match: (op) => ['+', '-', '*', '/', '%'].includes(op), print: (node, path, print) => { const groupIfNecessary = groupIfNecessaryBuilder(path); diff --git a/src/binary-operator-printers/assignment.js b/src/binary-operator-printers/assignment.js index caf94bb1d..ab72d82ca 100644 --- a/src/binary-operator-printers/assignment.js +++ b/src/binary-operator-printers/assignment.js @@ -1,10 +1,8 @@ -const { - doc: { - builders: { group, line, indent } - } -} = require('prettier'); +import { doc } from 'prettier'; -module.exports = { +const { group, line, indent } = doc.builders; + +export const assignment = { match: (op) => [ '=', diff --git a/src/binary-operator-printers/bit.js b/src/binary-operator-printers/bit.js index 78603ecae..761a182f8 100644 --- a/src/binary-operator-printers/bit.js +++ b/src/binary-operator-printers/bit.js @@ -1,6 +1,6 @@ -const arithmetic = require('./arithmetic'); +import { arithmetic } from './arithmetic.js'; -module.exports = { +export const bit = { match: (op) => ['&', '|', '^'].includes(op), print: arithmetic.print }; diff --git a/src/binary-operator-printers/comparison.js b/src/binary-operator-printers/comparison.js index 79f96e52b..56e3a3acb 100644 --- a/src/binary-operator-printers/comparison.js +++ b/src/binary-operator-printers/comparison.js @@ -1,24 +1,22 @@ -const { - doc: { - builders: { group, line, indent } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; -const indentIfNecessaryBuilder = (path) => (doc) => { +const indentIfNecessaryBuilder = (path) => (document) => { let node = path.getNode(); for (let i = 0; ; i += 1) { const parentNode = path.getParentNode(i); - if (parentNode.type === 'ReturnStatement') return doc; - if (parentNode.type === 'IfStatement') return doc; - if (parentNode.type === 'ForStatement') return doc; - if (parentNode.type === 'WhileStatement') return doc; - if (parentNode.type !== 'BinaryOperation') return indent(doc); - if (node === parentNode.right) return doc; + if (parentNode.type === 'ReturnStatement') return document; + if (parentNode.type === 'IfStatement') return document; + if (parentNode.type === 'ForStatement') return document; + if (parentNode.type === 'WhileStatement') return document; + if (parentNode.type !== 'BinaryOperation') return indent(document); + if (node === parentNode.right) return document; node = parentNode; } }; -module.exports = { +export const comparison = { match: (op) => ['<', '>', '<=', '>=', '==', '!='].includes(op), print: (node, path, print) => { const indentIfNecessary = indentIfNecessaryBuilder(path); diff --git a/src/binary-operator-printers/exponentiation.js b/src/binary-operator-printers/exponentiation.js index c6c12421b..637f68075 100644 --- a/src/binary-operator-printers/exponentiation.js +++ b/src/binary-operator-printers/exponentiation.js @@ -1,10 +1,8 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; -module.exports = { +export const exponentiation = { match: (op) => op === '**', print: (node, path, print) => { const right = [' ', node.operator, line, path.call(print, 'right')]; diff --git a/src/binary-operator-printers/index.js b/src/binary-operator-printers/index.js index ff5b84575..e65a4f1e9 100644 --- a/src/binary-operator-printers/index.js +++ b/src/binary-operator-printers/index.js @@ -1,13 +1,7 @@ -/* This file was automatically generated on 1666691919.933 */ - -/* eslint-disable global-require */ - -module.exports = { - arithmetic: require('./arithmetic'), - assignment: require('./assignment'), - bit: require('./bit'), - comparison: require('./comparison'), - exponentiation: require('./exponentiation'), - logical: require('./logical'), - shift: require('./shift') -}; +export * from './arithmetic.js'; +export * from './assignment.js'; +export * from './bit.js'; +export * from './comparison.js'; +export * from './exponentiation.js'; +export * from './logical.js'; +export * from './shift.js'; diff --git a/src/binary-operator-printers/logical.js b/src/binary-operator-printers/logical.js index 3d4f44fce..767b19e07 100644 --- a/src/binary-operator-printers/logical.js +++ b/src/binary-operator-printers/logical.js @@ -1,26 +1,24 @@ -const { - doc: { - builders: { group, line, indent } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, line, indent } = doc.builders; -const groupIfNecessaryBuilder = (path) => (doc) => - path.getParentNode().type === 'BinaryOperation' ? doc : group(doc); +const groupIfNecessaryBuilder = (path) => (document) => + path.getParentNode().type === 'BinaryOperation' ? document : group(document); -const indentIfNecessaryBuilder = (path) => (doc) => { +const indentIfNecessaryBuilder = (path) => (document) => { let node = path.getNode(); for (let i = 0; ; i += 1) { const parentNode = path.getParentNode(i); - if (parentNode.type === 'ReturnStatement') return doc; - if (parentNode.type === 'IfStatement') return doc; - if (parentNode.type === 'WhileStatement') return doc; - if (parentNode.type !== 'BinaryOperation') return indent(doc); - if (node === parentNode.right) return doc; + if (parentNode.type === 'ReturnStatement') return document; + if (parentNode.type === 'IfStatement') return document; + if (parentNode.type === 'WhileStatement') return document; + if (parentNode.type !== 'BinaryOperation') return indent(document); + if (node === parentNode.right) return document; node = parentNode; } }; -module.exports = { +export const logical = { match: (op) => ['&&', '||'].includes(op), print: (node, path, print) => { const groupIfNecessary = groupIfNecessaryBuilder(path); diff --git a/src/binary-operator-printers/shift.js b/src/binary-operator-printers/shift.js index d30eb2f86..026747cca 100644 --- a/src/binary-operator-printers/shift.js +++ b/src/binary-operator-printers/shift.js @@ -1,6 +1,6 @@ -const arithmetic = require('./arithmetic'); +import { arithmetic } from './arithmetic.js'; -module.exports = { +export const shift = { match: (op) => ['<<', '>>'].includes(op), print: arithmetic.print }; diff --git a/src/clean.js b/src/clean.js index ad4ef07a1..6ce7c3d55 100644 --- a/src/clean.js +++ b/src/clean.js @@ -3,4 +3,4 @@ const ignoredProperties = new Set(['loc', 'range', 'comments']); function clean(/* ast, newObj, parent */) {} clean.ignoredProperties = ignoredProperties; -module.exports = clean; +export default clean; diff --git a/src/comments/handler.js b/src/comments/handler.js index 611f9375c..208a189c1 100644 --- a/src/comments/handler.js +++ b/src/comments/handler.js @@ -1,12 +1,11 @@ -const { +import { handleOwnLineComment, handleEndOfLineComment, handleRemainingComment -} = require('../prettier-comments/language-js/comments'); +} from '../prettier-comments/language-js/comments.js'; +import handlers from './handlers/index.js'; -const handlers = require('./handlers'); - -function solidityHandleOwnLineComment( +export function solidityHandleOwnLineComment( comment, text, options, @@ -32,7 +31,7 @@ function solidityHandleOwnLineComment( return false; } -function solidityHandleEndOfLineComment( +export function solidityHandleEndOfLineComment( comment, text, options, @@ -58,7 +57,7 @@ function solidityHandleEndOfLineComment( return false; } -function solidityHandleRemainingComment( +export function solidityHandleRemainingComment( comment, text, options, @@ -84,13 +83,6 @@ function solidityHandleRemainingComment( return false; } -function isBlockComment(comment) { +export function isBlockComment(comment) { return comment.type === 'BlockComment'; } - -module.exports = { - handleOwnLineComment: solidityHandleOwnLineComment, - handleEndOfLineComment: solidityHandleEndOfLineComment, - handleRemainingComment: solidityHandleRemainingComment, - isBlockComment -}; diff --git a/src/comments/handlers/handleContractDefinitionComments.js b/src/comments/handlers/handleContractDefinitionComments.js index d9af96791..1a77e7360 100644 --- a/src/comments/handlers/handleContractDefinitionComments.js +++ b/src/comments/handlers/handleContractDefinitionComments.js @@ -1,7 +1,7 @@ -const { - util: { addLeadingComment, addTrailingComment, addDanglingComment } -} = require('prettier'); -const { getNextNonSpaceNonCommentCharacter } = require('../../common/util'); +import { util } from 'prettier'; +import { getNextNonSpaceNonCommentCharacter } from '../../common/util.js'; + +const { addLeadingComment, addTrailingComment, addDanglingComment } = util; function handleContractDefinitionComments({ text, @@ -55,4 +55,4 @@ function handleContractDefinitionComments({ return false; } -module.exports = handleContractDefinitionComments; +export default handleContractDefinitionComments; diff --git a/src/comments/handlers/handleModifierInvocationComments.js b/src/comments/handlers/handleModifierInvocationComments.js index 3f26dd494..1ef57184f 100644 --- a/src/comments/handlers/handleModifierInvocationComments.js +++ b/src/comments/handlers/handleModifierInvocationComments.js @@ -1,7 +1,7 @@ -const { - util: { addLeadingComment, addTrailingComment, addDanglingComment } -} = require('prettier'); -const { getNextNonSpaceNonCommentCharacter } = require('../../common/util'); +import { util } from 'prettier'; +import { getNextNonSpaceNonCommentCharacter } from '../../common/util.js'; + +const { addLeadingComment, addTrailingComment, addDanglingComment } = util; function handleModifierInvocationComments({ text, @@ -64,4 +64,4 @@ function handleModifierInvocationComments({ return false; } -module.exports = handleModifierInvocationComments; +export default handleModifierInvocationComments; diff --git a/src/comments/handlers/index.js b/src/comments/handlers/index.js index 75869c699..fa67eab16 100644 --- a/src/comments/handlers/index.js +++ b/src/comments/handlers/index.js @@ -1,6 +1,8 @@ /* eslint-disable global-require */ +import handleContractDefinitionComments from './handleContractDefinitionComments.js'; +import handleModifierInvocationComments from './handleModifierInvocationComments.js'; -module.exports = [ - require('./handleContractDefinitionComments'), - require('./handleModifierInvocationComments') +export default [ + handleContractDefinitionComments, + handleModifierInvocationComments ]; diff --git a/src/comments/ignore.js b/src/comments/ignore.js index ed9df35c0..ed021087a 100644 --- a/src/comments/ignore.js +++ b/src/comments/ignore.js @@ -30,4 +30,4 @@ function ignoreComments(path) { }); } -module.exports = ignoreComments; +export default ignoreComments; diff --git a/src/comments/index.js b/src/comments/index.js index 4d88f5618..22efb5a89 100644 --- a/src/comments/index.js +++ b/src/comments/index.js @@ -1,4 +1,2 @@ -const handler = require('./handler'); -const printer = require('./printer'); - -module.exports = { handleComments: handler, printComment: printer }; +export * from './handler.js'; +export * from './printer.js'; diff --git a/src/comments/printer.js b/src/comments/printer.js index 03062ec8e..d2d873818 100644 --- a/src/comments/printer.js +++ b/src/comments/printer.js @@ -1,9 +1,6 @@ -const { - doc: { - builders: { hardline, join } - }, - util: { hasNewline } -} = require('prettier'); +import { doc, util } from 'prettier'; + +const { hardline, join } = doc.builders; function isIndentableBlockComment(comment) { // If the comment has multiple lines and every line starts with a star @@ -31,7 +28,7 @@ function printIndentableBlockComment(comment) { ]; } -function printComment(commentPath, options) { +export function printComment(commentPath, options) { const comment = commentPath.getValue(); switch (comment.type) { @@ -43,7 +40,7 @@ function printComment(commentPath, options) { // interleaved. See https://github.com/prettier/prettier/issues/4412 if ( comment.trailing && - !hasNewline(options.originalText, options.locStart(comment), { + !util.hasNewline(options.originalText, options.locStart(comment), { backwards: true }) ) { @@ -60,5 +57,3 @@ function printComment(commentPath, options) { throw new Error(`Not a comment: ${JSON.stringify(comment)}`); } } - -module.exports = printComment; diff --git a/src/common/printer-helpers.js b/src/common/printer-helpers.js index 48683e4b0..cc72be1be 100644 --- a/src/common/printer-helpers.js +++ b/src/common/printer-helpers.js @@ -1,13 +1,11 @@ -const { - doc: { - builders: { group, indent, join, line, softline, hardline } - } -} = require('prettier'); -const { isNextLineEmpty, isPrettier2 } = require('./util'); +import { doc } from 'prettier'; +import { isNextLineEmpty, isPrettier2 } from './util.js'; + +const { group, indent, join, line, softline, hardline } = doc.builders; -const printComments = (node, path, options, filter = () => true) => { +export const printComments = (node, path, options, filter = () => true) => { if (!node.comments) return ''; - const doc = join( + const document = join( line, path .map((commentPath) => { @@ -29,12 +27,12 @@ const printComments = (node, path, options, filter = () => true) => { // Mocking the behaviour will introduce a lot of maintenance in the tests. /* c8 ignore start */ return isPrettier2() - ? doc.parts // Prettier V2 - : doc; // Prettier V3 + ? document.parts // Prettier V2 + : document; // Prettier V3 /* c8 ignore stop */ }; -function printPreservingEmptyLines(path, key, options, print) { +export function printPreservingEmptyLines(path, key, options, print) { const parts = []; path.each((childPath, index) => { const node = childPath.getValue(); @@ -78,7 +76,7 @@ function printPreservingEmptyLines(path, key, options, print) { // This function will add an indentation to the `item` and separate it from the // rest of the `doc` in most cases by a `softline`. -const printSeparatedItem = ( +export const printSeparatedItem = ( item, { firstSeparator = softline, @@ -86,15 +84,15 @@ const printSeparatedItem = ( grouped = true } = {} ) => { - const doc = [indent([firstSeparator, item]), lastSeparator]; - return grouped ? group(doc) : doc; + const document = [indent([firstSeparator, item]), lastSeparator]; + return grouped ? group(document) : document; }; // This function will add an indentation to the `list` and separate it from the // rest of the `doc` in most cases by a `softline`. // the list itself will be printed with a separator that in most cases is a // comma (,) and a `line` -const printSeparatedList = ( +export const printSeparatedList = ( list, { firstSeparator, separator = [',', line], lastSeparator, grouped } = {} ) => @@ -103,10 +101,3 @@ const printSeparatedList = ( lastSeparator, grouped }); - -module.exports = { - printComments, - printPreservingEmptyLines, - printSeparatedList, - printSeparatedItem -}; diff --git a/src/common/util.js b/src/common/util.js index 1e608a0f5..320bc49ce 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -1,26 +1,26 @@ -const { util, version } = require('prettier'); -const satisfies = require('semver/functions/satisfies'); +import { util, version } from 'prettier'; +import satisfies from 'semver/functions/satisfies.js'; -const prettierVersionSatisfies = (range) => satisfies(version, range); -const isPrettier2 = () => prettierVersionSatisfies('^2.3.0'); +export const prettierVersionSatisfies = (range) => satisfies(version, range); +export const isPrettier2 = () => prettierVersionSatisfies('^2.3.0'); // The following functions will never be 100% covered in a single run // since it depends on the version of Prettier being used. // Mocking the behaviour will introduce a lot of maintenance in the tests. /* c8 ignore start */ -function isNextLineEmpty(text, startIndex) { +export function isNextLineEmpty(text, startIndex) { return isPrettier2() ? util.isNextLineEmptyAfterIndex(text, startIndex) : util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex` } -function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) { +export function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) { return isPrettier2() ? util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) : util.getNextNonSpaceNonCommentCharacterIndex(text, locEnd(node)); // V3 signature changed } -function getNextNonSpaceNonCommentCharacter(text, node, locEnd) { +export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) { return isPrettier2() ? text.charAt( util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) @@ -29,7 +29,7 @@ function getNextNonSpaceNonCommentCharacter(text, node, locEnd) { } /* c8 ignore stop */ -function printString(rawContent, options) { +export function printString(rawContent, options) { const double = { quote: '"', regex: /"/g }; const single = { quote: "'", regex: /'/g }; @@ -64,7 +64,7 @@ function printString(rawContent, options) { return util.makeString(rawContent, enclosingQuote); } -function hasNodeIgnoreComment(node) { +export function hasNodeIgnoreComment(node) { return ( node && node.comments && @@ -72,13 +72,3 @@ function hasNodeIgnoreComment(node) { node.comments.some((comment) => comment.value.trim() === 'prettier-ignore') ); } - -module.exports = { - getNextNonSpaceNonCommentCharacter, - getNextNonSpaceNonCommentCharacterIndex, - isNextLineEmpty, - isPrettier2, - printString, - prettierVersionSatisfies, - hasNodeIgnoreComment -}; diff --git a/src/index.js b/src/index.js index 4409beba4..9d3bfe3cf 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,9 @@ -const { handleComments, printComment } = require('./comments'); -const massageAstNode = require('./clean'); -const loc = require('./loc'); -const options = require('./options'); -const parse = require('./parser'); -const print = require('./printer'); +import * as comments from './comments/index.js'; +import massageAstNode from './clean.js'; +import loc from './loc.js'; +import options from './options.js'; +import parse from './parser.js'; +import print from './printer.js'; // https://prettier.io/docs/en/plugins.html#languages // https://github.com/ikatyang/linguist-languages/blob/master/data/Solidity.json @@ -35,14 +35,14 @@ const printers = { 'solidity-ast': { canAttachComment, handleComments: { - ownLine: handleComments.handleOwnLineComment, - endOfLine: handleComments.handleEndOfLineComment, - remaining: handleComments.handleRemainingComment + ownLine: comments.solidityHandleOwnLineComment, + endOfLine: comments.solidityHandleEndOfLineComment, + remaining: comments.solidityHandleRemainingComment }, - isBlockComment: handleComments.isBlockComment, + isBlockComment: comments.isBlockComment, massageAstNode, print, - printComment + printComment: comments.printComment } }; @@ -52,10 +52,12 @@ const defaultOptions = { tabWidth: 4 }; -module.exports = { +const plugin = { languages, parsers, printers, options, defaultOptions }; + +export default plugin; diff --git a/src/loc.js b/src/loc.js index 48a322364..4fa684cd1 100644 --- a/src/loc.js +++ b/src/loc.js @@ -10,7 +10,7 @@ function getRange(index, node) { return null; } -module.exports = { +export default { locEnd: (node) => getRange(1, node), locStart: (node) => getRange(0, node) }; diff --git a/src/nodes/ArrayTypeName.js b/src/nodes/ArrayTypeName.js index b7c3245a2..850149bc2 100644 --- a/src/nodes/ArrayTypeName.js +++ b/src/nodes/ArrayTypeName.js @@ -1,4 +1,4 @@ -const ArrayTypeName = { +export const ArrayTypeName = { print: ({ node, path, print }) => [ path.call(print, 'baseTypeName'), '[', @@ -6,5 +6,3 @@ const ArrayTypeName = { ']' ] }; - -module.exports = ArrayTypeName; diff --git a/src/nodes/AssemblyAssignment.js b/src/nodes/AssemblyAssignment.js index 5df98b079..a45456890 100644 --- a/src/nodes/AssemblyAssignment.js +++ b/src/nodes/AssemblyAssignment.js @@ -1,15 +1,11 @@ -const { - doc: { - builders: { join } - } -} = require('prettier'); +import { doc } from 'prettier'; -const AssemblyAssignment = { +const { join } = doc.builders; + +export const AssemblyAssignment = { print: ({ path, print }) => [ join(', ', path.map(print, 'names')), ' := ', path.call(print, 'expression') ] }; - -module.exports = AssemblyAssignment; diff --git a/src/nodes/AssemblyBlock.js b/src/nodes/AssemblyBlock.js index c63af9595..680790711 100644 --- a/src/nodes/AssemblyBlock.js +++ b/src/nodes/AssemblyBlock.js @@ -1,16 +1,13 @@ -const { - doc: { - builders: { hardline } - } -} = require('prettier'); - -const { +import { doc } from 'prettier'; +import { printComments, printPreservingEmptyLines, printSeparatedItem -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { hardline } = doc.builders; -const AssemblyBlock = { +export const AssemblyBlock = { print: ({ node, options, path, print }) => [ '{', printSeparatedItem( @@ -23,5 +20,3 @@ const AssemblyBlock = { '}' ] }; - -module.exports = AssemblyBlock; diff --git a/src/nodes/AssemblyCall.js b/src/nodes/AssemblyCall.js index 134fd923a..b7973b8b6 100644 --- a/src/nodes/AssemblyCall.js +++ b/src/nodes/AssemblyCall.js @@ -1,6 +1,6 @@ -const { printSeparatedList } = require('../common/printer-helpers'); +import { printSeparatedList } from '../common/printer-helpers.js'; -const AssemblyCall = { +export const AssemblyCall = { print: ({ node, path, print, options }) => node.arguments.length === 0 && options.originalText.charAt(options.locEnd(node)) !== ')' @@ -12,5 +12,3 @@ const AssemblyCall = { ')' ] }; - -module.exports = AssemblyCall; diff --git a/src/nodes/AssemblyCase.js b/src/nodes/AssemblyCase.js index e0b2a3d4f..766e146c8 100644 --- a/src/nodes/AssemblyCase.js +++ b/src/nodes/AssemblyCase.js @@ -1,9 +1,7 @@ -const AssemblyCase = { +export const AssemblyCase = { print: ({ node, path, print }) => [ node.default ? 'default' : ['case ', path.call(print, 'value')], ' ', path.call(print, 'block') ] }; - -module.exports = AssemblyCase; diff --git a/src/nodes/AssemblyFor.js b/src/nodes/AssemblyFor.js index 99b8144bb..291382fd1 100644 --- a/src/nodes/AssemblyFor.js +++ b/src/nodes/AssemblyFor.js @@ -1,10 +1,8 @@ -const { - doc: { - builders: { join } - } -} = require('prettier'); +import { doc } from 'prettier'; -const AssemblyFor = { +const { join } = doc.builders; + +export const AssemblyFor = { print: ({ path, print }) => join(' ', [ 'for', @@ -14,5 +12,3 @@ const AssemblyFor = { path.call(print, 'body') ]) }; - -module.exports = AssemblyFor; diff --git a/src/nodes/AssemblyFunctionDefinition.js b/src/nodes/AssemblyFunctionDefinition.js index d92a65178..be5d93039 100644 --- a/src/nodes/AssemblyFunctionDefinition.js +++ b/src/nodes/AssemblyFunctionDefinition.js @@ -1,15 +1,12 @@ -const { - doc: { - builders: { line } - } -} = require('prettier'); - -const { +import { doc } from 'prettier'; +import { printSeparatedItem, printSeparatedList -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { line } = doc.builders; -const AssemblyFunctionDefinition = { +export const AssemblyFunctionDefinition = { print: ({ node, path, print }) => [ 'function ', node.name, @@ -31,5 +28,3 @@ const AssemblyFunctionDefinition = { path.call(print, 'body') ] }; - -module.exports = AssemblyFunctionDefinition; diff --git a/src/nodes/AssemblyIf.js b/src/nodes/AssemblyIf.js index ade74b2a8..2f7d170f6 100644 --- a/src/nodes/AssemblyIf.js +++ b/src/nodes/AssemblyIf.js @@ -1,4 +1,4 @@ -const AssemblyIf = { +export const AssemblyIf = { print: ({ path, print }) => [ 'if ', path.call(print, 'condition'), @@ -6,5 +6,3 @@ const AssemblyIf = { path.call(print, 'body') ] }; - -module.exports = AssemblyIf; diff --git a/src/nodes/AssemblyLocalDefinition.js b/src/nodes/AssemblyLocalDefinition.js index f2b281618..9e2c17e76 100644 --- a/src/nodes/AssemblyLocalDefinition.js +++ b/src/nodes/AssemblyLocalDefinition.js @@ -1,12 +1,9 @@ -const { - doc: { - builders: { line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { line } = doc.builders; -const AssemblyLocalDefinition = { +export const AssemblyLocalDefinition = { print: ({ node, path, print }) => { const parts = [ 'let', @@ -21,5 +18,3 @@ const AssemblyLocalDefinition = { return parts; } }; - -module.exports = AssemblyLocalDefinition; diff --git a/src/nodes/AssemblyMemberAccess.js b/src/nodes/AssemblyMemberAccess.js index 85f146359..662a94a5b 100644 --- a/src/nodes/AssemblyMemberAccess.js +++ b/src/nodes/AssemblyMemberAccess.js @@ -1,9 +1,7 @@ -const AssemblyMemberAccess = { +export const AssemblyMemberAccess = { print: ({ path, print }) => [ path.call(print, 'expression'), '.', path.call(print, 'memberName') ] }; - -module.exports = AssemblyMemberAccess; diff --git a/src/nodes/AssemblyStackAssignment.js b/src/nodes/AssemblyStackAssignment.js index 7d59bbe6c..32ada6c70 100644 --- a/src/nodes/AssemblyStackAssignment.js +++ b/src/nodes/AssemblyStackAssignment.js @@ -1,9 +1,7 @@ -const AssemblyStackAssignment = { +export const AssemblyStackAssignment = { print: ({ node, path, print }) => [ path.call(print, 'expression'), ' =: ', node.name ] }; - -module.exports = AssemblyStackAssignment; diff --git a/src/nodes/AssemblySwitch.js b/src/nodes/AssemblySwitch.js index 6589a336e..eccb91a0e 100644 --- a/src/nodes/AssemblySwitch.js +++ b/src/nodes/AssemblySwitch.js @@ -1,10 +1,8 @@ -const { - doc: { - builders: { hardline, join } - } -} = require('prettier'); +import { doc } from 'prettier'; -const AssemblySwitch = { +const { hardline, join } = doc.builders; + +export const AssemblySwitch = { print: ({ path, print }) => [ 'switch ', path.call(print, 'expression'), @@ -12,5 +10,3 @@ const AssemblySwitch = { join(hardline, path.map(print, 'cases')) ] }; - -module.exports = AssemblySwitch; diff --git a/src/nodes/BinaryOperation.js b/src/nodes/BinaryOperation.js index 667fc33a6..1d9787a94 100644 --- a/src/nodes/BinaryOperation.js +++ b/src/nodes/BinaryOperation.js @@ -1,7 +1,6 @@ -/* eslint-disable consistent-return */ -const printers = require('../binary-operator-printers'); +import * as printers from '../binary-operator-printers/index.js'; -const BinaryOperation = { +export const BinaryOperation = { print: ({ node, path, print, options }) => { const binaryOperationPrinter = Object.values(printers).find((printer) => printer.match(node.operator) @@ -16,5 +15,3 @@ const BinaryOperation = { return binaryOperationPrinter.print(node, path, print, options); } }; - -module.exports = BinaryOperation; diff --git a/src/nodes/Block.js b/src/nodes/Block.js index 402e216ed..3045fc249 100644 --- a/src/nodes/Block.js +++ b/src/nodes/Block.js @@ -1,15 +1,12 @@ -const { - doc: { - builders: { hardline, indent } - } -} = require('prettier'); - -const { +import { doc } from 'prettier'; +import { printComments, printPreservingEmptyLines -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { hardline, indent } = doc.builders; -const Block = { +export const Block = { print: ({ node, options, path, print }) => // if block is empty, just return the pair of braces node.statements.length === 0 && !node.comments @@ -25,5 +22,3 @@ const Block = { '}' ] }; - -module.exports = Block; diff --git a/src/nodes/BooleanLiteral.js b/src/nodes/BooleanLiteral.js index 62a6b83b5..863c995c3 100644 --- a/src/nodes/BooleanLiteral.js +++ b/src/nodes/BooleanLiteral.js @@ -1,5 +1,3 @@ -const BooleanLiteral = { +export const BooleanLiteral = { print: ({ node }) => (node.value ? 'true' : 'false') }; - -module.exports = BooleanLiteral; diff --git a/src/nodes/Break.js b/src/nodes/Break.js index 9a90ccf60..c1ebdb827 100644 --- a/src/nodes/Break.js +++ b/src/nodes/Break.js @@ -1,5 +1,3 @@ -const Break = { +export const Break = { print: () => 'break' }; - -module.exports = Break; diff --git a/src/nodes/BreakStatement.js b/src/nodes/BreakStatement.js index c6130ff61..5fcfe5612 100644 --- a/src/nodes/BreakStatement.js +++ b/src/nodes/BreakStatement.js @@ -1,5 +1,3 @@ -const BreakStatement = { +export const BreakStatement = { print: () => 'break;' }; - -module.exports = BreakStatement; diff --git a/src/nodes/CatchClause.js b/src/nodes/CatchClause.js index e72b4078d..a29c065e9 100644 --- a/src/nodes/CatchClause.js +++ b/src/nodes/CatchClause.js @@ -1,4 +1,4 @@ -const { printSeparatedList } = require('../common/printer-helpers'); +import { printSeparatedList } from '../common/printer-helpers.js'; const parameters = (node, path, print) => node.parameters @@ -10,12 +10,10 @@ const parameters = (node, path, print) => ] : ''; -const CatchClause = { +export const CatchClause = { print: ({ node, path, print }) => [ 'catch ', parameters(node, path, print), path.call(print, 'body') ] }; - -module.exports = CatchClause; diff --git a/src/nodes/Conditional.js b/src/nodes/Conditional.js index eb1979fbf..b67abe696 100644 --- a/src/nodes/Conditional.js +++ b/src/nodes/Conditional.js @@ -1,10 +1,8 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; -const Conditional = { +const { group, indent, line } = doc.builders; + +export const Conditional = { print: ({ path, print }) => group([ path.call(print, 'condition'), @@ -18,5 +16,3 @@ const Conditional = { ]) ]) }; - -module.exports = Conditional; diff --git a/src/nodes/Continue.js b/src/nodes/Continue.js index c327de284..6cb16018e 100644 --- a/src/nodes/Continue.js +++ b/src/nodes/Continue.js @@ -1,5 +1,3 @@ -const Continue = { +export const Continue = { print: () => 'continue' }; - -module.exports = Continue; diff --git a/src/nodes/ContinueStatement.js b/src/nodes/ContinueStatement.js index 883318b18..ba87dda15 100644 --- a/src/nodes/ContinueStatement.js +++ b/src/nodes/ContinueStatement.js @@ -1,5 +1,3 @@ -const ContinueStatement = { +export const ContinueStatement = { print: () => 'continue;' }; - -module.exports = ContinueStatement; diff --git a/src/nodes/ContractDefinition.js b/src/nodes/ContractDefinition.js index 5d19b3433..b95806ca1 100644 --- a/src/nodes/ContractDefinition.js +++ b/src/nodes/ContractDefinition.js @@ -1,15 +1,12 @@ -const { - doc: { - builders: { group, line, hardline } - } -} = require('prettier'); - -const { +import { doc } from 'prettier'; +import { printComments, printPreservingEmptyLines, printSeparatedItem, printSeparatedList -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { group, line, hardline } = doc.builders; const inheritance = (node, path, print) => node.baseContracts.length > 0 @@ -31,7 +28,7 @@ const body = (node, path, options, print) => { : ''; }; -const ContractDefinition = { +export const ContractDefinition = { print: ({ node, options, path, print }) => [ group([ node.kind === 'abstract' ? 'abstract contract' : node.kind, @@ -44,5 +41,3 @@ const ContractDefinition = { '}' ] }; - -module.exports = ContractDefinition; diff --git a/src/nodes/CustomErrorDefinition.js b/src/nodes/CustomErrorDefinition.js index d2b5b7260..e0ae941dc 100644 --- a/src/nodes/CustomErrorDefinition.js +++ b/src/nodes/CustomErrorDefinition.js @@ -1,11 +1,11 @@ -const { printSeparatedList } = require('../common/printer-helpers'); +import { printSeparatedList } from '../common/printer-helpers.js'; const parameters = (node, path, print) => node.parameters && node.parameters.length > 0 ? printSeparatedList(path.map(print, 'parameters')) : ''; -const CustomErrorDefinition = { +export const CustomErrorDefinition = { print: ({ node, path, print }) => [ 'error ', node.name, @@ -14,5 +14,3 @@ const CustomErrorDefinition = { ');' ] }; - -module.exports = CustomErrorDefinition; diff --git a/src/nodes/DecimalNumber.js b/src/nodes/DecimalNumber.js index 9ddac67b0..28f615899 100644 --- a/src/nodes/DecimalNumber.js +++ b/src/nodes/DecimalNumber.js @@ -1,5 +1,3 @@ -const DecimalNumber = { +export const DecimalNumber = { print: ({ node }) => node.value }; - -module.exports = DecimalNumber; diff --git a/src/nodes/DoWhileStatement.js b/src/nodes/DoWhileStatement.js index 22c2d4fc7..af0f86884 100644 --- a/src/nodes/DoWhileStatement.js +++ b/src/nodes/DoWhileStatement.js @@ -1,17 +1,14 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; -const { printSeparatedItem } = require('../common/printer-helpers'); +const { group, indent, line } = doc.builders; const printBody = (node, path, print) => node.body.type === 'Block' ? [' ', path.call(print, 'body'), ' '] : group([indent([line, path.call(print, 'body')]), line]); -const DoWhileStatement = { +export const DoWhileStatement = { print: ({ node, path, print }) => [ 'do', printBody(node, path, print), @@ -20,5 +17,3 @@ const DoWhileStatement = { ');' ] }; - -module.exports = DoWhileStatement; diff --git a/src/nodes/ElementaryTypeName.js b/src/nodes/ElementaryTypeName.js index 32ada41fb..e3244234c 100644 --- a/src/nodes/ElementaryTypeName.js +++ b/src/nodes/ElementaryTypeName.js @@ -3,8 +3,6 @@ const stateMutability = (node) => ? [' ', node.stateMutability] : ''; -const ElementaryTypeName = { +export const ElementaryTypeName = { print: ({ node }) => [node.name, stateMutability(node)] }; - -module.exports = ElementaryTypeName; diff --git a/src/nodes/EmitStatement.js b/src/nodes/EmitStatement.js index 4ef948a28..6444868e8 100644 --- a/src/nodes/EmitStatement.js +++ b/src/nodes/EmitStatement.js @@ -1,5 +1,3 @@ -const EmitStatement = { +export const EmitStatement = { print: ({ path, print }) => ['emit ', path.call(print, 'eventCall'), ';'] }; - -module.exports = EmitStatement; diff --git a/src/nodes/EnumDefinition.js b/src/nodes/EnumDefinition.js index 7ef37926c..c8cd0363f 100644 --- a/src/nodes/EnumDefinition.js +++ b/src/nodes/EnumDefinition.js @@ -1,12 +1,9 @@ -const { - doc: { - builders: { group, hardline } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, hardline } = doc.builders; -const EnumDefinition = { +export const EnumDefinition = { print: ({ node, path, print }) => group([ 'enum ', @@ -18,5 +15,3 @@ const EnumDefinition = { '}' ]) }; - -module.exports = EnumDefinition; diff --git a/src/nodes/EnumValue.js b/src/nodes/EnumValue.js index 1e728029c..b2c6e1497 100644 --- a/src/nodes/EnumValue.js +++ b/src/nodes/EnumValue.js @@ -1,5 +1,3 @@ -const EnumValue = { +export const EnumValue = { print: ({ node }) => node.name }; - -module.exports = EnumValue; diff --git a/src/nodes/EventDefinition.js b/src/nodes/EventDefinition.js index 63d4d05a0..47dd9276b 100644 --- a/src/nodes/EventDefinition.js +++ b/src/nodes/EventDefinition.js @@ -1,11 +1,11 @@ -const { printSeparatedList } = require('../common/printer-helpers'); +import { printSeparatedList } from '../common/printer-helpers.js'; const parameters = (node, path, print) => node.parameters && node.parameters.length > 0 ? printSeparatedList(path.map(print, 'parameters')) : ''; -const EventDefinition = { +export const EventDefinition = { print: ({ node, path, print }) => [ 'event ', node.name, @@ -16,5 +16,3 @@ const EventDefinition = { ';' ] }; - -module.exports = EventDefinition; diff --git a/src/nodes/ExpressionStatement.js b/src/nodes/ExpressionStatement.js index bc240ef9e..dbb9d189b 100644 --- a/src/nodes/ExpressionStatement.js +++ b/src/nodes/ExpressionStatement.js @@ -1,12 +1,9 @@ -const { - doc: { - builders: { hardline } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printComments } from '../common/printer-helpers.js'; -const { printComments } = require('../common/printer-helpers'); +const { hardline } = doc.builders; -const ExpressionStatement = { +export const ExpressionStatement = { print: ({ node, options, path, print }) => { const parts = []; @@ -28,5 +25,3 @@ const ExpressionStatement = { return parts; } }; - -module.exports = ExpressionStatement; diff --git a/src/nodes/FileLevelConstant.js b/src/nodes/FileLevelConstant.js index 3ff4dfdea..4d0e141d2 100644 --- a/src/nodes/FileLevelConstant.js +++ b/src/nodes/FileLevelConstant.js @@ -1,4 +1,4 @@ -const FileLevelConstant = { +export const FileLevelConstant = { print: ({ node, path, print }) => [ path.call(print, 'typeName'), ' constant ', @@ -8,5 +8,3 @@ const FileLevelConstant = { ';' ] }; - -module.exports = FileLevelConstant; diff --git a/src/nodes/ForStatement.js b/src/nodes/ForStatement.js index eca7c220d..609a92a7a 100644 --- a/src/nodes/ForStatement.js +++ b/src/nodes/ForStatement.js @@ -1,10 +1,7 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, indent, line } = doc.builders; const initExpression = (node, path, print) => node.initExpression ? path.call(print, 'initExpression') : ''; @@ -20,7 +17,7 @@ const printBody = (node, path, print) => ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])); -const ForStatement = { +export const ForStatement = { print: ({ node, path, print }) => [ 'for (', printSeparatedList( @@ -42,5 +39,3 @@ const ForStatement = { printBody(node, path, print) ] }; - -module.exports = ForStatement; diff --git a/src/nodes/FunctionCall.js b/src/nodes/FunctionCall.js index 283800a38..4168c8b94 100644 --- a/src/nodes/FunctionCall.js +++ b/src/nodes/FunctionCall.js @@ -1,10 +1,7 @@ -const { - doc: { - builders: { group, indentIfBreak, label, line, softline } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, indentIfBreak, label, line, softline } = doc.builders; const printObject = (path, print, options) => { const identifiers = path.map(print, 'identifiers'); @@ -28,7 +25,7 @@ const printArguments = (path, print) => }); let groupIndex = 0; -const FunctionCall = { +export const FunctionCall = { print: ({ node, path, print, options }) => { let expressionDoc = path.call(print, 'expression'); let argumentsDoc = ')'; @@ -61,5 +58,3 @@ const FunctionCall = { return [expressionDoc, '(', argumentsDoc]; } }; - -module.exports = FunctionCall; diff --git a/src/nodes/FunctionDefinition.js b/src/nodes/FunctionDefinition.js index 8e16a9be4..56633450b 100644 --- a/src/nodes/FunctionDefinition.js +++ b/src/nodes/FunctionDefinition.js @@ -1,15 +1,12 @@ -const { - doc: { - builders: { dedent, group, indent, join, line } - } -} = require('prettier'); -const { getNextNonSpaceNonCommentCharacter } = require('../common/util'); - -const { +import { doc } from 'prettier'; +import { getNextNonSpaceNonCommentCharacter } from '../common/util.js'; +import { printComments, printSeparatedItem, printSeparatedList -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { dedent, group, indent, join, line } = doc.builders; const functionName = (node, options) => { if (node.isConstructor && !node.name) return 'constructor'; @@ -94,7 +91,7 @@ const signatureEnd = (node) => (node.body ? dedent(line) : ';'); const body = (node, path, print) => (node.body ? path.call(print, 'body') : ''); -const FunctionDefinition = { +export const FunctionDefinition = { print: ({ node, path, print, options }) => [ group([ functionName(node, options), @@ -118,5 +115,3 @@ const FunctionDefinition = { body(node, path, print) ] }; - -module.exports = FunctionDefinition; diff --git a/src/nodes/FunctionTypeName.js b/src/nodes/FunctionTypeName.js index df19f8f20..688117fa5 100644 --- a/src/nodes/FunctionTypeName.js +++ b/src/nodes/FunctionTypeName.js @@ -1,10 +1,7 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, indent, line } = doc.builders; const returnTypes = (node, path, print) => node.returnTypes.length > 0 @@ -26,7 +23,7 @@ const stateMutability = (node) => ? [line, node.stateMutability] : ''; -const FunctionTypeName = { +export const FunctionTypeName = { print: ({ node, path, print }) => [ 'function(', printSeparatedList(path.map(print, 'parameterTypes')), @@ -40,5 +37,3 @@ const FunctionTypeName = { ) ] }; - -module.exports = FunctionTypeName; diff --git a/src/nodes/HexLiteral.js b/src/nodes/HexLiteral.js index f3037b97b..368d7001a 100644 --- a/src/nodes/HexLiteral.js +++ b/src/nodes/HexLiteral.js @@ -1,16 +1,11 @@ -const { - doc: { - builders: { join, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printString } from '../common/util.js'; -const { printString } = require('../common/util'); +const { join, line } = doc.builders; -const HexLiteral = { +export const HexLiteral = { print: ({ node, options }) => { const list = node.parts.map((part) => `hex${printString(part, options)}`); return join(line, list); } }; - -module.exports = HexLiteral; diff --git a/src/nodes/HexNumber.js b/src/nodes/HexNumber.js index 732d1f2d3..c719a9409 100644 --- a/src/nodes/HexNumber.js +++ b/src/nodes/HexNumber.js @@ -1,5 +1,3 @@ -const HexNumber = { +export const HexNumber = { print: ({ node }) => node.value }; - -module.exports = HexNumber; diff --git a/src/nodes/Identifier.js b/src/nodes/Identifier.js index e3613e004..451d287c0 100644 --- a/src/nodes/Identifier.js +++ b/src/nodes/Identifier.js @@ -1,5 +1,3 @@ -const Identifier = { +export const Identifier = { print: ({ node }) => node.name }; - -module.exports = Identifier; diff --git a/src/nodes/IfStatement.js b/src/nodes/IfStatement.js index 3cfc45fb1..1d9dbc5dc 100644 --- a/src/nodes/IfStatement.js +++ b/src/nodes/IfStatement.js @@ -1,13 +1,10 @@ -const { - doc: { - builders: { group, hardline, indent, line } - } -} = require('prettier'); - -const { +import { doc } from 'prettier'; +import { printComments, printSeparatedItem -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { group, hardline, indent, line } = doc.builders; const printTrueBody = (node, path, print) => { if (node.trueBody.type === 'Block') { @@ -38,7 +35,7 @@ const printElse = (node, path, print, commentsBetweenIfAndElse) => { return ''; }; -const IfStatement = { +export const IfStatement = { print: ({ node, options, path, print }) => { const comments = node.comments || []; const commentsBetweenIfAndElse = comments.filter( @@ -58,5 +55,3 @@ const IfStatement = { return parts; } }; - -module.exports = IfStatement; diff --git a/src/nodes/ImportDirective.js b/src/nodes/ImportDirective.js index d30e41216..225530ff6 100644 --- a/src/nodes/ImportDirective.js +++ b/src/nodes/ImportDirective.js @@ -1,22 +1,19 @@ -const { - doc: { - builders: { group, line, softline } - } -} = require('prettier'); -const coerce = require('semver/functions/coerce'); -const satisfies = require('semver/functions/satisfies'); +import { doc } from 'prettier'; +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; +import { printSeparatedList } from '../common/printer-helpers.js'; +import { printString } from '../common/util.js'; -const { printSeparatedList } = require('../common/printer-helpers'); -const { printString } = require('../common/util'); +const { group, line, softline } = doc.builders; -const ImportDirective = { +export const ImportDirective = { print: ({ node, options }) => { const importPath = printString(node.path, options); - let doc; + let document; if (node.unitAlias) { // import "./Foo.sol" as Foo; - doc = [importPath, ' as ', node.unitAlias]; + document = [importPath, ' as ', node.unitAlias]; } else if (node.symbolAliases) { // import { Foo, Bar as Qux } from "./Foo.sol"; const compiler = coerce(options.compiler); @@ -38,7 +35,7 @@ const ImportDirective = { separator = ', '; } - doc = [ + document = [ '{', printSeparatedList(symbolAliases, { firstSeparator, separator }), '} from ', @@ -46,10 +43,8 @@ const ImportDirective = { ]; } else { // import "./Foo.sol"; - doc = importPath; + document = importPath; } - return group(['import ', doc, ';']); + return group(['import ', document, ';']); } }; - -module.exports = ImportDirective; diff --git a/src/nodes/IndexAccess.js b/src/nodes/IndexAccess.js index 0348330b6..6838775e7 100644 --- a/src/nodes/IndexAccess.js +++ b/src/nodes/IndexAccess.js @@ -1,11 +1,9 @@ -const { - doc: { - builders: { group, indent, indentIfBreak, label, softline } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, indent, indentIfBreak, label, softline } = doc.builders; let groupIndex = 0; -const IndexAccess = { +export const IndexAccess = { print: ({ path, print }) => { let baseDoc = path.call(print, 'base'); let indexDoc = group([ @@ -34,5 +32,3 @@ const IndexAccess = { return [baseDoc, '[', indexDoc]; } }; - -module.exports = IndexAccess; diff --git a/src/nodes/IndexRangeAccess.js b/src/nodes/IndexRangeAccess.js index 1bdc6e35a..aae3e2ddd 100644 --- a/src/nodes/IndexRangeAccess.js +++ b/src/nodes/IndexRangeAccess.js @@ -1,4 +1,4 @@ -const IndexRangeAccess = { +export const IndexRangeAccess = { print: ({ node, path, print }) => [ path.call(print, 'base'), '[', @@ -8,5 +8,3 @@ const IndexRangeAccess = { ']' ] }; - -module.exports = IndexRangeAccess; diff --git a/src/nodes/InheritanceSpecifier.js b/src/nodes/InheritanceSpecifier.js index 5fcb4682a..dbfa1ced9 100644 --- a/src/nodes/InheritanceSpecifier.js +++ b/src/nodes/InheritanceSpecifier.js @@ -1,15 +1,13 @@ -const { printSeparatedList } = require('../common/printer-helpers'); +import { printSeparatedList } from '../common/printer-helpers.js'; const printArguments = (node, path, print) => node.arguments && node.arguments.length ? ['(', printSeparatedList(path.map(print, 'arguments')), ')'] : ''; -const InheritanceSpecifier = { +export const InheritanceSpecifier = { print: ({ node, path, print }) => [ path.call(print, 'baseName'), printArguments(node, path, print) ] }; - -module.exports = InheritanceSpecifier; diff --git a/src/nodes/InlineAssemblyStatement.js b/src/nodes/InlineAssemblyStatement.js index 793d60774..ede3789df 100644 --- a/src/nodes/InlineAssemblyStatement.js +++ b/src/nodes/InlineAssemblyStatement.js @@ -1,8 +1,8 @@ // @TODO: add support for assembly language specifier -const { printString } = require('../common/util'); -const { printSeparatedList } = require('../common/printer-helpers'); +import { printString } from '../common/util.js'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const InlineAssemblyStatement = { +export const InlineAssemblyStatement = { print: ({ node, path, print, options }) => [ 'assembly ', node.language ? `${printString(node.language, options)} ` : '', @@ -18,4 +18,3 @@ const InlineAssemblyStatement = { path.call(print, 'body') ] }; -module.exports = InlineAssemblyStatement; diff --git a/src/nodes/LabelDefinition.js b/src/nodes/LabelDefinition.js index 622251257..bff22d2c2 100644 --- a/src/nodes/LabelDefinition.js +++ b/src/nodes/LabelDefinition.js @@ -1,11 +1,7 @@ -const { - doc: { - builders: { dedent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; -const LabelDefinition = { +const { dedent, line } = doc.builders; + +export const LabelDefinition = { print: ({ node }) => [dedent(line), node.name, ':'] }; - -module.exports = LabelDefinition; diff --git a/src/nodes/Mapping.js b/src/nodes/Mapping.js index 7aab72ce2..03c619489 100644 --- a/src/nodes/Mapping.js +++ b/src/nodes/Mapping.js @@ -7,7 +7,7 @@ const namedParameter = (prefix, node, path, print) => ] : path.call(print, `${prefix}Type`); -const Mapping = { +export const Mapping = { print: ({ node, path, print }) => [ 'mapping(', namedParameter('key', node, path, print), @@ -16,5 +16,3 @@ const Mapping = { ')' ] }; - -module.exports = Mapping; diff --git a/src/nodes/MemberAccess.js b/src/nodes/MemberAccess.js index 698e54ffc..028daa630 100644 --- a/src/nodes/MemberAccess.js +++ b/src/nodes/MemberAccess.js @@ -1,8 +1,6 @@ -const { - doc: { - builders: { group, indent, label, softline } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, indent, label, softline } = doc.builders; const isEndOfChain = (node, path) => { let i = 0; @@ -107,21 +105,19 @@ const processChain = (chain) => { return label('MemberAccessChain', group([firstExpression, restOfChain])); }; -const MemberAccess = { +export const MemberAccess = { print: ({ node, path, print }) => { let expressionDoc = path.call(print, 'expression'); if (Array.isArray(expressionDoc)) { expressionDoc = expressionDoc.flat(); } - const doc = [ + const document = [ expressionDoc, label('separator', [softline, '.']), node.memberName ].flat(); - return isEndOfChain(node, path) ? processChain(doc) : doc; + return isEndOfChain(node, path) ? processChain(document) : document; } }; - -module.exports = MemberAccess; diff --git a/src/nodes/ModifierDefinition.js b/src/nodes/ModifierDefinition.js index 86f2eed5e..46bbcd42b 100644 --- a/src/nodes/ModifierDefinition.js +++ b/src/nodes/ModifierDefinition.js @@ -1,10 +1,7 @@ -const { - doc: { - builders: { group, hardline, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, hardline, indent, line } = doc.builders; const modifierParameters = (node, path, print) => { if (node.parameters && node.parameters.length > 0) { @@ -45,7 +42,7 @@ const body = (node, path, print) => { return [' ', path.call(print, 'body')]; }; -const ModifierDefinition = { +export const ModifierDefinition = { print: ({ node, path, print }) => [ 'modifier ', node.name, @@ -54,5 +51,3 @@ const ModifierDefinition = { body(node, path, print) ] }; - -module.exports = ModifierDefinition; diff --git a/src/nodes/ModifierInvocation.js b/src/nodes/ModifierInvocation.js index 829b48d4b..cd831d06a 100644 --- a/src/nodes/ModifierInvocation.js +++ b/src/nodes/ModifierInvocation.js @@ -1,7 +1,7 @@ -const { +import { printComments, printSeparatedList -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; const modifierArguments = (node, path, print, options) => { if (node.arguments) { @@ -27,11 +27,9 @@ const modifierArguments = (node, path, print, options) => { return ''; }; -const ModifierInvocation = { +export const ModifierInvocation = { print: ({ node, path, print, options }) => [ node.name, modifierArguments(node, path, print, options) ] }; - -module.exports = ModifierInvocation; diff --git a/src/nodes/NameValueExpression.js b/src/nodes/NameValueExpression.js index 91c3cd09b..bb15e55aa 100644 --- a/src/nodes/NameValueExpression.js +++ b/src/nodes/NameValueExpression.js @@ -1,4 +1,4 @@ -const NameValueExpression = { +export const NameValueExpression = { print: ({ path, print }) => [ path.call(print, 'expression'), '{', @@ -6,5 +6,3 @@ const NameValueExpression = { '}' ] }; - -module.exports = NameValueExpression; diff --git a/src/nodes/NameValueList.js b/src/nodes/NameValueList.js index 807e70715..0c97ace30 100644 --- a/src/nodes/NameValueList.js +++ b/src/nodes/NameValueList.js @@ -1,12 +1,9 @@ -const { - doc: { - builders: { line, softline } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { line, softline } = doc.builders; -const NameValueList = { +export const NameValueList = { print: ({ node, path, print, options }) => printSeparatedList( path @@ -17,5 +14,3 @@ const NameValueList = { } ) }; - -module.exports = NameValueList; diff --git a/src/nodes/NewExpression.js b/src/nodes/NewExpression.js index 0d53b0864..66c886976 100644 --- a/src/nodes/NewExpression.js +++ b/src/nodes/NewExpression.js @@ -1,5 +1,3 @@ -const NewExpression = { +export const NewExpression = { print: ({ path, print }) => ['new ', path.call(print, 'typeName')] }; - -module.exports = NewExpression; diff --git a/src/nodes/NumberLiteral.js b/src/nodes/NumberLiteral.js index 2461c7087..d86c8c621 100644 --- a/src/nodes/NumberLiteral.js +++ b/src/nodes/NumberLiteral.js @@ -1,8 +1,6 @@ -const NumberLiteral = { +export const NumberLiteral = { print: ({ node }) => node.subdenomination ? [node.number, ' ', node.subdenomination] : node.number }; - -module.exports = NumberLiteral; diff --git a/src/nodes/PragmaDirective.js b/src/nodes/PragmaDirective.js index c6773a5fe..a05c5da8a 100644 --- a/src/nodes/PragmaDirective.js +++ b/src/nodes/PragmaDirective.js @@ -1,5 +1,3 @@ -const PragmaDirective = { +export const PragmaDirective = { print: ({ node }) => ['pragma ', node.name, ' ', node.value, ';'] }; - -module.exports = PragmaDirective; diff --git a/src/nodes/ReturnStatement.js b/src/nodes/ReturnStatement.js index 9b1d0b28e..e51832004 100644 --- a/src/nodes/ReturnStatement.js +++ b/src/nodes/ReturnStatement.js @@ -1,8 +1,6 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; const expression = (node, path, print) => { if (node.expression) { @@ -13,12 +11,10 @@ const expression = (node, path, print) => { return ''; }; -const ReturnStatement = { +export const ReturnStatement = { print: ({ node, path, print }) => [ 'return', expression(node, path, print), ';' ] }; - -module.exports = ReturnStatement; diff --git a/src/nodes/RevertStatement.js b/src/nodes/RevertStatement.js index 606051bcb..3d0cc49d7 100644 --- a/src/nodes/RevertStatement.js +++ b/src/nodes/RevertStatement.js @@ -1,5 +1,3 @@ -const RevertStatement = { +export const RevertStatement = { print: ({ path, print }) => ['revert ', path.call(print, 'revertCall'), ';'] }; - -module.exports = RevertStatement; diff --git a/src/nodes/SourceUnit.js b/src/nodes/SourceUnit.js index aa9a02ca8..413f97393 100644 --- a/src/nodes/SourceUnit.js +++ b/src/nodes/SourceUnit.js @@ -1,16 +1,11 @@ -const { - doc: { - builders: { line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printPreservingEmptyLines } from '../common/printer-helpers.js'; -const { printPreservingEmptyLines } = require('../common/printer-helpers'); +const { line } = doc.builders; -const SourceUnit = { +export const SourceUnit = { print: ({ options, path, print }) => [ printPreservingEmptyLines(path, 'children', options, print), options.parentParser ? '' : line ] }; - -module.exports = SourceUnit; diff --git a/src/nodes/StateVariableDeclaration.js b/src/nodes/StateVariableDeclaration.js index dfd8a62ce..e9c6fb07a 100644 --- a/src/nodes/StateVariableDeclaration.js +++ b/src/nodes/StateVariableDeclaration.js @@ -1,8 +1,6 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; + +const { group, indent, line } = doc.builders; const initialValue = (node, path, print) => { if (!node.initialValue) { @@ -16,12 +14,10 @@ const initialValue = (node, path, print) => { return group([' =', indent([line, path.call(print, 'initialValue')])]); }; -const StateVariableDeclaration = { +export const StateVariableDeclaration = { print: ({ node, path, print }) => [ ...path.map(print, 'variables'), initialValue(node, path, print), ';' ] }; - -module.exports = StateVariableDeclaration; diff --git a/src/nodes/StringLiteral.js b/src/nodes/StringLiteral.js index 8d24aa459..112e498b4 100644 --- a/src/nodes/StringLiteral.js +++ b/src/nodes/StringLiteral.js @@ -1,11 +1,9 @@ -const { - doc: { - builders: { join, hardline } - } -} = require('prettier'); -const { printString } = require('../common/util'); +import { doc } from 'prettier'; +import { printString } from '../common/util.js'; + +const { join, hardline } = doc.builders; -const StringLiteral = { +export const StringLiteral = { print: ({ node, options }) => { const list = node.parts.map( (part, index) => @@ -17,5 +15,3 @@ const StringLiteral = { return join(hardline, list); } }; - -module.exports = StringLiteral; diff --git a/src/nodes/StructDefinition.js b/src/nodes/StructDefinition.js index 8099c16e7..858eb6366 100644 --- a/src/nodes/StructDefinition.js +++ b/src/nodes/StructDefinition.js @@ -1,12 +1,9 @@ -const { - doc: { - builders: { hardline } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { hardline } = doc.builders; -const StructDefinition = { +export const StructDefinition = { print: ({ node, path, print }) => [ 'struct ', node.name, @@ -21,5 +18,3 @@ const StructDefinition = { '}' ] }; - -module.exports = StructDefinition; diff --git a/src/nodes/ThrowStatement.js b/src/nodes/ThrowStatement.js index 67c484fa4..5b53b99f0 100644 --- a/src/nodes/ThrowStatement.js +++ b/src/nodes/ThrowStatement.js @@ -1,5 +1,3 @@ -const ThrowStatement = { +export const ThrowStatement = { print: () => 'throw;' }; - -module.exports = ThrowStatement; diff --git a/src/nodes/TryStatement.js b/src/nodes/TryStatement.js index 5c07d8e5e..44688d713 100644 --- a/src/nodes/TryStatement.js +++ b/src/nodes/TryStatement.js @@ -1,13 +1,10 @@ -const { - doc: { - builders: { join, line } - } -} = require('prettier'); - -const { +import { doc } from 'prettier'; +import { printSeparatedItem, printSeparatedList -} = require('../common/printer-helpers'); +} from '../common/printer-helpers.js'; + +const { join, line } = doc.builders; const returnParameters = (node, path, print) => node.returnParameters @@ -18,7 +15,7 @@ const returnParameters = (node, path, print) => ] : ''; -const TryStatement = { +export const TryStatement = { print: ({ node, path, print }) => { let parts = [ 'try', @@ -41,5 +38,3 @@ const TryStatement = { return parts; } }; - -module.exports = TryStatement; diff --git a/src/nodes/TupleExpression.js b/src/nodes/TupleExpression.js index 64c8aa2e4..427e9c605 100644 --- a/src/nodes/TupleExpression.js +++ b/src/nodes/TupleExpression.js @@ -1,10 +1,7 @@ -const { - doc: { - builders: { group } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group } = doc.builders; const contents = (node, path, print) => node.components && @@ -13,7 +10,7 @@ const contents = (node, path, print) => ? path.map(print, 'components') : [printSeparatedList(path.map(print, 'components'))]; -const TupleExpression = { +export const TupleExpression = { print: ({ node, path, print }) => group([ node.isArray ? '[' : '(', @@ -21,5 +18,3 @@ const TupleExpression = { node.isArray ? ']' : ')' ]) }; - -module.exports = TupleExpression; diff --git a/src/nodes/TypeDefinition.js b/src/nodes/TypeDefinition.js index d94c337c1..99ac8a43c 100644 --- a/src/nodes/TypeDefinition.js +++ b/src/nodes/TypeDefinition.js @@ -1,5 +1,3 @@ -const TypeDefinition = { +export const TypeDefinition = { print: ({ node }) => ['type ', node.name, ' is ', node.definition.name, ';'] }; - -module.exports = TypeDefinition; diff --git a/src/nodes/UnaryOperation.js b/src/nodes/UnaryOperation.js index d2c7e0345..05dc3809c 100644 --- a/src/nodes/UnaryOperation.js +++ b/src/nodes/UnaryOperation.js @@ -1,4 +1,4 @@ -const UnaryOperation = { +export const UnaryOperation = { print: ({ node, path, print }) => node.isPrefix ? [ @@ -8,5 +8,3 @@ const UnaryOperation = { ] : [path.call(print, 'subExpression'), node.operator] }; - -module.exports = UnaryOperation; diff --git a/src/nodes/UncheckedStatement.js b/src/nodes/UncheckedStatement.js index 2853b0579..4d8ca31a5 100644 --- a/src/nodes/UncheckedStatement.js +++ b/src/nodes/UncheckedStatement.js @@ -1,11 +1,7 @@ -const { - doc: { - builders: { group } - } -} = require('prettier'); +import { doc } from 'prettier'; -const UncheckedStatement = { +const { group } = doc.builders; + +export const UncheckedStatement = { print: ({ path, print }) => group(['unchecked ', path.call(print, 'block')]) }; - -module.exports = UncheckedStatement; diff --git a/src/nodes/UserDefinedTypeName.js b/src/nodes/UserDefinedTypeName.js index 0f4396c13..96f90b8d7 100644 --- a/src/nodes/UserDefinedTypeName.js +++ b/src/nodes/UserDefinedTypeName.js @@ -1,5 +1,3 @@ -const UserDefinedTypeName = { +export const UserDefinedTypeName = { print: ({ node }) => node.namePath }; - -module.exports = UserDefinedTypeName; diff --git a/src/nodes/UsingForDeclaration.js b/src/nodes/UsingForDeclaration.js index 86ff95f27..69a96b9b9 100644 --- a/src/nodes/UsingForDeclaration.js +++ b/src/nodes/UsingForDeclaration.js @@ -1,12 +1,9 @@ -const { - doc: { - builders: { line, softline } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { line, softline } = doc.builders; -const UsingForDeclaration = { +export const UsingForDeclaration = { print: ({ node, path, print, options }) => [ 'using ', node.functions && node.functions.length @@ -30,5 +27,3 @@ const UsingForDeclaration = { node.isGlobal ? ' global;' : ';' ] }; - -module.exports = UsingForDeclaration; diff --git a/src/nodes/VariableDeclaration.js b/src/nodes/VariableDeclaration.js index cdf918737..50bb764dc 100644 --- a/src/nodes/VariableDeclaration.js +++ b/src/nodes/VariableDeclaration.js @@ -1,10 +1,7 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, indent, line } = doc.builders; const indexed = (node) => (node.isIndexed ? ' indexed' : ''); @@ -35,7 +32,7 @@ const override = (node, path, print) => { const name = (node) => (node.name ? [' ', node.name] : ''); -const VariableDeclaration = { +export const VariableDeclaration = { print: ({ node, path, print }) => node.typeName ? group([ @@ -52,5 +49,3 @@ const VariableDeclaration = { ]) : node.name }; - -module.exports = VariableDeclaration; diff --git a/src/nodes/VariableDeclarationStatement.js b/src/nodes/VariableDeclarationStatement.js index b7b0fcb52..100ba15c8 100644 --- a/src/nodes/VariableDeclarationStatement.js +++ b/src/nodes/VariableDeclarationStatement.js @@ -1,19 +1,16 @@ -const { - doc: { - builders: { group, indentIfBreak } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedList } from '../common/printer-helpers.js'; -const { printSeparatedList } = require('../common/printer-helpers'); +const { group, indentIfBreak } = doc.builders; -const embraceVariables = (doc, embrace) => - embrace ? ['(', printSeparatedList(doc), ')'] : doc; +const embraceVariables = (document, embrace) => + embrace ? ['(', printSeparatedList(document), ')'] : document; const initialValue = (node, path, print) => node.initialValue ? [' = ', path.call(print, 'initialValue')] : ''; let groupIndex = 0; -const VariableDeclarationStatement = { +export const VariableDeclarationStatement = { print: ({ node, path, print }) => { const startsWithVar = node.variables.filter((x) => x && x.typeName).length === 0; @@ -40,5 +37,3 @@ const VariableDeclarationStatement = { ]); } }; - -module.exports = VariableDeclarationStatement; diff --git a/src/nodes/WhileStatement.js b/src/nodes/WhileStatement.js index 89f1e3b0c..778b618e3 100644 --- a/src/nodes/WhileStatement.js +++ b/src/nodes/WhileStatement.js @@ -1,17 +1,14 @@ -const { - doc: { - builders: { group, indent, line } - } -} = require('prettier'); +import { doc } from 'prettier'; +import { printSeparatedItem } from '../common/printer-helpers.js'; -const { printSeparatedItem } = require('../common/printer-helpers'); +const { group, indent, line } = doc.builders; const printBody = (node, path, print) => node.body.type === 'Block' ? [' ', path.call(print, 'body')] : group(indent([line, path.call(print, 'body')])); -const WhileStatement = { +export const WhileStatement = { print: ({ node, path, print }) => [ 'while (', printSeparatedItem(path.call(print, 'condition')), @@ -19,5 +16,3 @@ const WhileStatement = { printBody(node, path, print) ] }; - -module.exports = WhileStatement; diff --git a/src/nodes/index.js b/src/nodes/index.js index 30e601276..179299865 100644 --- a/src/nodes/index.js +++ b/src/nodes/index.js @@ -1,78 +1,72 @@ -/* This file was automatically generated on 1666691919.885 */ - -/* eslint-disable global-require */ - -module.exports = { - ArrayTypeName: require('./ArrayTypeName'), - AssemblyAssignment: require('./AssemblyAssignment'), - AssemblyBlock: require('./AssemblyBlock'), - AssemblyCall: require('./AssemblyCall'), - AssemblyCase: require('./AssemblyCase'), - AssemblyFor: require('./AssemblyFor'), - AssemblyFunctionDefinition: require('./AssemblyFunctionDefinition'), - AssemblyIf: require('./AssemblyIf'), - AssemblyLocalDefinition: require('./AssemblyLocalDefinition'), - AssemblyMemberAccess: require('./AssemblyMemberAccess'), - AssemblyStackAssignment: require('./AssemblyStackAssignment'), - AssemblySwitch: require('./AssemblySwitch'), - BinaryOperation: require('./BinaryOperation'), - Block: require('./Block'), - BooleanLiteral: require('./BooleanLiteral'), - Break: require('./Break'), - BreakStatement: require('./BreakStatement'), - CatchClause: require('./CatchClause'), - Conditional: require('./Conditional'), - Continue: require('./Continue'), - ContinueStatement: require('./ContinueStatement'), - ContractDefinition: require('./ContractDefinition'), - CustomErrorDefinition: require('./CustomErrorDefinition'), - DecimalNumber: require('./DecimalNumber'), - DoWhileStatement: require('./DoWhileStatement'), - ElementaryTypeName: require('./ElementaryTypeName'), - EmitStatement: require('./EmitStatement'), - EnumDefinition: require('./EnumDefinition'), - EnumValue: require('./EnumValue'), - EventDefinition: require('./EventDefinition'), - ExpressionStatement: require('./ExpressionStatement'), - FileLevelConstant: require('./FileLevelConstant'), - ForStatement: require('./ForStatement'), - FunctionCall: require('./FunctionCall'), - FunctionDefinition: require('./FunctionDefinition'), - FunctionTypeName: require('./FunctionTypeName'), - HexLiteral: require('./HexLiteral'), - HexNumber: require('./HexNumber'), - Identifier: require('./Identifier'), - IfStatement: require('./IfStatement'), - ImportDirective: require('./ImportDirective'), - IndexAccess: require('./IndexAccess'), - IndexRangeAccess: require('./IndexRangeAccess'), - InheritanceSpecifier: require('./InheritanceSpecifier'), - InlineAssemblyStatement: require('./InlineAssemblyStatement'), - LabelDefinition: require('./LabelDefinition'), - Mapping: require('./Mapping'), - MemberAccess: require('./MemberAccess'), - ModifierDefinition: require('./ModifierDefinition'), - ModifierInvocation: require('./ModifierInvocation'), - NameValueExpression: require('./NameValueExpression'), - NameValueList: require('./NameValueList'), - NewExpression: require('./NewExpression'), - NumberLiteral: require('./NumberLiteral'), - PragmaDirective: require('./PragmaDirective'), - ReturnStatement: require('./ReturnStatement'), - RevertStatement: require('./RevertStatement'), - SourceUnit: require('./SourceUnit'), - StateVariableDeclaration: require('./StateVariableDeclaration'), - StringLiteral: require('./StringLiteral'), - StructDefinition: require('./StructDefinition'), - ThrowStatement: require('./ThrowStatement'), - TryStatement: require('./TryStatement'), - TupleExpression: require('./TupleExpression'), - TypeDefinition: require('./TypeDefinition'), - UnaryOperation: require('./UnaryOperation'), - UncheckedStatement: require('./UncheckedStatement'), - UserDefinedTypeName: require('./UserDefinedTypeName'), - UsingForDeclaration: require('./UsingForDeclaration'), - VariableDeclaration: require('./VariableDeclaration'), - VariableDeclarationStatement: require('./VariableDeclarationStatement'), - WhileStatement: require('./WhileStatement') -}; +export * from './ArrayTypeName.js'; +export * from './AssemblyAssignment.js'; +export * from './AssemblyBlock.js'; +export * from './AssemblyCall.js'; +export * from './AssemblyCase.js'; +export * from './AssemblyFor.js'; +export * from './AssemblyFunctionDefinition.js'; +export * from './AssemblyIf.js'; +export * from './AssemblyLocalDefinition.js'; +export * from './AssemblyMemberAccess.js'; +export * from './AssemblyStackAssignment.js'; +export * from './AssemblySwitch.js'; +export * from './BinaryOperation.js'; +export * from './Block.js'; +export * from './BooleanLiteral.js'; +export * from './Break.js'; +export * from './BreakStatement.js'; +export * from './CatchClause.js'; +export * from './Conditional.js'; +export * from './Continue.js'; +export * from './ContinueStatement.js'; +export * from './ContractDefinition.js'; +export * from './CustomErrorDefinition.js'; +export * from './DecimalNumber.js'; +export * from './DoWhileStatement.js'; +export * from './ElementaryTypeName.js'; +export * from './EmitStatement.js'; +export * from './EnumDefinition.js'; +export * from './EnumValue.js'; +export * from './EventDefinition.js'; +export * from './ExpressionStatement.js'; +export * from './FileLevelConstant.js'; +export * from './ForStatement.js'; +export * from './FunctionCall.js'; +export * from './FunctionDefinition.js'; +export * from './FunctionTypeName.js'; +export * from './HexLiteral.js'; +export * from './HexNumber.js'; +export * from './Identifier.js'; +export * from './IfStatement.js'; +export * from './ImportDirective.js'; +export * from './IndexAccess.js'; +export * from './IndexRangeAccess.js'; +export * from './InheritanceSpecifier.js'; +export * from './InlineAssemblyStatement.js'; +export * from './LabelDefinition.js'; +export * from './Mapping.js'; +export * from './MemberAccess.js'; +export * from './ModifierDefinition.js'; +export * from './ModifierInvocation.js'; +export * from './NameValueExpression.js'; +export * from './NameValueList.js'; +export * from './NewExpression.js'; +export * from './NumberLiteral.js'; +export * from './PragmaDirective.js'; +export * from './ReturnStatement.js'; +export * from './RevertStatement.js'; +export * from './SourceUnit.js'; +export * from './StateVariableDeclaration.js'; +export * from './StringLiteral.js'; +export * from './StructDefinition.js'; +export * from './ThrowStatement.js'; +export * from './TryStatement.js'; +export * from './TupleExpression.js'; +export * from './TypeDefinition.js'; +export * from './UnaryOperation.js'; +export * from './UncheckedStatement.js'; +export * from './UserDefinedTypeName.js'; +export * from './UsingForDeclaration.js'; +export * from './VariableDeclaration.js'; +export * from './VariableDeclarationStatement.js'; +export * from './WhileStatement.js'; diff --git a/src/options.js b/src/options.js index 4cec7325c..bbd003f9b 100644 --- a/src/options.js +++ b/src/options.js @@ -48,4 +48,4 @@ const options = { } }; -module.exports = options; +export default options; diff --git a/src/parser.js b/src/parser.js index 3dabdcba9..5a9df23a9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,8 +1,8 @@ -const extractComments = require('solidity-comments-extractor'); +import extractComments from 'solidity-comments-extractor'; // https://prettier.io/docs/en/plugins.html#parsers -const parser = require('@solidity-parser/parser'); -const coerce = require('semver/functions/coerce'); -const satisfies = require('semver/functions/satisfies'); +import parser from '@solidity-parser/parser'; +import coerce from 'semver/functions/coerce.js'; +import satisfies from 'semver/functions/satisfies.js'; const tryHug = (node, operators) => { if (node.type === 'BinaryOperation' && operators.includes(node.operator)) @@ -184,4 +184,4 @@ function parse(text, _parsers, options = _parsers) { return parsed; } -module.exports = parse; +export default parse; diff --git a/src/prettier-comments/index.js b/src/prettier-comments/index.js deleted file mode 100644 index 33cc56246..000000000 --- a/src/prettier-comments/index.js +++ /dev/null @@ -1,3 +0,0 @@ -const comments = require('./language-js/comments'); - -module.exports = { handleComments: comments }; diff --git a/src/prettier-comments/language-js/comments.js b/src/prettier-comments/language-js/comments.js index 628076533..20c986021 100644 --- a/src/prettier-comments/language-js/comments.js +++ b/src/prettier-comments/language-js/comments.js @@ -1,17 +1,15 @@ -"use strict"; +import { util } from "prettier"; +import { getNextNonSpaceNonCommentCharacter } from "../../common/util.js"; const { - util: { - addLeadingComment, - addTrailingComment, - addDanglingComment, - hasNewline, - hasNewlineInRange - } -} = require('prettier'); -const { getNextNonSpaceNonCommentCharacter, getNextNonSpaceNonCommentCharacterIndex} = require("../../common/util"); - -function handleOwnLineComment(comment, text, options, ast, isLastComment) { + addLeadingComment, + addTrailingComment, + addDanglingComment, + hasNewline, + hasNewlineInRange +} = util + +export function handleOwnLineComment(comment, text, options, ast, isLastComment) { const { precedingNode, enclosingNode, followingNode } = comment; if ( handleLastFunctionArgComments( @@ -76,7 +74,7 @@ function handleOwnLineComment(comment, text, options, ast, isLastComment) { return false; } -function handleEndOfLineComment(comment, text, options, ast, isLastComment) { +export function handleEndOfLineComment(comment, text, options, ast, isLastComment) { const { precedingNode, enclosingNode, followingNode } = comment; if ( handleLastFunctionArgComments( @@ -131,7 +129,7 @@ function handleEndOfLineComment(comment, text, options, ast, isLastComment) { return false; } -function handleRemainingComment(comment, text, options, ast, isLastComment) { +export function handleRemainingComment(comment, text, options, ast, isLastComment) { const { precedingNode, enclosingNode, followingNode } = comment; if ( @@ -833,13 +831,6 @@ function handleTSMappedTypeComments( return false; } -function isBlockComment(comment) { +export function isBlockComment(comment) { return comment.type === "Block" || comment.type === "CommentBlock"; } - -module.exports = { - handleOwnLineComment, - handleEndOfLineComment, - handleRemainingComment, - isBlockComment -}; diff --git a/src/printer.js b/src/printer.js index a73fb8f29..e725b1de4 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1,9 +1,9 @@ -const nodes = require('./nodes'); -const { +import * as nodes from './nodes/index.js'; +import { hasNodeIgnoreComment, prettierVersionSatisfies -} = require('./common/util'); -const ignoreComments = require('./comments/ignore'); +} from './common/util.js'; +import ignoreComments from './comments/ignore.js'; let checked = false; @@ -41,4 +41,4 @@ function genericPrint(path, options, print) { return nodes[node.type].print({ node, options, path, print }); } -module.exports = genericPrint; +export default genericPrint; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 10dc7083c..7c3a3ed74 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -1,18 +1,17 @@ -"use strict"; - -const { TEST_STANDALONE } = process.env; - -const fs = require("fs"); -const path = require("path"); -const prettier = !TEST_STANDALONE - ? require("./require-prettier") - : require("./require-standalone"); -const createSnapshot = require("./utils/create-snapshot"); -const visualizeEndOfLine = require("./utils/visualize-end-of-line"); -const consistentEndOfLine = require("./utils/consistent-end-of-line"); -const stringifyOptionsForTitle = require("./utils/stringify-options-for-title"); - -const { FULL_TEST } = process.env; +import fs from "node:fs"; +import path from "node:path"; +import url from "node:url"; +import createEsmUtils from "esm-utils"; +import getPrettier from "./get-prettier.js"; +import compileContract from "./utils/compile-contract.js"; +import createSnapshot from "./utils/create-snapshot.js"; +import visualizeEndOfLine from "./utils/visualize-end-of-line.js"; +import consistentEndOfLine from "./utils/consistent-end-of-line.js"; +import stringifyOptionsForTitle from "./utils/stringify-options-for-title.js"; + +const { __dirname } = createEsmUtils(import.meta); + +const { FULL_TEST, TEST_STANDALONE } = process.env; const BOM = "\uFEFF"; const CURSOR_PLACEHOLDER = "<|>"; @@ -114,8 +113,10 @@ const isTestDirectory = (dirname, name) => ); function runSpec(fixtures, parsers, options) { - let { dirname, snippets = [] } = - typeof fixtures === "string" ? { dirname: fixtures } : fixtures; + let { importMeta, snippets = [] } = fixtures.importMeta + ? fixtures + : { importMeta: fixtures }; + const dirname = path.dirname(url.fileURLToPath(importMeta.url)); // `IS_PARSER_INFERENCE_TESTS` mean to test `inferParser` on `standalone` const IS_PARSER_INFERENCE_TESTS = isTestDirectory( @@ -137,6 +138,11 @@ function runSpec(fixtures, parsers, options) { snippets = snippets.map((test, index) => { test = typeof test === "string" ? { code: test } : test; + + if (typeof test.code !== "string") { + throw Object.assign(new Error("Invalid test"), { test }); + } + return { ...test, name: `snippet: ${test.name || `#${index}`}`, @@ -181,15 +187,10 @@ function runSpec(fixtures, parsers, options) { describe(title, () => { const formatOptions = { - plugins: [ - path.join( - __dirname, - TEST_STANDALONE ? "../../dist/standalone.js" : "../../src/index.js" - ), - ], + plugins: TEST_STANDALONE + ? [] + : [path.join(__dirname, "../../src/index.js")], printWidth: 80, - // Should not search plugins by default - pluginSearchDirs: false, ...options, filepath: filename, parser, @@ -350,13 +351,6 @@ async function runTest({ } if (shouldCompareBytecode(filename, formatOptions)) { - // We require the compiler here as it makes all tests slow when added at - // the top of the file. - // TODO investigate this warning - // - A worker process has failed to exit gracefully and has been force - // exited. This is likely caused by tests leaking due to improper - // teardown. Try running with --detectOpenHandles to find leaks. - const compileContract = require("./utils/compile-contract"); const output = compileContract(filename, formatResult.output); const expected = compileContract(filename, formatResult.input); expect(output).toEqual(expected); @@ -383,6 +377,7 @@ function shouldSkipEolTest(code, options) { } async function parse(source, options) { + const prettier = await getPrettier(); const { ast } = await prettier.__debug.parse(source, options, { massage: true, }); @@ -435,6 +430,7 @@ async function format(originalText, originalOptions) { originalOptions ); const inputWithCursor = insertCursor(input, options.cursorOffset); + const prettier = await getPrettier(); const { formatted: output, cursorOffset } = await prettier.formatWithCursor( input, @@ -456,4 +452,4 @@ async function format(originalText, originalOptions) { }; } -module.exports = runSpec; +export default runSpec; diff --git a/tests/config/get-prettier.js b/tests/config/get-prettier.js new file mode 100644 index 000000000..5d72040c0 --- /dev/null +++ b/tests/config/get-prettier.js @@ -0,0 +1,16 @@ +function getPrettierInternal() { + const entry = process.env.TEST_STANDALONE + ? new URL("./require-standalone.cjs", import.meta.url) + : new URL("./require-prettier.cjs", import.meta.url); + + return import(entry).then((module) => module.default); +} + +let promise; +function getPrettier() { + promise = promise ?? getPrettierInternal(); + + return promise; +} + +export default getPrettier; diff --git a/tests/config/require-prettier.js b/tests/config/require-prettier.cjs similarity index 100% rename from tests/config/require-prettier.js rename to tests/config/require-prettier.cjs diff --git a/tests/config/require-standalone.js b/tests/config/require-standalone.cjs similarity index 70% rename from tests/config/require-standalone.js rename to tests/config/require-standalone.cjs index fe1e7de7b..2f2c10bbc 100644 --- a/tests/config/require-standalone.js +++ b/tests/config/require-standalone.cjs @@ -2,11 +2,12 @@ const path = require("path"); const vm = require("vm"); -const createSandBox = require("./utils/create-sandbox"); -const { isPrettier2 } = require("../../src/common/util"); +const prettier = require("prettier"); +const satisfies = require("semver/functions/satisfies"); +const createSandBox = require("./utils/create-sandbox.cjs"); const prettierPath = path.dirname(require.resolve("prettier")); -const pluginPrefix = isPrettier2() +const pluginPrefix = satisfies(prettier.version, "^2.3.0") ? "parser-" // Prettier V2 : "plugins/"; // Prettier V3 @@ -15,7 +16,7 @@ const sandbox = createSandBox({ path.join(prettierPath, "standalone.js"), path.join(prettierPath, `${pluginPrefix}babel.js`), path.join(prettierPath, `${pluginPrefix}markdown.js`), - path.join(__dirname, "../../dist/standalone.js"), + path.join(__dirname, "../../dist/standalone.cjs"), ], }); @@ -39,7 +40,7 @@ module.exports = { }, __debug: { - parse(input, options, massage) { + parse(input, options, devOptions) { return vm.runInNewContext( ` const options = { @@ -49,9 +50,14 @@ module.exports = { ...($$$options.plugins || []), ], }; - prettier.__debug.parse($$$input, options, ${JSON.stringify(massage)}); + prettier.__debug.parse($$$input, options, $$$devOptions); `, - { $$$input: input, $$$options: options, ...sandbox } + { + $$$input: input, + $$$options: options, + $$$devOptions: devOptions, + ...sandbox, + } ); }, }, diff --git a/tests/config/setup.js b/tests/config/setup.js index 7ae0b4cd7..3d3b8b4c7 100644 --- a/tests/config/setup.js +++ b/tests/config/setup.js @@ -1,7 +1,3 @@ -"use strict"; +import runSpec from "./format-test.js"; -Object.defineProperty(global, "run_spec", { - get() { - return require("./format-test"); - }, -}); +globalThis.run_spec = runSpec; diff --git a/tests/config/utils/compile-contract.js b/tests/config/utils/compile-contract.js index 785fb3887..57e315954 100644 --- a/tests/config/utils/compile-contract.js +++ b/tests/config/utils/compile-contract.js @@ -1,6 +1,16 @@ -const solc = require("solc"); +function importSolcInternal() { + return import("solc").then((module) => module.default); +} + +let promise; +function importSolc() { + promise = promise ?? importSolcInternal(); + + return promise; +} -function compileContract(filename, content) { +async function compileContract(filename, content) { + const solc = await importSolc(); const input = { language: "Solidity", sources: { @@ -34,4 +44,4 @@ function compileContract(filename, content) { ); } -module.exports = compileContract; +export default compileContract; diff --git a/tests/config/utils/consistent-end-of-line.js b/tests/config/utils/consistent-end-of-line.js index 63d990181..e618ab542 100644 --- a/tests/config/utils/consistent-end-of-line.js +++ b/tests/config/utils/consistent-end-of-line.js @@ -1,13 +1,9 @@ -"use strict"; - function consistentEndOfLine(text) { let firstEndOfLine; return text.replace(/\r\n?|\n/g, (endOfLine) => { - if (!firstEndOfLine) { - firstEndOfLine = endOfLine; - } + firstEndOfLine = firstEndOfLine ?? endOfLine; return firstEndOfLine; }); } -module.exports = consistentEndOfLine; +export default consistentEndOfLine; diff --git a/tests/config/utils/create-sandbox.js b/tests/config/utils/create-sandbox.cjs similarity index 100% rename from tests/config/utils/create-sandbox.js rename to tests/config/utils/create-sandbox.cjs diff --git a/tests/config/utils/create-snapshot.js b/tests/config/utils/create-snapshot.js index 19ee0e10b..c0d9003c4 100644 --- a/tests/config/utils/create-snapshot.js +++ b/tests/config/utils/create-snapshot.js @@ -1,8 +1,6 @@ -"use strict"; - -const raw = require("jest-snapshot-serializer-raw").wrap; -const visualizeRange = require("./visualize-range"); -const visualizeEndOfLine = require("./visualize-end-of-line"); +import { wrap as raw } from "jest-snapshot-serializer-raw"; +import visualizeRange from "./visualize-range.js"; +import visualizeEndOfLine from "./visualize-end-of-line.js"; const SEPARATOR_WIDTH = 80; function printSeparator(description = "") { @@ -25,15 +23,10 @@ function printOptions(options) { filepath, errors, parser, - pluginSearchDirs, ...snapshotOptions } = options; - if (pluginSearchDirs !== false) { - snapshotOptions.pluginSearchDirs = pluginSearchDirs; - } - const keys = Object.keys(snapshotOptions).sort(); return keys .map((key) => `${key}: ${stringify(snapshotOptions[key])}`) @@ -100,4 +93,4 @@ function createSnapshot( ); } -module.exports = createSnapshot; +export default createSnapshot; diff --git a/tests/config/utils/stringify-options-for-title.js b/tests/config/utils/stringify-options-for-title.js index dbc95627f..7591265a8 100644 --- a/tests/config/utils/stringify-options-for-title.js +++ b/tests/config/utils/stringify-options-for-title.js @@ -1,5 +1,3 @@ -"use strict"; - function stringifyOptions(options) { const string = JSON.stringify(options || {}, (key, value) => key === "plugins" || key === "errors" @@ -12,4 +10,4 @@ function stringifyOptions(options) { return string === "{}" ? "" : string; } -module.exports = stringifyOptions; +export default stringifyOptions; diff --git a/tests/config/utils/visualize-end-of-line.js b/tests/config/utils/visualize-end-of-line.js index 13a30befc..9dec987e0 100644 --- a/tests/config/utils/visualize-end-of-line.js +++ b/tests/config/utils/visualize-end-of-line.js @@ -1,5 +1,3 @@ -"use strict"; - function visualizeEndOfLine(text) { return text.replace(/\r\n?|\n/g, (endOfLine) => { switch (endOfLine) { @@ -15,4 +13,4 @@ function visualizeEndOfLine(text) { }); } -module.exports = visualizeEndOfLine; +export default visualizeEndOfLine; diff --git a/tests/config/utils/visualize-range.js b/tests/config/utils/visualize-range.js index 7fca537b0..6d3762f7f 100644 --- a/tests/config/utils/visualize-range.js +++ b/tests/config/utils/visualize-range.js @@ -1,7 +1,5 @@ -"use strict"; - -const LinesAndColumns = require("lines-and-columns").default; -const { codeFrameColumns } = require("@babel/code-frame"); +import { LinesAndColumns } from "lines-and-columns"; +import { codeFrameColumns } from "@babel/code-frame"; const codeFrameColumnsOptions = { linesAbove: Number.POSITIVE_INFINITY, linesBelow: Number.POSITIVE_INFINITY, @@ -37,4 +35,4 @@ const visualizeRange = (text, { rangeStart = 0, rangeEnd = text.length }) => : codeFrameColumnsOptions ); -module.exports = visualizeRange; +export default visualizeRange; diff --git a/tests/format/AddressPayable/jsfmt.spec.js b/tests/format/AddressPayable/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/AddressPayable/jsfmt.spec.js +++ b/tests/format/AddressPayable/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/AllSolidityFeatures/jsfmt.spec.js b/tests/format/AllSolidityFeatures/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/AllSolidityFeatures/jsfmt.spec.js +++ b/tests/format/AllSolidityFeatures/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Arrays/jsfmt.spec.js b/tests/format/Arrays/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Arrays/jsfmt.spec.js +++ b/tests/format/Arrays/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Assembly/jsfmt.spec.js b/tests/format/Assembly/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Assembly/jsfmt.spec.js +++ b/tests/format/Assembly/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/BasicIterator/jsfmt.spec.js b/tests/format/BasicIterator/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/BasicIterator/jsfmt.spec.js +++ b/tests/format/BasicIterator/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/BinaryOperators/jsfmt.spec.js b/tests/format/BinaryOperators/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/BinaryOperators/jsfmt.spec.js +++ b/tests/format/BinaryOperators/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js index 1a456f86f..b64637462 100644 --- a/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.7.4/jsfmt.spec.js @@ -1,14 +1,14 @@ -run_spec(__dirname, ['solidity-parse'], { compiler: '0.7.4' }); -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.4' }); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.4', bracketSpacing: true }); -run_spec(__dirname, ['solidity-parse'], { compiler: '0.7.3' }); -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.3' }); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.3', bracketSpacing: true }); -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js index 673f748d6..037d673ba 100644 --- a/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js +++ b/tests/format/BreakingChangesV0.8.0/jsfmt.spec.js @@ -1,3 +1,3 @@ -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { compiler: '0.8.0' }); -run_spec(__dirname, ['solidity-parse'], { compiler: '0.7.0' }); +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.0' }); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.7.0' }); diff --git a/tests/format/Comments/jsfmt.spec.js b/tests/format/Comments/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Comments/jsfmt.spec.js +++ b/tests/format/Comments/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Conditional/jsfmt.spec.js b/tests/format/Conditional/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Conditional/jsfmt.spec.js +++ b/tests/format/Conditional/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Constructors/jsfmt.spec.js b/tests/format/Constructors/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Constructors/jsfmt.spec.js +++ b/tests/format/Constructors/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ContractDefinitions/jsfmt.spec.js b/tests/format/ContractDefinitions/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/ContractDefinitions/jsfmt.spec.js +++ b/tests/format/ContractDefinitions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/CustomErrors/jsfmt.spec.js b/tests/format/CustomErrors/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/CustomErrors/jsfmt.spec.js +++ b/tests/format/CustomErrors/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/EnumDefinitions/jsfmt.spec.js b/tests/format/EnumDefinitions/jsfmt.spec.js index ba3fe57a9..993a81764 100644 --- a/tests/format/EnumDefinitions/jsfmt.spec.js +++ b/tests/format/EnumDefinitions/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/Etc/jsfmt.spec.js b/tests/format/Etc/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Etc/jsfmt.spec.js +++ b/tests/format/Etc/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ForStatements/jsfmt.spec.js b/tests/format/ForStatements/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/ForStatements/jsfmt.spec.js +++ b/tests/format/ForStatements/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/FunctionCalls/jsfmt.spec.js b/tests/format/FunctionCalls/jsfmt.spec.js index ba3fe57a9..993a81764 100644 --- a/tests/format/FunctionCalls/jsfmt.spec.js +++ b/tests/format/FunctionCalls/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/FunctionDefinitions/jsfmt.spec.js b/tests/format/FunctionDefinitions/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/FunctionDefinitions/jsfmt.spec.js +++ b/tests/format/FunctionDefinitions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/HexLiteral/jsfmt.spec.js b/tests/format/HexLiteral/jsfmt.spec.js index 4f7c61e3b..ac4400e7d 100644 --- a/tests/format/HexLiteral/jsfmt.spec.js +++ b/tests/format/HexLiteral/jsfmt.spec.js @@ -1,8 +1,8 @@ -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6', singleQuote: true }); -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6', singleQuote: false }); diff --git a/tests/format/IfStatements/jsfmt.spec.js b/tests/format/IfStatements/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/IfStatements/jsfmt.spec.js +++ b/tests/format/IfStatements/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Immutable/jsfmt.spec.js b/tests/format/Immutable/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Immutable/jsfmt.spec.js +++ b/tests/format/Immutable/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ImportDirective/jsfmt.spec.js b/tests/format/ImportDirective/jsfmt.spec.js index ba3fe57a9..993a81764 100644 --- a/tests/format/ImportDirective/jsfmt.spec.js +++ b/tests/format/ImportDirective/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/Inbox/jsfmt.spec.js b/tests/format/Inbox/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Inbox/jsfmt.spec.js +++ b/tests/format/Inbox/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/IndexOf/jsfmt.spec.js b/tests/format/IndexOf/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/IndexOf/jsfmt.spec.js +++ b/tests/format/IndexOf/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/IndexRangeAccess/jsfmt.spec.js b/tests/format/IndexRangeAccess/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/IndexRangeAccess/jsfmt.spec.js +++ b/tests/format/IndexRangeAccess/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/InheritanceSpecifier/jsfmt.spec.js b/tests/format/InheritanceSpecifier/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/InheritanceSpecifier/jsfmt.spec.js +++ b/tests/format/InheritanceSpecifier/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Issues/jsfmt.spec.js b/tests/format/Issues/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Issues/jsfmt.spec.js +++ b/tests/format/Issues/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Libraries/jsfmt.spec.js b/tests/format/Libraries/jsfmt.spec.js index ba3fe57a9..993a81764 100644 --- a/tests/format/Libraries/jsfmt.spec.js +++ b/tests/format/Libraries/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/Markdown/jsfmt.spec.js b/tests/format/Markdown/jsfmt.spec.js index fbebb4cf8..cca2da906 100644 --- a/tests/format/Markdown/jsfmt.spec.js +++ b/tests/format/Markdown/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['markdown']); +run_spec(import.meta, ['markdown']); diff --git a/tests/format/MemberAccess/jsfmt.spec.js b/tests/format/MemberAccess/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/MemberAccess/jsfmt.spec.js +++ b/tests/format/MemberAccess/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ModifierDefinitions/jsfmt.spec.js b/tests/format/ModifierDefinitions/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/ModifierDefinitions/jsfmt.spec.js +++ b/tests/format/ModifierDefinitions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/ModifierInvocations/jsfmt.spec.js b/tests/format/ModifierInvocations/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/ModifierInvocations/jsfmt.spec.js +++ b/tests/format/ModifierInvocations/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/MultipartStrings/jsfmt.spec.js b/tests/format/MultipartStrings/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/MultipartStrings/jsfmt.spec.js +++ b/tests/format/MultipartStrings/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/NameValueExpression/jsfmt.spec.js b/tests/format/NameValueExpression/jsfmt.spec.js index ba3fe57a9..993a81764 100644 --- a/tests/format/NameValueExpression/jsfmt.spec.js +++ b/tests/format/NameValueExpression/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ['solidity-parse']); -run_spec(__dirname, ['solidity-parse'], { bracketSpacing: true }); +run_spec(import.meta, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse'], { bracketSpacing: true }); diff --git a/tests/format/Ownable/jsfmt.spec.js b/tests/format/Ownable/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Ownable/jsfmt.spec.js +++ b/tests/format/Ownable/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Parentheses/jsfmt.spec.js b/tests/format/Parentheses/jsfmt.spec.js index 0a6065ad8..8c772cba0 100644 --- a/tests/format/Parentheses/jsfmt.spec.js +++ b/tests/format/Parentheses/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse'], { compiler: '0.8.6' }); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.6' }); diff --git a/tests/format/Pragma/jsfmt.spec.js b/tests/format/Pragma/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Pragma/jsfmt.spec.js +++ b/tests/format/Pragma/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/PrettierIgnore/jsfmt.spec.js b/tests/format/PrettierIgnore/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/PrettierIgnore/jsfmt.spec.js +++ b/tests/format/PrettierIgnore/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Proxy/jsfmt.spec.js b/tests/format/Proxy/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Proxy/jsfmt.spec.js +++ b/tests/format/Proxy/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/RespectDefaultOptions/jsfmt.spec.js b/tests/format/RespectDefaultOptions/jsfmt.spec.js index c14a298f2..21d1d2cb5 100644 --- a/tests/format/RespectDefaultOptions/jsfmt.spec.js +++ b/tests/format/RespectDefaultOptions/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['babel']); +run_spec(import.meta, ['babel']); diff --git a/tests/format/SampleCrowdsale/jsfmt.spec.js b/tests/format/SampleCrowdsale/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/SampleCrowdsale/jsfmt.spec.js +++ b/tests/format/SampleCrowdsale/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/SimpleAuction/jsfmt.spec.js b/tests/format/SimpleAuction/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/SimpleAuction/jsfmt.spec.js +++ b/tests/format/SimpleAuction/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/SimpleStorage/jsfmt.spec.js b/tests/format/SimpleStorage/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/SimpleStorage/jsfmt.spec.js +++ b/tests/format/SimpleStorage/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/SplittableCommodity/jsfmt.spec.js b/tests/format/SplittableCommodity/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/SplittableCommodity/jsfmt.spec.js +++ b/tests/format/SplittableCommodity/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/StateVariableDeclarations/jsfmt.spec.js b/tests/format/StateVariableDeclarations/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/StateVariableDeclarations/jsfmt.spec.js +++ b/tests/format/StateVariableDeclarations/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/StringLiteral/jsfmt.spec.js b/tests/format/StringLiteral/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/StringLiteral/jsfmt.spec.js +++ b/tests/format/StringLiteral/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/StyleGuide/jsfmt.spec.js b/tests/format/StyleGuide/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/StyleGuide/jsfmt.spec.js +++ b/tests/format/StyleGuide/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/TryCatch/jsfmt.spec.js b/tests/format/TryCatch/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/TryCatch/jsfmt.spec.js +++ b/tests/format/TryCatch/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/Tupples/jsfmt.spec.js b/tests/format/Tupples/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/Tupples/jsfmt.spec.js +++ b/tests/format/Tupples/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/TypeDefinition/jsfmt.spec.js b/tests/format/TypeDefinition/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/TypeDefinition/jsfmt.spec.js +++ b/tests/format/TypeDefinition/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/WhileStatements/jsfmt.spec.js b/tests/format/WhileStatements/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/WhileStatements/jsfmt.spec.js +++ b/tests/format/WhileStatements/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/format/WrongCompiler/jsfmt.spec.js b/tests/format/WrongCompiler/jsfmt.spec.js index 37b5a40d2..0e6bb7941 100644 --- a/tests/format/WrongCompiler/jsfmt.spec.js +++ b/tests/format/WrongCompiler/jsfmt.spec.js @@ -1,10 +1,10 @@ // Should warn twice -run_spec(__dirname, ['solidity-parse'], { compiler: '0.8.4' }); +run_spec(import.meta, ['solidity-parse'], { compiler: '0.8.4' }); // Should warn once -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse'], { compiler: 'v0.7.5-nightly.2020.11.9+commit.41f50365' }); // Should not warn -run_spec(__dirname, ['solidity-parse'], { +run_spec(import.meta, ['solidity-parse'], { compiler: 'v0.7.3+commit.9bfce1f6' }); diff --git a/tests/format/quotes/jsfmt.spec.js b/tests/format/quotes/jsfmt.spec.js index 68a722047..3272026cc 100644 --- a/tests/format/quotes/jsfmt.spec.js +++ b/tests/format/quotes/jsfmt.spec.js @@ -1,2 +1,2 @@ -run_spec(__dirname, ['solidity-parse'], { singleQuote: true }); -run_spec(__dirname, ['solidity-parse'], { singleQuote: false }); +run_spec(import.meta, ['solidity-parse'], { singleQuote: true }); +run_spec(import.meta, ['solidity-parse'], { singleQuote: false }); diff --git a/tests/format/strings/jsfmt.spec.js b/tests/format/strings/jsfmt.spec.js index f7722a72b..765dd60a6 100644 --- a/tests/format/strings/jsfmt.spec.js +++ b/tests/format/strings/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ['solidity-parse']); +run_spec(import.meta, ['solidity-parse']); diff --git a/tests/unit/binary-operation.test.js b/tests/unit/binary-operation.test.js index d4c915f28..163384bf4 100644 --- a/tests/unit/binary-operation.test.js +++ b/tests/unit/binary-operation.test.js @@ -1,4 +1,4 @@ -const genericPrint = require('../../src/printer'); +import genericPrint from '../../src/printer.js'; test('given an unknown operator then the BinaryOperation print function should throw', () => { const mockPath = { diff --git a/tests/unit/binary-operator-printers/index.test.js b/tests/unit/binary-operator-printers/index.test.js index 6e48852da..e802c8981 100644 --- a/tests/unit/binary-operator-printers/index.test.js +++ b/tests/unit/binary-operator-printers/index.test.js @@ -1,4 +1,4 @@ -const binaryOperatorPrinters = require('../../../src/binary-operator-printers'); +import * as binaryOperatorPrinters from '../../../src/binary-operator-printers/index.js'; test('binary operators printers to match snapshot', () => { expect(Object.keys(binaryOperatorPrinters)).toMatchSnapshot(); diff --git a/tests/unit/comments/printer.test.js b/tests/unit/comments/printer.test.js index 87a03fe65..c28a03f15 100644 --- a/tests/unit/comments/printer.test.js +++ b/tests/unit/comments/printer.test.js @@ -1,4 +1,4 @@ -const printComment = require('../../../src/comments/printer'); +import { printComment } from '../../../src/comments/printer.js'; test('given an unknown comment type then printComment function should throw', () => { const mockCommentPath = { getValue: () => ({ type: 'UnknownComment' }) }; diff --git a/tests/unit/prettier-version.test.js b/tests/unit/prettier-version.test.js deleted file mode 100644 index 984a96760..000000000 --- a/tests/unit/prettier-version.test.js +++ /dev/null @@ -1,31 +0,0 @@ -const { TEST_STANDALONE } = process.env; - -const prettier = TEST_STANDALONE - ? require('prettier/standalone') - : require('prettier'); - -const proxyquire = require('proxyquire'); - -const prettierMock = proxyquire('../config/require-prettier', { - prettier: { ...prettier, version: '2.2.1', '@global': true } -}); - -const plugin = proxyquire( - TEST_STANDALONE ? '../../dist/standalone' : '../../src/index', - { - prettier: prettierMock - } -); - -test('should throw if the installed version of prettier is less than v2.3.0', async () => { - const data = 'contract CheckPrettierVersion {}'; - - const options = { - plugins: [plugin], - parser: 'solidity-parse' - }; - - await expect(async () => { - await prettierMock.formatWithCursor(data, options); - }).rejects.toThrow('>=2.3.0'); -}); diff --git a/tests/unit/prettier-version/esmock-plugin.js b/tests/unit/prettier-version/esmock-plugin.js new file mode 100644 index 000000000..20a129d95 --- /dev/null +++ b/tests/unit/prettier-version/esmock-plugin.js @@ -0,0 +1,18 @@ +import esmock from 'esmock'; +import prettier from 'prettier'; + +const esmockPlugin = async () => { + const prettierMock = { ...prettier, version: '2.2.1' }; + + const plugin = await esmock( + '../../../src/index.js', + {}, + { + prettier: prettierMock + } + ); + + return { plugin, prettierMock }; +}; + +export default esmockPlugin; diff --git a/tests/unit/prettier-version/index.test.js b/tests/unit/prettier-version/index.test.js new file mode 100644 index 000000000..28ec7e7da --- /dev/null +++ b/tests/unit/prettier-version/index.test.js @@ -0,0 +1,20 @@ +test('should throw if the installed version of prettier is less than v2.3.0', async () => { + const entry = process.env.TEST_STANDALONE + ? new URL('./proxyquire-plugin.cjs', import.meta.url) // standalone uses proxyquire to mock cjs + : './esmock-plugin.js'; // uses esmock to mock esm + + const { plugin, prettierMock } = await import(entry).then((module) => + module.default() + ); + + const data = 'contract CheckPrettierVersion {}'; + + const options = { + plugins: [plugin], + parser: 'solidity-parse' + }; + + await expect(async () => { + await prettierMock.formatWithCursor(data, options); + }).rejects.toThrow('>=2.3.0'); +}); diff --git a/tests/unit/prettier-version/proxyquire-plugin.cjs b/tests/unit/prettier-version/proxyquire-plugin.cjs new file mode 100644 index 000000000..1b547f6db --- /dev/null +++ b/tests/unit/prettier-version/proxyquire-plugin.cjs @@ -0,0 +1,14 @@ +const proxyquire = require('proxyquire'); +const prettier = require('prettier/standalone.js'); + +const proxyquirePlugin = () => { + const prettierMock = { ...prettier, version: '2.2.1', '@global': true }; + + const plugin = proxyquire('../../../dist/standalone.cjs', { + prettier: prettierMock + }); + + return { plugin, prettierMock }; +}; + +module.exports = proxyquirePlugin; diff --git a/tests/unit/printer.test.js b/tests/unit/printer.test.js index eb3a1ebba..902b6f2be 100644 --- a/tests/unit/printer.test.js +++ b/tests/unit/printer.test.js @@ -1,4 +1,4 @@ -const genericPrint = require('../../src/printer'); +import genericPrint from '../../src/printer.js'; test('given an unknown module type then genericPrint function should throw', () => { const mockPath = { getValue: () => ({ type: 'UnknownModule' }) }; diff --git a/webpack.config.js b/webpack.config.js index 5989b0794..d285730b7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,13 @@ -const path = require('path'); +import path from 'node:path'; +import { createRequire } from 'node:module'; +import createEsmUtils from 'esm-utils'; + +const require = createRequire(import.meta.url); +const { __dirname } = createEsmUtils(import.meta); + // This is the production and development configuration. // It is focused on developer experience, fast rebuilds, and a minimal bundle. -module.exports = (webpackEnv) => { +export default (webpackEnv) => { const isEnvProduction = Boolean(webpackEnv.production); return { @@ -43,7 +49,8 @@ module.exports = (webpackEnv) => { target: ['browserslist'], output: { path: path.resolve(__dirname, 'dist'), - filename: 'standalone.js', + filename: 'standalone.cjs', + clean: true, globalObject: ` typeof globalThis !== "undefined" ? globalThis @@ -54,6 +61,7 @@ module.exports = (webpackEnv) => { : this || {} `, library: { + export: 'default', name: { commonjs: 'prettierPluginSolidity', root: ['prettierPlugins', 'solidity']